From 50ea5ab6baf31da6fa3be4f1420d683fd54013cd Mon Sep 17 00:00:00 2001 From: Dietrich Date: Mon, 20 Apr 2015 04:17:46 -0600 Subject: Added float type to the Parser and Scanner --- Source/Core/Parser.cs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'Source/Core/Parser.cs') diff --git a/Source/Core/Parser.cs b/Source/Core/Parser.cs index 696a72ed..5545d8c4 100644 --- a/Source/Core/Parser.cs +++ b/Source/Core/Parser.cs @@ -1717,7 +1717,7 @@ out List/*!*/ ins, out List/*!*/ outs, out QKeyValue kv) { } void AtomExpression(out Expr/*!*/ e) { - Contract.Ensures(Contract.ValueAtReturn(out e) != null); IToken/*!*/ x; int n; BigNum bn; BigDec bd; + Contract.Ensures(Contract.ValueAtReturn(out e) != null); IToken/*!*/ x; int n; BigNum bn; BigDec bd; FP32 fp; List/*!*/ es; List/*!*/ ds; Trigger trig; List/*!*/ typeParams; IdentifierExpr/*!*/ id; @@ -1742,11 +1742,16 @@ out List/*!*/ ins, out List/*!*/ outs, out QKeyValue kv) { e = new LiteralExpr(t, bn); break; } - case 5: case 6: { + case 5: { Dec(out bd); e = new LiteralExpr(t, bd); break; } + case 6: { + Float(out fp); + e = new LiteralExpr(t, fp); + break; + } case 2: { BvLit(out bn, out n); e = new LiteralExpr(t, bn, n); @@ -1856,6 +1861,21 @@ out List/*!*/ ins, out List/*!*/ outs, out QKeyValue kv) { } + void Float(out FP32 n) + { + string s = ""; + if (la.kind == 6) { + Get(); + s = t.val; + } else SynErr(126); + try { + n = FP32.FromString(s); + } catch (FormatException) { + this.SemErr("incorrectly formatted number"); + n = FP32.ZERO; + } + } + void BvLit(out BigNum n, out int m) { Expect(2); int pos = t.val.IndexOf("bv"); -- cgit v1.2.3