コード例 #1
0
        public override AstNode VisitForStmt(StannumParser.ForStmtContext context)
        {
            if (!(Visit(context.Label) is Identifier label))
            {
                throw new Exception("Unrecognized identifier!");
            }

            if (!(Visit(context.Value) is Expr value))
            {
                throw new Exception("Unrecognized expression!");
            }

            var variable = context.Var?.GetText();

            if (!(Visit(context.Body) is BlockStmt body))
            {
                throw new Exception("Unrecognized block!");
            }

            return(new ForStmt(label.Value, value, variable, body));
        }
コード例 #2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="StannumParser.forStmt"/>.
 /// <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 VisitForStmt([NotNull] StannumParser.ForStmtContext context)
 {
     return(VisitChildren(context));
 }