source: trunk/yao/share/antlr-2.7.7/examples/java/transform/Calc.java @ 1

Last change on this file since 1 was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

File size: 732 bytes
Line 
1import java.io.*;
2import antlr.CommonAST;
3import antlr.collections.AST;
4import antlr.DumpASTVisitor;
5
6class 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.