package serene.simple; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.Console; import java.io.FileInputStream; public class Main { public static void main(String[] args) throws IOException { if (args.length == 0) { startRepl(); return; } runSerene(args[0]); } private static void startRepl() throws IOException { Scope rootScope = Scope.getRootScope(); //Console console = System.console(); //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); Scanner in = new Scanner(System.in); System.out.println("Serene 'simple' v0.1.0"); while(true) { System.out.print("serene-> "); //String inputData = reader.readLine(); String inputData = in.nextLine(); if (inputData == null) break; ByteArrayInputStream inputStream = new ByteArrayInputStream(inputData.getBytes()); ListNode nodes = Reader.read(inputStream); Object result = ListNode.EMPTY; for (Node n : nodes) { result = n.eval(rootScope); } if (result != ListNode.EMPTY) { System.out.println(result); } } in.close(); } private static void runSerene(String filePath) throws IOException { Scope rootScope = Scope.getRootScope(); ListNode nodes = Reader.read(new FileInputStream(filePath)); for (Node n : nodes) { n.eval(rootScope); } } }