public static void main(String args[]) throws Exception { Yylex l = null; parser p; try { if (args.length == 0) l = new Yylex(System.in); else l = new Yylex(new FileReader(args[0])); } catch (FileNotFoundException e) { System.err.println("Error: File not found: " + args[0]); System.exit(1); } p = new parser(l); /* The default parser is the first-defined entry point. */ /* You may want to change this. Other options are: */ /* */ try { pl.edu.mimuw.cloudatlas.interpreter.query.Absyn.Program parse_tree = p.pProgram(); System.out.println(); System.out.println("Parse Succesful!"); System.out.println(); System.out.println("[Abstract Syntax]"); System.out.println(); System.out.println(PrettyPrinter.show(parse_tree)); System.out.println(); System.out.println("[Linearized Tree]"); System.out.println(); System.out.println(PrettyPrinter.print(parse_tree)); } catch (Throwable e) { System.err.println( "At line " + String.valueOf(l.line_num()) + ", near \"" + l.buff() + "\" :"); System.err.println(" " + e.getMessage()); System.exit(1); } }
public String printString() { return (PrettyPrinter.print( rs, new Printer<Object>() { @Override public String print(Object obj) { return obj.toString(); } })); }
public void print() { System.out.println( PrettyPrinter.print( rs, new Printer<Object>() { @Override public String print(Object obj) { return obj.toString(); } })); }
public static void main(String args[]) { try { System.out.println("Type in a tiny exp folowed by one or two Ctrl-d's:"); Parser p = new Parser(new Lexer(new PushbackReader(new InputStreamReader(System.in), 1024))); Start tree = p.parse(); NewEval.replaceUminus(tree); /* pretty-print */ System.out.println("\nThe result of evaluating:"); PrettyPrinter.print(tree); /* pre-eval to replace uminus */ /* evaluate */ System.out.print("\nis: "); PrettyPrinter.print(Evaluator.eval(tree)); System.out.println("\n"); } catch (Exception e) { System.out.println(e); } }
/** Pretty-printing */ public void pretty(PrettyPrinter pp) { pp.print("STORE " + x); }