//When a single factor is parsed in Algo. public override object VisitFactor([NotNull] algoParser.FactorContext context) { //Is there a power? if (context.POW_OP() != null) { //Yes. //Evaluate left factor. AlgoValue left = (AlgoValue)VisitFactor(context.factor()); //Evaluate right sub. AlgoValue right = (AlgoValue)VisitSub(context.sub()); //Perform a power. return(AlgoOperators.Pow(context, left, right)); } else { //No, just evaluate the sub. return((AlgoValue)VisitSub(context.sub())); } //Error. throw new Exception("Invalid expression type."); }
/// <summary> /// Visit a parse tree produced by <see cref="algoParser.factor"/>. /// <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 VisitFactor([NotNull] algoParser.FactorContext context) { return(VisitChildren(context)); }
/// <summary> /// Exit a parse tree produced by <see cref="algoParser.factor"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitFactor([NotNull] algoParser.FactorContext context) { }