00001: import java.io.FileInputStream; 00002: import java.util.List; 00003: import java.util.Map; 00004: 00005: import java_cup.runtime.*; 00006: 00007: 00008: public class Main 00009: { 00010: public static void main (String[] args) 00011: throws Exception 00012: { 00013: SymbolFactory sf = new ComplexSymbolFactory (); 00014: ArithmeticLexer lexer; 00015: if (args.length == 0) { 00016: lexer = new ArithmeticLexer (System.in, sf); 00017: } else { 00018: lexer = new ArithmeticLexer (new java.io.FileInputStream (args[0]), sf); 00019: } 00020: ArithmeticParser parser = new ArithmeticParser (lexer, sf); 00021: 00022: Symbol symbol = parser.parse (); 00023: 00024: List<Decl> decls = (List<Decl>) symbol.value; 00025: for (Decl decl : decls) { 00026: System.out.println (decl); 00027: } 00028: 00029: System.out.println (); 00030: 00031: Interpreter interpreter = new Interpreter (); 00032: Map<String, Integer> bindings = interpreter.evaluateDecls (decls); 00033: for (String var : bindings.keySet ()) { 00034: System.out.println (var + " = " + bindings.get (var)); 00035: } 00036: } 00037: } 00038: 00039: