//An "if" statement. public override object VisitStat_if([NotNull] algoParser.Stat_ifContext context) { //Evaluate the check. AlgoValue checkReturned = (AlgoValue)VisitCheck(context.check()); bool mainCheck = AlgoComparators.GetBooleanValue(checkReturned, context); //Did it pass? If so, eval the if. if (mainCheck) { //Create scope. Scopes.AddScope(); //Evaluate the main statement body. foreach (var statement in context.statement()) { AlgoValue returned = (AlgoValue)VisitStatement(statement); if (returned != null) { Scopes.RemoveScope(); return(returned); } } //Delete scope. Scopes.RemoveScope(); //Return. return(null); } //Maincheck failed, complete all the "else if" checks if they exist. if (context.stat_elif().Length != 0) { foreach (var elseifblock in context.stat_elif()) { //Does the check pass? var checkContext = elseifblock.check(); AlgoValue elifCheckReturned = (AlgoValue)VisitCheck(checkContext); bool elseifCheck = AlgoComparators.GetBooleanValue(elifCheckReturned, context); if (elseifCheck) { //Create scope. Scopes.AddScope(); //Evaluate statements. foreach (var statement in elseifblock.statement()) { AlgoValue returned = (AlgoValue)VisitStatement(statement); if (returned != null) { Scopes.RemoveScope(); return(returned); } } //Remove scope. Scopes.RemoveScope(); //Return. return(null); } } } //Is there an else? if (context.stat_else() != null) { //Create a scope. Scopes.AddScope(); //Evaluate statements. foreach (var statement in context.stat_else().statement()) { AlgoValue returned = (AlgoValue)VisitStatement(statement); if (returned != null) { Scopes.RemoveScope(); return(returned); } } //Deleting scope. Scopes.RemoveScope(); } //Returning. return(null); }
/// <summary> /// Visit a parse tree produced by <see cref="algoParser.stat_if"/>. /// <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 VisitStat_if([NotNull] algoParser.Stat_ifContext context) { return(VisitChildren(context)); }
/// <summary> /// Exit a parse tree produced by <see cref="algoParser.stat_if"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitStat_if([NotNull] algoParser.Stat_ifContext context) { }