Beispiel #1
0
        public override AstNode VisitWhileStmt(StannumParser.WhileStmtContext context)
        {
            if (!(Visit(context.Value) is Expr value))
            {
                throw new Exception("Unrecognized expression!");
            }

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

            if (context.Label == null)
            {
                return(new WhileStmt(null, value, body));
            }

            if (!(Visit(context.Label) is Identifier label))
            {
                throw new Exception("Unrecognized identifier!");
            }

            return(new WhileStmt(label.Value, value, body));
        }
Beispiel #2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="StannumParser.whileStmt"/>.
 /// <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 VisitWhileStmt([NotNull] StannumParser.WhileStmtContext context)
 {
     return(VisitChildren(context));
 }