예제 #1
0
파일: Calc.cs 프로젝트: TRXMaik/lg3d-escher
    public static void Main(string[] args)
    {
        try
        {
            CalcLexer lexer = new CalcLexer(new CharBuffer(Console.In));
            lexer.setFilename("<stdin>");
            CalcParser parser = new CalcParser(lexer);
            parser.setFilename("<stdin>");

            // Parse the input expression
            parser.expr();
            CommonAST t = (CommonAST)parser.getAST();

            // Print the resulting tree out in LISP notation
            Console.Out.WriteLine(t.ToStringTree());
            CalcTreeWalker walker = new CalcTreeWalker();

            // Traverse the tree created by the parser
            float r = walker.expr(t);
            Console.Out.WriteLine("value is " + r);
        }
        catch (TokenStreamException e)
        {
            Console.Error.WriteLine("exception: " + e);
        }
        catch (RecognitionException e)
        {
            Console.Error.WriteLine("exception: " + e);
        }
    }
예제 #2
0
 protected CommonAST(CommonAST another)
 {
     // don't include child/sibling pointers in Clone()/dup()
     //down	= another.down;
     //right	= another.right;
     ttype = another.ttype;
     text  = (another.text == null) ? null : String.Copy(another.text);
 }
예제 #3
0
 protected CommonAST(CommonAST another)
 {
     // don't include child/sibling pointers in Clone()/dup()
     //down	= another.down;
     //right	= another.right;
     ttype	= another.ttype;
     text	= (another.text==null) ? null : String.Copy(another.text);
 }
예제 #4
0
파일: Main.cs 프로젝트: dilawar/ahir
    public static void Main(string[] args)
    {
        try {
            ExprLexer lexer = new ExprLexer(new CharBuffer(Console.In));
            ExprParser parser = new ExprParser(lexer);

            // set the type of tree node to create; this is default action
            // so it is unnecessary to do it here, but demos capability.
            parser.setASTNodeClass("antlr.CommonAST");

            parser.expr();
            antlr.CommonAST ast = (antlr.CommonAST)parser.getAST();
            if (ast != null) {
                Console.Out.WriteLine(ast.ToStringList());
            } else {
                Console.Out.WriteLine("null AST");
            }
        } catch(Exception e) {
            Console.Error.WriteLine("exception: "+e);
        }
    }