Beispiel #1
0
 public string Visit_LiteralExpr(LiteralExpr expr)
 {
     if (expr.value == null)
     {
         return("nil");
     }
     return("'" + expr.value.ToString() + "'");
 }
Beispiel #2
0
 public object VisitLiteralExpr(LiteralExpr expr)
 {
     return(expr.Value);
 }
Beispiel #3
0
        private Stmt ForStatement()
        {
            Expect(TokenType.LeftParen, ErrorType.ExpectedOpenParen);

            Stmt initializer;

            if (CheckCurrentToken(TokenType.Semicolon))
            {
                initializer = null;
                Advance();
            }
            else if (CheckCurrentToken(TokenType.Var))
            {
                Advance();
                initializer = VarDeclaration();
            }
            else
            {
                initializer = ExpressionStatement();
            }

            Expr condition = null;

            if (!CheckCurrentToken(TokenType.Semicolon))
            {
                condition = Expression();
            }
            Expect(TokenType.Semicolon, ErrorType.ExpectedSemicolon);

            Expr increment = null;

            if (!CheckCurrentToken(TokenType.RightParen))
            {
                increment = Expression();
            }
            Expect(TokenType.RightParen, ErrorType.ExpectedClosedParen);

            Stmt body = Statement();

            if (increment != null)
            {
                body = new BlockStmt(new List <Stmt> {
                    body, new ExpressionStmt(increment)
                });
            }

            if (condition == null)
            {
                condition = new LiteralExpr(true);
            }
            body = new WhileStmt(condition, body);

            if (initializer != null)
            {
                body = new BlockStmt(new List <Stmt> {
                    initializer, body
                });
            }

            return(body);
        }
Beispiel #4
0
 public object VisitLiteralExpr(LiteralExpr expr)
 {
     return(null);
 }
Beispiel #5
0
 public Object Visit_LiteralExpr(LiteralExpr expr)
 {
     return(expr.value);
 }
Beispiel #6
0
 public Void Visit_LiteralExpr(LiteralExpr expr)
 {
     return(null);
 }