source: trunk/yao/share/antlr-2.7.7/examples/java/heteroAST/Main.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: 828 bytes
Line 
1import java.io.*;
2import antlr.CommonAST;
3import antlr.collections.AST;
4
5class Main {
6        public static void main(String[] args) {
7                new INTNode();
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                        CalcAST t = (CalcAST)parser.getAST();
14
15                        // Print the resulting tree out in LISP notation
16                        System.out.println(t.toStringTree());
17
18                        // XML serialize the tree, showing
19                        // different physical node class types
20                        Writer w = new OutputStreamWriter(System.out);
21                        t.xmlSerialize(w);
22                        w.write("\n");
23                        w.flush();
24
25                        // Compute value and return
26                        int r = t.value();
27                        System.out.println("value is "+r);
28                } catch(Exception e) {
29                        System.err.println("exception: "+e);
30                        e.printStackTrace();
31                }
32        }
33}
Note: See TracBrowser for help on using the repository browser.