コード例 #1
0
        private Stmt ForStatement()
        {
            Consume(LEFT_PAREN, "Expect '(' after 'for'.");
            Stmt initializer;

            if (Match(SEMICOLON))
            {
                initializer = null;
            }
            else if (Match(VAR))
            {
                initializer = VarDeclaration();
            }
            else
            {
                initializer = ExpressionStatement();
            }

            Expr condition = null;

            if (!Check(SEMICOLON))
            {
                condition = Expression();
            }

            Consume(SEMICOLON, "Expect ';' after loop condition.");
            Expr increment = null;

            if (!Check(RIGHT_PAREN))
            {
                increment = Expression();
            }

            Consume(RIGHT_PAREN, "Expect ')' after for clauses.");
            Stmt body = Statement();

            if (increment != null)
            {
                body = new Stmt.Block(
                    new List <Stmt>(
                        new[] { body, new Stmt.Expression(increment) }));
            }

            if (condition == null)
            {
                condition = new Expr.Literal(true);
            }

            body = new Stmt.While(condition, body);
            if (initializer != null)
            {
                body = new Stmt.Block(
                    new List <Stmt>(
                        new[] { initializer, body }));
            }
            return(body);
        }
コード例 #2
0
ファイル: RpnPrinter.cs プロジェクト: cortexarts/Scripted
        public string VisitLiteralExpr(Expr.Literal expr)
        {
            var sb = new StringBuilder();

            if (expr.Value == null)
            {
                sb.Append("nil");
                return(sb.ToString());
            }
            sb.Append(expr.Value);
            return(sb.ToString());
        }
コード例 #3
0
 public object VisitLiteralExpr(Expr.Literal expr)
 {
     return(expr.Value);
 }
コード例 #4
0
ファイル: Resolver.cs プロジェクト: cortexarts/Scripted
 public Nothing VisitLiteralExpr(Expr.Literal expr)
 {
     return(Nothing.AtAll);
 }