/// <summary> /// Visit a parse tree produced by <see cref="OALParser.expr"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitExpr([NotNull] OALParser.ExprContext context) { return(VisitChildren(context)); }
public override object VisitExpr([NotNull] OALParser.ExprContext context) { //Console.WriteLine("Expr: " + context.ChildCount); //Console.WriteLine(context.GetChild(0).GetType().Name); if (context.ChildCount == 1) { if (context.GetChild(0).GetType().Name.Contains("TerminalNode") && stackEXEASTNode.Count() == 0) { EXEASTNodeLeaf ast = new EXEASTNodeLeaf(ParseUtil.StripWhiteSpace(context.GetChild(0).GetText())); stackEXEASTNode.Push(ast); //stackEXEASTNode.Peek().AddOperand(new EXEASTNodeComposite(ParseUtil.StripWhiteSpace(context.GetChild(0).GetText()))); } else { ((EXEASTNodeComposite)stackEXEASTNode.Peek()).AddOperand(new EXEASTNodeLeaf(ParseUtil.StripWhiteSpace(context.GetChild(0).GetText()))); } } else if (context.ChildCount == 2) { EXEASTNodeComposite ast = new EXEASTNodeComposite(ParseUtil.StripWhiteSpace(context.GetChild(0).GetText())); stackEXEASTNode.Push(ast); base.VisitExpr(context); if (context.GetChild(0).GetType().Name.Contains("TerminalNode") && !context.GetChild(0).GetText().Equals("not ")) { ((EXEASTNodeComposite)stackEXEASTNode.Peek()).AddOperand(new EXEASTNodeLeaf(ParseUtil.StripWhiteSpace(context.GetChild(1).GetText()))); EXEASTNode temp = stackEXEASTNode.Pop(); ((EXEASTNodeComposite)stackEXEASTNode.Peek()).AddOperand(temp); } else if (context.GetChild(0).GetText().Equals("not ")) { if (stackEXEASTNode.Count() > 1) { EXEASTNode temp = stackEXEASTNode.Pop(); ((EXEASTNodeComposite)stackEXEASTNode.Peek()).AddOperand(temp); } } } else if (context.ChildCount == 3) { if (!context.GetChild(0).GetText().Equals("(")) { EXEASTNodeComposite ast = new EXEASTNodeComposite(ParseUtil.StripWhiteSpace(context.GetChild(1).GetText())); stackEXEASTNode.Push(ast); } base.VisitExpr(context); if (context.GetChild(0).GetType().Name.Contains("TerminalNode") && !context.GetChild(0).GetText().Equals("(")) { ((EXEASTNodeComposite)stackEXEASTNode.Peek()).AddOperand(new EXEASTNodeLeaf(ParseUtil.StripWhiteSpace(context.GetChild(0).GetText()))); ((EXEASTNodeComposite)stackEXEASTNode.Peek()).AddOperand(new EXEASTNodeLeaf(ParseUtil.StripWhiteSpace(context.GetChild(2).GetText()))); EXEASTNode temp = stackEXEASTNode.Pop(); ((EXEASTNodeComposite)stackEXEASTNode.Peek()).AddOperand(temp); } else if (stackEXEASTNode.Count > 1 && !context.GetChild(0).GetText().Equals("(")) { EXEASTNode temp = stackEXEASTNode.Pop(); ((EXEASTNodeComposite)stackEXEASTNode.Peek()).AddOperand(temp); } } return(null); //return base.VisitExpr(context); }
/// <summary> /// Exit a parse tree produced by <see cref="OALParser.expr"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitExpr([NotNull] OALParser.ExprContext context) { }