Пример #1
0
        public string VisitLiteralExpr(Expr.Literal expr)
        {
            if (expr.Value == null)
            {
                return("null");
            }

            return(expr.Value.ToString() !);
        }
Пример #2
0
        public string visitLiteralExpr(Expr.Literal expr)
        {
            if (expr.Value == null)
            {
                return("none");
            }

            return(expr.Value.ToString());
        }
Пример #3
0
        public TypeSpecifier VisitLiteralExpression(Expr.Literal exp)
        {
            LLVMValueRef outval;

            if (exp.Type == TypeEnum.I8)
            {
                ulong b = Convert.ToUInt64(exp.Value);
                if (b < 0)
                {
                    outval = LLVM.ConstInt(LLVM.Int8Type(), b, _lTrue);
                }
                else
                {
                    outval = LLVM.ConstInt(LLVM.Int8Type(), b, _lFalse);
                }
            }
            else if (exp.Type == TypeEnum.I16)
            {
                ulong b = Convert.ToUInt64(exp.Value);
                if (b < 0)
                {
                    outval = LLVM.ConstInt(LLVM.Int16Type(), b, _lTrue);
                }
                else
                {
                    outval = LLVM.ConstInt(LLVM.Int16Type(), b, _lFalse);
                }
            }
            else if (exp.Type == TypeEnum.I32)
            {
                ulong b = Convert.ToUInt64(exp.Value);
                if (b < 0)
                {
                    outval = LLVM.ConstInt(LLVM.Int32Type(), b, _lTrue);
                }
                else
                {
                    outval = LLVM.ConstInt(LLVM.Int32Type(), b, _lFalse);
                }
            }
            else if (exp.Type == TypeEnum.I64)
            {
                ulong b = Convert.ToUInt64(exp.Value);
                if (b < 0)
                {
                    outval = LLVM.ConstInt(LLVM.Int64Type(), b, _lTrue);
                }
                else
                {
                    outval = LLVM.ConstInt(LLVM.Int64Type(), b, _lFalse);
                }
            }
            else if (exp.Type == TypeEnum.F32)
            {
                double d = Convert.ToDouble(exp.Value);
                outval = LLVM.ConstReal(LLVM.FloatType(), d);
            }
            else if (exp.Type == TypeEnum.F64)
            {
                double d = Convert.ToDouble(exp.Value);
                outval = LLVM.ConstReal(LLVM.DoubleType(), d);
            }
            else if (exp.Type == TypeEnum.BOOL)
            {
                bool b = Convert.ToBoolean(exp.Value);
                if (b)
                {
                    outval = LLVM.ConstInt(LLVM.Int1Type(), 1, _lFalse);
                }
                else
                {
                    outval = LLVM.ConstInt(LLVM.Int1Type(), 0, _lTrue);
                }
            }
            else if (exp.Type == TypeEnum.STRING)
            {
                string str = exp.Value.ToString();

                outval = LLVM.BuildGlobalStringPtr(_builder, str, "");
                //outval = LLVM.ConstString(str, (uint)(str.Length + 1), _lFalse);
            }
            else
            {
                throw new Exception("Unknown literal");
            }

            _valueStack.Push(outval);
            return(new TypeSpecifier {
                Type = exp.Type, Dimensions = 0
            });
        }
Пример #4
0
 public object VisitLiteralExpr(Expr.Literal expr)
 {
     return(null);
 }
Пример #5
0
 public VoidObject VisitLiteralExpr(Expr.Literal expr)
 {
     return(VoidObject.Void);
 }
Пример #6
0
 public Token visitLiteralExpr(Expr.Literal literal)
 {
     return(literal.type);
 }
Пример #7
0
        private Stmt ForStatement()
        {
            Consume(LEFT_PAREN, "Expected \"(\" 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, "Expected \";\" after loop condition");

            Expr increment = null;

            if (!Check(RIGHT_PAREN))
            {
                increment = Expression();
            }
            Consume(RIGHT_PAREN, "Expected \")\" after clauses");

            Stmt body = Statement();

            if (increment != null)
            {
                body = new Stmt.Block(new List <Stmt>()
                {
                    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>()
                {
                    initializer, body
                });
            }

            return(body);
        }
Пример #8
0
 public object VisitLiteralExpr(Expr.Literal expr)
 {
     return(expr.value);
 }
Пример #9
0
        /// <summary>
        /// Parse a for loop
        /// </summary>
        /// <returns>The statement</returns>
        private Stmt ForStatement()
        {
            _loop_depth++;

            try
            {
                Consume(TokenType.LEFT_PAREN, "Expect '(' after 'for'.");

                // Initializer

                Stmt initializer;
                if (Match(TokenType.SEMICOLON))
                {
                    // No initialiser
                    initializer = null;
                }
                else if (Match(TokenType.VAR))
                {
                    // Its a variable decalration
                    initializer = VarDeclaration();
                }
                else
                {
                    // Its an expression
                    // This must be a _statement_
                    initializer = ExpressionStatement();
                }

                // Condition
                Expr condition = null;
                if (!Check(TokenType.SEMICOLON))
                {
                    condition = Expression();
                }
                Consume(TokenType.SEMICOLON, "Expect ';' after loop condition.");

                // Increment
                Expr increment = null;
                if (!Check(TokenType.SEMICOLON))
                {
                    increment = Expression();
                }
                Consume(TokenType.RIGHT_PAREN, "Expect ')' after for clauses.");

                // Body
                Stmt body = Statement();

                // Convert to a while loop
                if (increment != null)
                {
                    body = new Stmt.Block(new[] { body, new Stmt.ExpressionStatement(increment) });
                }

                if (condition == null)
                {
                    // No condition, so set to true
                    condition = new Expr.Literal(true);
                }

                body = new Stmt.While(condition, body);

                if (initializer != null)
                {
                    body = new Stmt.Block(new[] { initializer, body });
                }

                return(body);
            }
            finally
            {
                _loop_depth--;
            }
        }
Пример #10
0
    private Stmt ForStatement()
    {
        Consume(LeftParen, "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(RightParen))
        {
            increment = Expression();
        }

        Consume(RightParen, "Expect ')' after for clauses.");

        Stmt body = Statement();

        if (increment != null)
        {
            body = new Stmt.Block(
                new List <Stmt> {
                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> {
                initializer, body
            });
        }

        return(body);
    }
Пример #11
0
 public object Visit(Expr.Literal expr)
 {
     return(expr.Value);
 }
Пример #12
0
 public T VisitLiteralExpression(Expr.Literal exp);
Пример #13
0
 public object VisitLiteralExpr(Expr.Literal expr, object options = null)
 {
     return(null);
 }
Пример #14
0
 object Expr.Visitor <object> .VisitLiteralExpr(Expr.Literal expr)
 {
     return(expr.value);
 }
Пример #15
0
 public string VisitLiteralExpr(Expr.Literal expr)
 {
     return(expr.value == null ? "nil" : expr.value.ToString());
 }
Пример #16
0
 public string VisitLiteralExpr(Expr.Literal expr) => expr.Value == null ? "nil" : expr.Value.ToString();
Пример #17
0
 public void Visit(Expr.Literal expr) => _sql.Append($"'{expr.Value}'");
Пример #18
0
        private Stmt ForStatment()
        {
            try
            {
                this.LoopCounter += 1;

                Consume(LEFT_PAREN, "Exepect '(' after 'for.");
                Stmt initialiser;
                if (Match(SEMICOLON))
                {
                    initialiser = null;
                }
                else if (Match(VAR))
                {
                    initialiser = VarDeclaration();
                }
                else
                {
                    initialiser = 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 clausess.");

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

                if (Condition == null)
                {
                    Condition = new Expr.Literal(true);
                }
                body = new Stmt.While(Condition, body);

                if (initialiser != null)
                {
                    body = new Stmt.Block(new List <Stmt> {
                        initialiser, body
                    });
                }



                return(body);
            }
            finally
            {
                LoopCounter--;
            }
        }
Пример #19
0
 public string VisitLiteralExpr(Expr.Literal expr) => (expr.value == null) ? "null" : expr.value.ToString();
Пример #20
0
 public TrashObject VisitLiteralExpr(Expr.Literal expr)
 {
     return(expr.Value);
 }
Пример #21
0
 public Unit VisitLiteralExpr(Expr.Literal expr)
 {
     return(new Unit());
 }
Пример #22
0
 public LoxVoid VisitLiteralExpr(Expr.Literal expr)
 {
     return(null);
 }