private CommonTree getTree(string customExpression) { ANTLRStringStream expression = new ANTLRStringStream(customExpression); var tokens = new CommonTokenStream(new SimpleBooleanLexer(expression)); var parser = new SimpleBooleanParser(tokens); SimpleBooleanParser.expr_return ret = parser.expr(); return((CommonTree)ret.Tree); }
public SimpleBooleanParser.expr_return expr() { EnterRule_expr(); EnterRule("expr", 2); TraceIn("expr", 2); SimpleBooleanParser.expr_return retval = new SimpleBooleanParser.expr_return(this); retval.Start = (IToken)input.LT(1); object root_0 = default(object); SimpleBooleanParser.andexpr_return andexpr2 = default(SimpleBooleanParser.andexpr_return); try { DebugEnterRule(GrammarFileName, "expr"); DebugLocation(19, 14); try { // D:\\projects\\common\\Antlr\\simpleboolean-parser\\SimpleBoolean.g:19:6: ( andexpr ) DebugEnterAlt(1); // D:\\projects\\common\\Antlr\\simpleboolean-parser\\SimpleBoolean.g:19:8: andexpr { root_0 = (object)adaptor.Nil(); DebugLocation(19, 8); PushFollow(Follow._andexpr_in_expr145); andexpr2 = andexpr(); PopFollow(); adaptor.AddChild(root_0, andexpr2.Tree); } retval.Stop = (IToken)input.LT(-1); retval.Tree = (object)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, retval.Start, retval.Stop); } catch (RecognitionException re) { ReportError(re); Recover(input, re); retval.Tree = (object)adaptor.ErrorNode(input, retval.Start, input.LT(-1), re); } finally { TraceOut("expr", 2); LeaveRule("expr", 2); LeaveRule_expr(); } DebugLocation(19, 14); } finally { DebugExitRule(GrammarFileName, "expr"); } return(retval); }
private SimpleBooleanParser.atom_return atom() { EnterRule_atom(); EnterRule("atom", 5); TraceIn("atom", 5); SimpleBooleanParser.atom_return retval = new SimpleBooleanParser.atom_return(this); retval.Start = (IToken)input.LT(1); object root_0 = default(object); IToken WORD9 = default(IToken); IToken LPAREN10 = default(IToken); IToken RPAREN12 = default(IToken); SimpleBooleanParser.expr_return expr11 = default(SimpleBooleanParser.expr_return); object WORD9_tree = default(object); object LPAREN10_tree = default(object); object RPAREN12_tree = default(object); try { DebugEnterRule(GrammarFileName, "atom"); DebugLocation(22, 34); try { // D:\\projects\\common\\Antlr\\simpleboolean-parser\\SimpleBoolean.g:22:6: ( WORD | LPAREN expr RPAREN ) int alt3 = 2; try { DebugEnterDecision(3, false); int LA3_0 = input.LA(1); if ((LA3_0 == WORD)) { alt3 = 1; } else if ((LA3_0 == LPAREN)) { alt3 = 2; } else { NoViableAltException nvae = new NoViableAltException("", 3, 0, input); DebugRecognitionException(nvae); throw nvae; } } finally { DebugExitDecision(3); } switch (alt3) { case 1: DebugEnterAlt(1); // D:\\projects\\common\\Antlr\\simpleboolean-parser\\SimpleBoolean.g:22:8: WORD { root_0 = (object)adaptor.Nil(); DebugLocation(22, 8); WORD9 = (IToken)Match(input, WORD, Follow._WORD_in_atom182); WORD9_tree = (object)adaptor.Create(WORD9); adaptor.AddChild(root_0, WORD9_tree); } break; case 2: DebugEnterAlt(2); // D:\\projects\\common\\Antlr\\simpleboolean-parser\\SimpleBoolean.g:22:15: LPAREN expr RPAREN { root_0 = (object)adaptor.Nil(); DebugLocation(22, 21); LPAREN10 = (IToken)Match(input, LPAREN, Follow._LPAREN_in_atom186); DebugLocation(22, 23); PushFollow(Follow._expr_in_atom189); expr11 = expr(); PopFollow(); adaptor.AddChild(root_0, expr11.Tree); DebugLocation(22, 34); RPAREN12 = (IToken)Match(input, RPAREN, Follow._RPAREN_in_atom191); } break; } retval.Stop = (IToken)input.LT(-1); retval.Tree = (object)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, retval.Start, retval.Stop); } catch (RecognitionException re) { ReportError(re); Recover(input, re); retval.Tree = (object)adaptor.ErrorNode(input, retval.Start, input.LT(-1), re); } finally { TraceOut("atom", 5); LeaveRule("atom", 5); LeaveRule_atom(); } DebugLocation(22, 34); } finally { DebugExitRule(GrammarFileName, "atom"); } return(retval); }