예제 #1
0
        //When an expression is parsed in Algo.
        public override object VisitExpr([NotNull] algoParser.ExprContext context)
        {
            //Is it an addition?
            if (context.ADD_OP() != null)
            {
                //Yes. Evaluate the left hand expression.
                AlgoValue left = (AlgoValue)VisitExpr(context.expr());

                //Evaluate the right hand term.
                AlgoValue right = (AlgoValue)VisitTerm(context.term());

                //Perform an add operation, based on type.
                return(AlgoOperators.Add(context, left, right));
            }
            else if (context.TAKE_OP() != null)
            {
                //Take operation.
                //Evaluate the left hand expression.
                AlgoValue left = (AlgoValue)VisitExpr(context.expr());

                //Evaluate the right hand term.
                AlgoValue right = (AlgoValue)VisitTerm(context.term());

                //Perform a take operation, based on type.
                return(AlgoOperators.Sub(context, left, right));
            }
            else
            {
                //No, just a term, evaluate.
                return((AlgoValue)VisitTerm(context.term()));
            }
        }
예제 #2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="algoParser.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] algoParser.ExprContext context)
 {
     return(VisitChildren(context));
 }
예제 #3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="algoParser.expr"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitExpr([NotNull] algoParser.ExprContext context)
 {
 }