source: trunk/yao/share/antlr-2.7.7/examples/cpp/heteroAST/Main.cpp @ 1

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

Initial import of YAO sources

  • Property svn:eol-style set to native
File size: 902 bytes
Line 
1
2#include <iostream>
3
4#include "CalcLexer.hpp"
5#include "CalcParser.hpp"
6#include "CalcAST.hpp"
7
8int main()
9{
10        ANTLR_USING_NAMESPACE(std)
11        ANTLR_USING_NAMESPACE(antlr)
12
13        try {
14                CalcLexer lexer(cin);
15                CalcParser parser(lexer);
16
17                ASTFactory ast_factory;
18
19                parser.initializeASTFactory(ast_factory);
20                parser.setASTFactory(&ast_factory);
21
22                // Parse the input expression
23                parser.expr();
24                RefCalcAST t = RefCalcAST(parser.getAST());
25
26                if( t )
27                {
28                        // Print the resulting tree out in LISP notation
29                        cout << t->toStringTree() << endl;
30
31                        // Compute value and return
32                        int r = t->value();
33                        cout << "value is " << r << endl;
34                }
35                else
36                        cerr << "Errors encountered during parse.." << endl;
37        }
38        catch( ANTLRException& e )
39        {
40                cerr << "ANTLRException: " << e.getMessage() << endl;
41                return -1;
42        }
43        catch(exception& e)
44        {
45                cerr << "exception: " << e.what() << endl;
46                return -1;
47        }
48        return 0;
49}
Note: See TracBrowser for help on using the repository browser.