public override void Visit(DoubleLiteral node) { PushLocation(node); _ilGen.Ldc_R8(node.Value); _result.ValueType = mdr.ValueTypes.Double; PopLocation(); }
override public void VisitDoubleLiteral(DoubleLiteral x) { //string format = "FloatingPoint"; //switch (x.Format) //{ // case Literal.LiteralFormat.ExponentialSmall: format = "ExponentialSmall"; break; // case Literal.LiteralFormat.ExponentialBig: format = "ExponentialBig"; break; //} _serializer.Serialize(typeof(DoubleLiteral).Name, SerializeSpan(x.Span), new NodeObj("Value", x.Value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)) /*, new NodeObj("Format", format)*/); }
public static LispLiteral Add(Context context, params LispLiteral[] args) { var evaluatedArgs = EvalArgs(context, args.ToList()); if (evaluatedArgs.Count != 2) { throw new LispPrimitiveBadArgNumber("ADD", 1, evaluatedArgs.Count); } var v1 = evaluatedArgs[0] as LispLiteral; var v2 = evaluatedArgs[1] as LispLiteral; var t1 = v1.Type; var t2 = v2.Type; if (!v1.IsNumericType) { throw new LispPrimitiveBadArgType("ADD", 1, LispValueType.Numeric, t1); } if (!v2.IsNumericType) { throw new LispPrimitiveBadArgType("ADD", 1, LispValueType.Numeric, t2); } var resultType = t1 == LispValueType.Double || t2 == LispValueType.Double ? LispValueType.Double : LispValueType.Int; LispLiteral result = null; if (resultType == LispValueType.Double) { result = new DoubleLiteral(v1.DoubleValue + v2.DoubleValue); } else if (resultType == LispValueType.Int) { result = new IntLiteral(v1.IntValue + v2.IntValue); } else { result = NilLiteral.Instance; } return(result); }
public static Literal /*!*/ Create(Text.Span position, object value, AccessType access) { Literal result; if (value == null) { result = new NullLiteral(position); } else if (value.GetType() == typeof(int)) { result = new IntLiteral(position, (int)value); } else if (value.GetType() == typeof(string)) { result = new StringLiteral(position, (string)value); } else if (value.GetType() == typeof(bool)) { result = new BoolLiteral(position, (bool)value); } else if (value.GetType() == typeof(double)) { result = new DoubleLiteral(position, (double)value); } else if (value.GetType() == typeof(long)) { result = new LongIntLiteral(position, (long)value); } else if (value.GetType() == typeof(PhpBytes)) { result = new BinaryStringLiteral(position, ((PhpBytes)value).ReadonlyData); } else { throw new ArgumentException("value"); } // Debug.Assert(result != null); result.NodeCompiler <IExpressionCompiler>().Access = access; // return(result); }
private Expression ParseExpr() { if (this.index == this.tokens.Count) { throw new System.Exception("expected expression, got EOF"); } if (this.tokens[this.index] is Text.StringBuilder) { string value = ((Text.StringBuilder) this.tokens[this.index++]).ToString(); StringLiteral stringLiteral = new StringLiteral(); stringLiteral.Value = value; return(stringLiteral); } else if (this.tokens[this.index] is int) { int intValue = (int)this.tokens[this.index++]; IntLiteral intLiteral = new IntLiteral(); intLiteral.Value = intValue; return(intLiteral); } else if (this.tokens[this.index] is double) { double doubleValue = (double)this.tokens[this.index++]; DoubleLiteral doubleLiteral = new DoubleLiteral(); doubleLiteral.Value = doubleValue; return(doubleLiteral); } else if (this.tokens[this.index] is string) { string ident = (string)this.tokens[this.index++]; Variable var = new Variable(); var.Ident = ident; return(var); } else { throw new System.Exception("expected string literal, int literal, double literal or variable"); } }
public override void VisitDoubleLiteral(DoubleLiteral x) { VisitSpecificElementProlog(); SerializeToken(nameof(x.Value), x.Value.ToString(), x.Span); }
virtual public void VisitDoubleLiteral(DoubleLiteral x) { // nothing }
override public void VisitDoubleLiteral(DoubleLiteral x) { _serializer.Serialize(typeof(DoubleLiteral).Name, SerializeSpan(x.Span), new NodeObj("Value", x.Value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo))); }
private Expression AtomExpression() { if (Current.TokenKind == TokenKind.StringStart) { return ReadString(); } else if (Current.TokenKind == TokenKind.ID) { Token id = Consume(); Expression exp = null; if (Current.TokenKind == TokenKind.LParen) { Consume(); Expression[] args = ReadArguments(); Consume(TokenKind.RParen); exp = new FCall(id.Line, id.Col, id.Data, args); } else { exp = new Name(id.Line, id.Col, id.Data); } while (Current.TokenKind == TokenKind.Dot || Current.TokenKind == TokenKind.LBracket) { if (Current.TokenKind == TokenKind.Dot) { Consume(); Token field = Consume(TokenKind.ID); if (Current.TokenKind == TokenKind.LParen) { Consume(); Expression[] args = ReadArguments(); Consume(TokenKind.RParen); exp = new MCall(field.Line, field.Col, exp, field.Data, args); } else { exp = new FieldAccess(field.Line, field.Col, exp, field.Data); } } else { Token bracket = Current; Consume(); Expression indexExp = TopExpression(); Consume(TokenKind.RBracket); exp = new ArrayAccess(bracket.Line, bracket.Col, exp, indexExp); } } return exp; } else if (Current.TokenKind == TokenKind.Integer) { int value = int.Parse(Current.Data); IntLiteral intLiteral = new IntLiteral(Current.Line, Current.Col, value); Consume(); return intLiteral; } else if (Current.TokenKind == TokenKind.Double) { double value = double.Parse(Current.Data); DoubleLiteral dLiteral = new DoubleLiteral(Current.Line, Current.Col, value); Consume(); return dLiteral; } else if (Current.TokenKind == TokenKind.LParen) { Consume(); Expression exp = TopExpression(); Consume(TokenKind.RParen); return exp; } else { throw new TmplException(string.Format("Invalid token in expression: " + Current.TokenKind + ". Was expecting ID or string.L{0}/C{1}", Current.Line, Current.Col), Current.Line, Current.Col); } }
/// <inheritdoc /> public override void VisitDoubleLiteral(DoubleLiteral x) { RValueResult(x); }
/// <summary> /// Create double representation of given literal /// </summary> /// <param name="x">Literal value</param> /// <returns>Created literal value representation</returns> public virtual MemoryEntry DoubleLiteral(DoubleLiteral x) { return(new MemoryEntry(OutSet.CreateDouble((double)x.Value))); }
public override void Visit(DoubleLiteral node) { AssignToImplicitReturn(node); }
public override void visit(DoubleLiteral n) { n.Scope = Scope; }
private XPathExpr make_double_lit(double d) { DoubleLiteral dl = new DoubleLiteral(d); return(make_xpathexpr(dl)); }
public override void Visit(DoubleLiteral node) { WriteNode(node, node.Value.ToString()); }
Expression PrimaryExpression() { if (Current.TokenKind == TokenKind.StringStart) { return(ReadString()); } else if (Current.TokenKind == TokenKind.ID) { Token id = Consume(); Expression exp = null; // if ( follows ID, we have a function call if (Current.TokenKind == TokenKind.LParen) { Consume(); // consume LParen Expression[] args = ReadArguments(); Consume(TokenKind.RParen); exp = new FCall(id.Line, id.Col, id.Data, args); } else // else, we just have id { exp = new Name(id.Line, id.Col, id.Data); } // while we have ".", keep chaining up field access or method call while (Current.TokenKind == TokenKind.Dot || Current.TokenKind == TokenKind.LBracket) { if (Current.TokenKind == TokenKind.Dot) { Consume(); // consume DOT Token field = Consume(TokenKind.ID); // consume ID after dot // if "(" after ID, then it's a method call if (Current.TokenKind == TokenKind.LParen) { Consume(); // consume "(" Expression[] args = ReadArguments(); Consume(TokenKind.RParen); // read ")" exp = new MethodCall(field.Line, field.Col, exp, field.Data, args); } else { exp = new FieldAccess(field.Line, field.Col, exp, field.Data); } } else // must be LBracket { // array access Token bracket = Current; Consume(); // consume [ Expression indexExp = TopExpression(); Consume(TokenKind.RBracket); exp = new ArrayAccess(bracket.Line, bracket.Col, exp, indexExp); } } return(exp); } else if (Current.TokenKind == TokenKind.Integer) { int value = Int32.Parse(Current.Data); IntLiteral intLiteral = new IntLiteral(Current.Line, Current.Col, value); Consume(); // consume int return(intLiteral); } else if (Current.TokenKind == TokenKind.Double) { double value = Double.Parse(Current.Data); DoubleLiteral dLiteral = new DoubleLiteral(Current.Line, Current.Col, value); Consume(); // consume int return(dLiteral); } else if (Current.TokenKind == TokenKind.LParen) { Consume(); // eat ( Expression exp = TopExpression(); Consume(TokenKind.RParen); // eat ) return(exp); } else { throw new ParseException("Invalid token in expression: " + Current.TokenKind + ". Was expecting ID or string.", Current.Line, Current.Col); } }
private void TokenPush(bool as_string) { if(current_token.Length == 0 && !as_string) { return; } TreeNode node = null; string token = current_token.ToString(); if(Debug) { Console.Write("{3}[{0}] TOKEN({4},{5}): [{2}{1}{2}]", scope, token, as_string ? "\"" : String.Empty, String.Empty.PadLeft(scope - 1, ' '), line, column - current_token.Length); } if(as_string) { node = new StringLiteral(token); } else if(token == "#t") { node = new BooleanLiteral(true); } else if(token == "#f") { node = new BooleanLiteral(false); } else if(token.Length > 0 && token != "." && token != "-" && token != "+" && number_regex.IsMatch(token)) { try { if(token.StartsWith("0x") || token.StartsWith("-0x")) { int offset = token[0] == '-' ? 3 : 2; int value = Int32.Parse(token.Substring(offset), NumberStyles.HexNumber, culture_info.NumberFormat); node = new IntLiteral(value * (offset == 3 ? -1 : 1)); } else if(token.Contains(".")) { node = new DoubleLiteral(Double.Parse(token, NumberStyles.Float, culture_info.NumberFormat)); } else { node = new IntLiteral(Int32.Parse(token, NumberStyles.Integer, culture_info.NumberFormat)); } } catch { throw new FormatException("Invalid number format: " + token); } } else { node = new FunctionNode(token); } if(Debug) { Console.WriteLine(" => [{0}]", node); } node.Line = line; node.Column = column; current_parent.AddChild(node); current_token.Remove(0, current_token.Length); }
public override void Visit(DoubleLiteral node) { Visit((Literal)node); }
/// <summary> /// Visits the double literal. /// </summary> /// <param name="x">The x.</param> public override void VisitDoubleLiteral(DoubleLiteral x) { initializationValue = expressionResolver.DoubleLiteral(x); }
public override void Visit(DoubleLiteral node) { UpdateType(node, TypeCalculator.GetType(node)); }
private Expression AtomExpression() { if (Current.TokenKind == TokenKind.StringStart) { return(ReadString()); } else if (Current.TokenKind == TokenKind.ID) { Token id = Consume(); Expression exp = null; if (Current.TokenKind == TokenKind.LParen) { Consume(); Expression[] args = ReadArguments(); Consume(TokenKind.RParen); exp = new FCall(id.Line, id.Col, id.Data, args); } else { exp = new Name(id.Line, id.Col, id.Data); } while (Current.TokenKind == TokenKind.Dot || Current.TokenKind == TokenKind.LBracket) { if (Current.TokenKind == TokenKind.Dot) { Consume(); Token field = Consume(TokenKind.ID); if (Current.TokenKind == TokenKind.LParen) { Consume(); Expression[] args = ReadArguments(); Consume(TokenKind.RParen); exp = new MCall(field.Line, field.Col, exp, field.Data, args); } else { exp = new FieldAccess(field.Line, field.Col, exp, field.Data); } } else { Token bracket = Current; Consume(); Expression indexExp = TopExpression(); Consume(TokenKind.RBracket); exp = new ArrayAccess(bracket.Line, bracket.Col, exp, indexExp); } } return(exp); } else if (Current.TokenKind == TokenKind.Integer) { int value = int.Parse(Current.Data); IntLiteral intLiteral = new IntLiteral(Current.Line, Current.Col, value); Consume(); return(intLiteral); } else if (Current.TokenKind == TokenKind.Double) { double value = double.Parse(Current.Data); DoubleLiteral dLiteral = new DoubleLiteral(Current.Line, Current.Col, value); Consume(); return(dLiteral); } else if (Current.TokenKind == TokenKind.LParen) { Consume(); Expression exp = TopExpression(); Consume(TokenKind.RParen); return(exp); } else { throw new VoltException(string.Format("Invalid token in expression: " + Current.TokenKind + ". Was expecting ID or string.L{0}/C{1}", Current.Line, Current.Col), Current.Line, Current.Col); } }
public override void VisitDoubleLiteral(DoubleLiteral x) { visitConstantNularyElement(x, (e) => e.DoubleLiteral(x) ); }
public void visit(DoubleLiteral n) { throw new NotImplementedException(); }
/// <summary> /// Validate a double literal. /// </summary> /// <param name="e"> /// is the expression. </param> /// <returns> null. </returns> public virtual object visit(DoubleLiteral e) { return(null); }
/// <inheritdoc /> public override void VisitDoubleLiteral(DoubleLiteral x) { literal = outSet.CreateDouble((double)x.Value); }
Expression PrimaryExpression() { if (Current.TokenKind == TokenKind.StringStart) return ReadString(); else if (Current.TokenKind == TokenKind.ID) { Token id = Consume(); Expression exp = null; // if ( follows ID, we have a function call if (Current.TokenKind == TokenKind.LParen) { Consume(); // consume LParen Expression[] args = ReadArguments(); Consume(TokenKind.RParen); exp = new FCall(id.Line, id.Col, id.Data, args); } else // else, we just have id exp = new Name(id.Line, id.Col, id.Data); // while we have ".", keep chaining up field access or method call while (Current.TokenKind == TokenKind.Dot || Current.TokenKind == TokenKind.LBracket) { if (Current.TokenKind == TokenKind.Dot) { Consume(); // consume DOT Token field = Consume(TokenKind.ID); // consume ID after dot // if "(" after ID, then it's a method call if (Current.TokenKind == TokenKind.LParen) { Consume(); // consume "(" Expression[] args = ReadArguments(); Consume(TokenKind.RParen); // read ")" exp = new MethodCall(field.Line, field.Col, exp, field.Data, args); } else exp = new FieldAccess(field.Line, field.Col, exp, field.Data); } else // must be LBracket { // array access Token bracket = Current; Consume(); // consume [ Expression indexExp = TopExpression(); Consume(TokenKind.RBracket); exp = new ArrayAccess(bracket.Line, bracket.Col, exp, indexExp); } } return exp; } else if (Current.TokenKind == TokenKind.Integer) { int value = Int32.Parse(Current.Data); IntLiteral intLiteral = new IntLiteral(Current.Line, Current.Col, value); Consume(); // consume int return intLiteral; } else if (Current.TokenKind == TokenKind.Double) { double value = Double.Parse(Current.Data); DoubleLiteral dLiteral = new DoubleLiteral(Current.Line, Current.Col, value); Consume(); // consume int return dLiteral; } else if (Current.TokenKind == TokenKind.LParen) { Consume(); // eat ( Expression exp = TopExpression(); Consume(TokenKind.RParen); // eat ) return exp; } else throw new ParseException("Invalid token in expression: " + Current.TokenKind + ". Was expecting ID or string.", Current.Line, Current.Col); }
public override void Visit(DoubleLiteral node) { unfinishedClone = new DoubleLiteral(node.Value, node.SourceOffset); base.Visit(node); }
public override void VisitDoubleLiteral(DoubleLiteral x) { _composer.ConsumeLiteral(x); }
public ASTType visit(DoubleLiteral n) { return new DoubleType(); }