コード例 #1
0
ファイル: AST_Printer.cs プロジェクト: sirgru/CsLox
 public string Visit_LiteralExpr(LiteralExpr expr)
 {
     if (expr.value == null)
     {
         return("nil");
     }
     return("'" + expr.value.ToString() + "'");
 }
コード例 #2
0
ファイル: Interpreter.cs プロジェクト: CaptainNic/cslox
 public object VisitLiteralExpr(LiteralExpr expr)
 {
     return(expr.Value);
 }
コード例 #3
0
ファイル: Parser.cs プロジェクト: sirgru/CsLox
        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);
        }
コード例 #4
0
 public object VisitLiteralExpr(LiteralExpr expr)
 {
     return(null);
 }
コード例 #5
0
ファイル: Interpreter.cs プロジェクト: sirgru/CsLox
 public Object Visit_LiteralExpr(LiteralExpr expr)
 {
     return(expr.value);
 }
コード例 #6
0
 public Void Visit_LiteralExpr(LiteralExpr expr)
 {
     return(null);
 }