public string VisitLiteralExpr(Expr.Literal expr) { if (expr.Value == null) { return("null"); } return(expr.Value.ToString() !); }
public string visitLiteralExpr(Expr.Literal expr) { if (expr.Value == null) { return("none"); } return(expr.Value.ToString()); }
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 }); }
public object VisitLiteralExpr(Expr.Literal expr) { return(null); }
public VoidObject VisitLiteralExpr(Expr.Literal expr) { return(VoidObject.Void); }
public Token visitLiteralExpr(Expr.Literal literal) { return(literal.type); }
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); }
public object VisitLiteralExpr(Expr.Literal expr) { return(expr.value); }
/// <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--; } }
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); }
public object Visit(Expr.Literal expr) { return(expr.Value); }
public T VisitLiteralExpression(Expr.Literal exp);
public object VisitLiteralExpr(Expr.Literal expr, object options = null) { return(null); }
object Expr.Visitor <object> .VisitLiteralExpr(Expr.Literal expr) { return(expr.value); }
public string VisitLiteralExpr(Expr.Literal expr) { return(expr.value == null ? "nil" : expr.value.ToString()); }
public string VisitLiteralExpr(Expr.Literal expr) => expr.Value == null ? "nil" : expr.Value.ToString();
public void Visit(Expr.Literal expr) => _sql.Append($"'{expr.Value}'");
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--; } }
public string VisitLiteralExpr(Expr.Literal expr) => (expr.value == null) ? "null" : expr.value.ToString();
public TrashObject VisitLiteralExpr(Expr.Literal expr) { return(expr.Value); }
public Unit VisitLiteralExpr(Expr.Literal expr) { return(new Unit()); }
public LoxVoid VisitLiteralExpr(Expr.Literal expr) { return(null); }