Line | |
---|
1 | import java.io.*; |
---|
2 | import antlr.CommonAST; |
---|
3 | import antlr.collections.AST; |
---|
4 | import antlr.DumpASTVisitor; |
---|
5 | |
---|
6 | class Calc { |
---|
7 | public static void main(String[] args) { |
---|
8 | try { |
---|
9 | CalcLexer lexer = new CalcLexer(new DataInputStream(System.in)); |
---|
10 | CalcParser parser = new CalcParser(lexer); |
---|
11 | // Parse the input expression |
---|
12 | parser.expr(); |
---|
13 | CommonAST t = (CommonAST)parser.getAST(); |
---|
14 | // Print the resulting tree out in LISP notation |
---|
15 | System.out.println(t.toStringList()); |
---|
16 | CalcTreeWalker walker = new CalcTreeWalker(); |
---|
17 | // Traverse the tree created by the parser |
---|
18 | walker.expr(t); |
---|
19 | t = (CommonAST)walker.getAST(); |
---|
20 | System.out.println(t.toStringList()); |
---|
21 | } catch(Exception e) { |
---|
22 | System.err.println("exception: "+e); |
---|
23 | } |
---|
24 | } |
---|
25 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.