Exemple #1
0
 public object visitExprLiteralExpr(ExprLiteral expr)
 {
     if (expr.eValue == null)
     {
         return("Nil");
     }
     return(expr.eValue.ToString());
 }
Exemple #2
0
        Stmt forStatement()
        {
            consume(TokenType.LEFT_PAREN, "Expected '(' after 'for'.");
            Stmt initStmt;

            if (match(TokenType.SEMICOLON))
            {
                initStmt = null;
            }
            else if (match(TokenType.VAR))
            {
                initStmt = varDeclaration();
            }
            else
            {
                initStmt = exprStatement();
            }

            Expr condition = null;

            if (!check(TokenType.SEMICOLON))
            {
                condition = expression();
            }
            consume(TokenType.SEMICOLON, "Expected ';' after loop condition");

            Expr increment = null;

            if (!check(TokenType.RIGHT_PAREN))
            {
                increment = expression();
            }
            consume(TokenType.RIGHT_PAREN, "Expected ')' after for clauses");

            Stmt body = statement();

            if (increment != null)
            {
                body = new StmtBlock(new List <Stmt>()
                {
                    body, new StmtExpression(increment)
                });
            }
            if (condition == null)
            {
                condition = new ExprLiteral(true);
            }
            body = new StmtWhile(condition, body);
            if (initStmt != null)
            {
                body = new StmtBlock(new List <Stmt>()
                {
                    initStmt, body
                });
            }

            return(body);
        }
Exemple #3
0
 public object visitExprLiteralExpr(ExprLiteral expr)
 {
     return(null);
 }
Exemple #4
0
 public object visitExprLiteralExpr(ExprLiteral expr)
 {
     return(expr.eValue);
 }