示例#1
0
 public BaseAST Parse(string code)
 {
     var codeStream = new ANTLRStringStream(code);
     var lexer = new EvaluationGrammarLexer(codeStream);
     if (lexer.NumberOfSyntaxErrors > 0)
     {
         return null;
     }
     var tokenStream = new CommonTokenStream(lexer);
     var parser = new EvaluationGrammarParser(tokenStream);
     var parseTree = (CommonTree)parser.program().Tree;
     if (parser.NumberOfSyntaxErrors > 0)
     {
         return null;
     }
     var nodes = new CommonTreeNodeStream(parseTree);
     var astGenerator = new ASTGenerator(nodes);
     return astGenerator.getAST();
 }
示例#2
0
        public BaseAST Parse(string code)
        {
            var codeStream = new ANTLRStringStream(code);
            var lexer      = new EvaluationGrammarLexer(codeStream);

            if (lexer.NumberOfSyntaxErrors > 0)
            {
                return(null);
            }
            var tokenStream = new CommonTokenStream(lexer);
            var parser      = new EvaluationGrammarParser(tokenStream);
            var parseTree   = (CommonTree)parser.program().Tree;

            if (parser.NumberOfSyntaxErrors > 0)
            {
                return(null);
            }
            var nodes        = new CommonTreeNodeStream(parseTree);
            var astGenerator = new ASTGenerator(nodes);

            return(astGenerator.getAST());
        }