summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar mikebarnett <unknown>2010-06-22 17:58:58 +0000
committerGravatar mikebarnett <unknown>2010-06-22 17:58:58 +0000
commit67c07706d2b4ee941954301a0c18abfcf253384c (patch)
tree994d3e772c2fce65605bd28b947ed7f2ede9d00a
parent98ee7b446b22df255ecf914d68f1997ea987877e (diff)
Updated the frame files to work with the latest Coco/R. This entails *not* having them in this repository because of license issues. Instead, they must be downloaded from http://boogiepartners.codeplex.com/ and then copied into the appropriate directories.
Lots of code changes to compensate for the new frame files.
-rw-r--r--Source/BoogieDriver/BoogieDriver.ssc11
-rw-r--r--Source/Core/Absy.ssc15
-rw-r--r--Source/Core/AbsyCmd.ssc16
-rw-r--r--Source/Core/BoogiePL.atg244
-rw-r--r--Source/Core/Core.sscproj4
-rw-r--r--Source/Core/Makefile7
-rw-r--r--Source/Core/Parser.ssc1234
-rw-r--r--Source/Core/ParserHelper.ssc116
-rw-r--r--Source/Core/Scanner.ssc1095
-rw-r--r--Source/Core/parser.frame103
-rw-r--r--Source/Core/scanner.frame377
-rw-r--r--Source/Dafny/Dafny.atg314
-rw-r--r--Source/Dafny/DafnyAst.ssc149
-rw-r--r--Source/Dafny/DafnyMain.ssc3
-rw-r--r--Source/Dafny/Makefile7
-rw-r--r--Source/Dafny/Parser.ssc1248
-rw-r--r--Source/Dafny/Resolver.ssc7
-rw-r--r--Source/Dafny/Scanner.ssc902
-rw-r--r--Source/Dafny/Translator.ssc115
-rw-r--r--Source/Dafny/parser.frame103
-rw-r--r--Source/Dafny/scanner.frame170
-rw-r--r--Source/DafnyDriver/DafnyDriver.ssc6
-rw-r--r--Test/test0/Answer4
23 files changed, 3072 insertions, 3178 deletions
diff --git a/Source/BoogieDriver/BoogieDriver.ssc b/Source/BoogieDriver/BoogieDriver.ssc
index 179cba3c..c1bf358e 100644
--- a/Source/BoogieDriver/BoogieDriver.ssc
+++ b/Source/BoogieDriver/BoogieDriver.ssc
@@ -21,6 +21,7 @@ namespace Microsoft.Boogie
using VC;
using Cci = System.Compiler;
using AI = Microsoft.AbstractInterpretationFramework;
+ using BoogiePL = Microsoft.Boogie;
/*
The following assemblies are referenced because they are needed at runtime, not at compile time:
@@ -206,7 +207,7 @@ namespace Microsoft.Boogie
static void ProcessFiles (List<string!>! fileNames)
{
using (XmlFileScope xf = new XmlFileScope(CommandLineOptions.Clo.XmlSink, fileNames[fileNames.Count-1])) {
- BoogiePL.Errors.count = 0;
+ //BoogiePL.Errors.count = 0;
Program program = ParseBoogieProgram(fileNames, false);
if (program == null) return;
if (CommandLineOptions.Clo.PrintFile != null) {
@@ -215,10 +216,10 @@ namespace Microsoft.Boogie
PipelineOutcome oc = ResolveAndTypecheck(program, fileNames[fileNames.Count-1]);
if (oc != PipelineOutcome.ResolvedAndTypeChecked) return;
- BoogiePL.Errors.count = 0;
+ //BoogiePL.Errors.count = 0;
oc = EliminateDeadVariablesAndInline(program);
- BoogiePL.Errors.count = 0;
+ //BoogiePL.Errors.count = 0;
int errorCount, verified, inconclusives, timeOuts, outOfMemories;
oc = InferAndVerify(program, null, out errorCount, out verified, out inconclusives, out timeOuts, out outOfMemories);
@@ -332,7 +333,7 @@ namespace Microsoft.Boogie
/// </summary>
static Program ParseBoogieProgram(List<string!>! fileNames, bool suppressTraceOutput)
{
- BoogiePL.Errors.count = 0;
+ //BoogiePL.Errors.count = 0;
Program program = null;
bool okay = true;
foreach (string bplFileName in fileNames) {
@@ -350,7 +351,7 @@ namespace Microsoft.Boogie
try {
errorCount = BoogiePL.Parser.Parse(bplFileName, out programSnippet);
if (programSnippet == null || errorCount != 0) {
- Console.WriteLine("{0} parse errors detected in {1}", BoogiePL.Errors.count, bplFileName);
+ Console.WriteLine("{0} parse errors detected in {1}", errorCount, bplFileName);
okay = false;
continue;
}
diff --git a/Source/Core/Absy.ssc b/Source/Core/Absy.ssc
index 6b4cae62..07723e4d 100644
--- a/Source/Core/Absy.ssc
+++ b/Source/Core/Absy.ssc
@@ -1680,17 +1680,26 @@ namespace Microsoft.Boogie
VariableSeq! inParams, VariableSeq! outParams,
VariableSeq! localVariables, [Captured] StmtList! structuredStmts)
{
- this(tok, name, typeParams, inParams, outParams, localVariables, structuredStmts, null);
+ this(tok, name, typeParams, inParams, outParams, localVariables, structuredStmts, null, new Errors());
}
public Implementation(IToken! tok, string! name, TypeVariableSeq! typeParams,
VariableSeq! inParams, VariableSeq! outParams,
- VariableSeq! localVariables, [Captured] StmtList! structuredStmts, QKeyValue kv)
+ VariableSeq! localVariables, [Captured] StmtList! structuredStmts,
+ Errors! errorHandler)
+ {
+ this(tok, name, typeParams, inParams, outParams, localVariables, structuredStmts, null, errorHandler);
+ }
+
+ public Implementation(IToken! tok, string! name, TypeVariableSeq! typeParams,
+ VariableSeq! inParams, VariableSeq! outParams,
+ VariableSeq! localVariables, [Captured] StmtList! structuredStmts, QKeyValue kv,
+ Errors! errorHandler)
: base(tok, name, typeParams, inParams, outParams)
{
LocVars = localVariables;
StructuredStmts = structuredStmts;
- BigBlocksResolutionContext ctx = new BigBlocksResolutionContext(structuredStmts);
+ BigBlocksResolutionContext ctx = new BigBlocksResolutionContext(structuredStmts, errorHandler);
Blocks = ctx.Blocks;
BlockPredecessorsComputed = false;
scc = null;
diff --git a/Source/Core/AbsyCmd.ssc b/Source/Core/AbsyCmd.ssc
index bf80116c..d682029e 100644
--- a/Source/Core/AbsyCmd.ssc
+++ b/Source/Core/AbsyCmd.ssc
@@ -202,9 +202,11 @@ namespace Microsoft.Boogie
string! prefix = "anon";
int anon = 0;
Set<string!> allLabels = new Set<string!>();
+ Errors! errorHandler;
- public BigBlocksResolutionContext(StmtList! stmtList) {
+ public BigBlocksResolutionContext(StmtList! stmtList, Errors! errorHandler) {
this.stmtList = stmtList;
+ this.errorHandler = errorHandler;
}
public List<Block!>! Blocks {
@@ -212,7 +214,7 @@ namespace Microsoft.Boogie
if (blocks == null) {
blocks = new List<Block!>();
- int startErrorCount = BoogiePL.Errors.count;
+ int startErrorCount = this.errorHandler.count;
// Check that there are no goto's into the middle of a block, and no break statement to a non-enclosing loop.
// Also, determine a good value for "prefix".
CheckLegalLabels(stmtList, null, null);
@@ -223,7 +225,7 @@ namespace Microsoft.Boogie
// determine successor blocks
RecordSuccessors(stmtList, null);
- if (BoogiePL.Errors.count == startErrorCount) {
+ if (this.errorHandler.count == startErrorCount) {
// generate blocks from the big blocks
CreateBlocks(stmtList, null);
}
@@ -270,7 +272,7 @@ namespace Microsoft.Boogie
}
}
if (!found) {
- BoogiePL.Errors.SemErr(g.tok, "Error: goto label '" + lbl + "' is undefined or out of reach");
+ this.errorHandler.SemErr(g.tok, "Error: goto label '" + lbl + "' is undefined or out of reach");
}
}
}
@@ -299,7 +301,7 @@ namespace Microsoft.Boogie
bcmd.BreakEnclosure = bb;
} else {
// the label of bb refers to the first statement of bb, which in which case is a simple statement, not an if/while statement
- BoogiePL.Errors.SemErr(bcmd.tok, "Error: break label '" + bcmd.Label + "' must designate an enclosing statement");
+ this.errorHandler.SemErr(bcmd.tok, "Error: break label '" + bcmd.Label + "' must designate an enclosing statement");
}
found = true; // don't look any further, since we've found a matching label
break;
@@ -307,9 +309,9 @@ namespace Microsoft.Boogie
}
if (!found) {
if (bcmd.Label == null) {
- BoogiePL.Errors.SemErr(bcmd.tok, "Error: break statement is not inside a loop");
+ this.errorHandler.SemErr(bcmd.tok, "Error: break statement is not inside a loop");
} else {
- BoogiePL.Errors.SemErr(bcmd.tok, "Error: break label '" + bcmd.Label + "' must designate an enclosing statement");
+ this.errorHandler.SemErr(bcmd.tok, "Error: break label '" + bcmd.Label + "' must designate an enclosing statement");
}
}
}
diff --git a/Source/Core/BoogiePL.atg b/Source/Core/BoogiePL.atg
index aded331b..896dc0e5 100644
--- a/Source/Core/BoogiePL.atg
+++ b/Source/Core/BoogiePL.atg
@@ -7,6 +7,8 @@
using PureCollections;
using System.Collections;
using System.Collections.Generic;
+using System.IO;
+using System.Text;
using Microsoft.Boogie;
using Microsoft.Basetypes;
using Bpl = Microsoft.Boogie;
@@ -33,22 +35,24 @@ static StructuredCmd! dummyStructuredCmd = new BreakCmd(Token.NoToken, null);
///the parsed program.
///</summary>
public static int Parse (string! filename, out /*maybe null*/ Program program) /* throws System.IO.IOException */ {
- using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) {
- Buffer.Fill(reader);
- Scanner.Init(filename);
- return Parse(out program);
- }
-}
-///<summary>
-///Returns the number of parsing errors encountered. If 0, "program" returns as
-///the parsed program.
-///Note: first initialize the Scanner.
-///</summary>
-public static int Parse (out /*maybe null*/ Program program) {
+
+ FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
+// Scanner scanner = new Scanner(stream);
+
+ string s = ParserHelper.Fill(stream,new List<string!>());
+ byte[]! buffer = (!) UTF8Encoding.Default.GetBytes(s);
+ MemoryStream ms = new MemoryStream(buffer,false);
+ Errors errors = new Errors();
+ Scanner scanner = new Scanner(ms, errors, filename);
+
+/*
+ Scanner scanner = new Scanner(filename);
+*/
+ Parser parser = new Parser(scanner, errors);
Pgm = new Program(); // reset the global variable
- Parse();
- if (Errors.count == 0)
+ parser.Parse();
+ if (parser.errors.count == 0)
{
program = Pgm;
return 0;
@@ -56,22 +60,50 @@ public static int Parse (out /*maybe null*/ Program program) {
else
{
program = null;
- return Errors.count;
+ return parser.errors.count;
}
+/*
+ using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) {
+ Buffer.Fill(reader);
+ Scanner.Init(filename);
+ return Parse(out program);
+ }
+*/
}
-
+///<summary>
+///Returns the number of parsing errors encountered. If 0, "program" returns as
+///the parsed program.
+///Note: first initialize the Scanner.
+///</summary>
+//public static int Parse (out /*maybe null*/ Program program) {
+// Pgm = new Program(); // reset the global variable
+// Parse();
+// if (Errors.count == 0)
+// {
+// program = Pgm;
+// return 0;
+// }
+// else
+// {
+// program = null;
+// return Errors.count;
+// }
+//}
+
+/*
public static int ParseProposition (string! text, out Expr! expression)
{
Buffer.Fill(text);
Scanner.Init(string.Format("\"{0}\"", text));
Errors.SynErr = new ErrorProc(SynErr);
- t = new Token();
+ la = new Token();
Get();
Proposition(out expression);
return Errors.count;
}
+*/
// Class to represent the bounds of a bitvector expression t[a:b].
// Objects of this class only exist during parsing and are directly
@@ -228,7 +260,7 @@ IdsTypeWhere<bool allowWhereClauses, TypedIdentSeq! tyds>
[ "where" Expression<out nne> (. if (allowWhereClauses) {
wh = nne;
} else {
- SemErr("where clause not allowed here");
+ this.SemErr("where clause not allowed here");
}
.)
]
@@ -267,8 +299,8 @@ TypeArgs<TypeSeq! ts>
TypeAtom<out Bpl.Type! ty>
= (. ty = dummyType; .)
- ( "int" (. ty = new BasicType(token, SimpleType.Int); .)
- | "bool" (. ty = new BasicType(token, SimpleType.Bool); .)
+ ( "int" (. ty = new BasicType(t, SimpleType.Int); .)
+ | "bool" (. ty = new BasicType(t, SimpleType.Bool); .)
/* note: bitvectors are handled in UnresolvedTypeIdentifier */
|
"("
@@ -285,7 +317,7 @@ MapType<out Bpl.Type! ty>
TypeVariableSeq! typeParameters = new TypeVariableSeq();
.)
[ TypeParams<out nnTok, out typeParameters> (. tok = nnTok; .) ]
- "[" (. if (tok == null) tok = token; .)
+ "[" (. if (tok == null) tok = t; .)
[ Types<arguments> ]
"]"
Type<out result>
@@ -296,7 +328,7 @@ MapType<out Bpl.Type! ty>
TypeParams<out IToken! tok, out Bpl.TypeVariableSeq! typeParams>
= (. TokenSeq! typeParamToks; .)
- "<" (. tok = token; .)
+ "<" (. tok = t; .)
Idents<out typeParamToks>
">"
(.
@@ -321,7 +353,7 @@ Consts<out VariableSeq! ds>
bool u = false; QKeyValue kv = null;
bool ChildrenComplete = false;
List<ConstantParent!> Parents = null; .)
- "const" (. y = token; .)
+ "const" (. y = t; .)
{ Attribute<ref kv> }
[ "unique" (. u = true; .)
]
@@ -349,7 +381,7 @@ Consts<out VariableSeq! ds>
";"
.
-OrderSpec<out bool ChildrenComplete, out List<ConstantParent!\> Parents>
+OrderSpec<.out bool ChildrenComplete, out List<ConstantParent!> Parents.>
= (. ChildrenComplete = false;
Parents = null;
bool u;
@@ -401,7 +433,7 @@ Function<out DeclarationSeq! ds>
(.
if (retTyd == null) {
// construct a dummy type for the case of syntax error
- tyd = new TypedIdent(token, "", new BasicType(token, SimpleType.Int));
+ tyd = new TypedIdent(t, "", new BasicType(t, SimpleType.Int));
} else {
tyd = retTyd;
}
@@ -421,7 +453,7 @@ Function<out DeclarationSeq! ds>
TypedIdent! curr = ((!)arguments[i]).TypedIdent;
if (curr.Name == "") {
if (prevType == null) {
- SemErr(curr.tok, "the type of the last parameter is unspecified");
+ this.errors.SemErr(curr.tok, "the type of the last parameter is unspecified");
break;
}
Type ty = curr.Type;
@@ -430,7 +462,7 @@ Function<out DeclarationSeq! ds>
curr.Name = ((!)(ty as UnresolvedTypeIdentifier)).Name;
curr.Type = prevType;
} else {
- SemErr(curr.tok, "expecting an identifier as parameter name");
+ this.errors.SemErr(curr.tok, "expecting an identifier as parameter name");
}
} else {
prevType = curr.Type;
@@ -479,7 +511,7 @@ VarOrType<out TypedIdent! tyd>
((!)(ty as UnresolvedTypeIdentifier)).Arguments.Length == 0) {
varName = ((!)(ty as UnresolvedTypeIdentifier)).Name;
} else {
- SemErr("expected identifier before ':'");
+ this.SemErr("expected identifier before ':'");
}
.)
Type<out ty>
@@ -492,12 +524,12 @@ Axiom<out Axiom! m>
= (. Expr! e; QKeyValue kv = null; .)
"axiom"
{ Attribute<ref kv> }
- (. IToken! x = token; .)
+ (. IToken! x = t; .)
Proposition<out e> ";" (. m = new Axiom(x,e, null, kv); .)
.
/*------------------------------------------------------------------------*/
-UserDefinedTypes<out List<Declaration!\>! ts>
+UserDefinedTypes<.out List<Declaration!>! ts.>
= (. Declaration! decl; QKeyValue kv = null; ts = new List<Declaration!> (); .)
"type"
{ Attribute<ref kv> }
@@ -552,7 +584,7 @@ Procedure<out Procedure! proc, out /*maybe null*/ Implementation impl>
(.
// here we attach kv only to the Procedure, not its implementation
impl = new Implementation(x, x.val, typeParams,
- Formal.StripWhereClauses(ins), Formal.StripWhereClauses(outs), locals, stmtList, null);
+ Formal.StripWhereClauses(ins), Formal.StripWhereClauses(outs), locals, stmtList, null, this.errors);
.)
)
(. proc = new Procedure(x, x.val, typeParams, ins, outs, pre, mods, post, kv); .)
@@ -571,7 +603,7 @@ Implementation<out Implementation! impl>
"implementation"
ProcSignature<false, out x, out typeParams, out ins, out outs, out kv>
ImplBody<out locals, out stmtList>
- (. impl = new Implementation(x, x.val, typeParams, ins, outs, locals, stmtList, kv); .)
+ (. impl = new Implementation(x, x.val, typeParams, ins, outs, locals, stmtList, kv, this.errors); .)
.
@@ -602,14 +634,14 @@ Spec<RequiresSeq! pre, IdentifierExprSeq! mods, EnsuresSeq! post>
SpecPrePost<bool free, RequiresSeq! pre, EnsuresSeq! post>
= (. Expr! e; VariableSeq! locals; BlockSeq! blocks; Token tok = null; QKeyValue kv = null; .)
- ( "requires" (. tok = token; .)
+ ( "requires" (. tok = t; .)
{ Attribute<ref kv> }
(Proposition<out e> ";" (. pre.Add(new Requires(tok, free, e, null, kv)); .)
|
SpecBody<out locals, out blocks> ";"
(. pre.Add(new Requires(tok, free, new BlockExpr(locals, blocks), null, kv)); .)
)
- | "ensures" (. tok = token; .)
+ | "ensures" (. tok = t; .)
{ Attribute<ref kv> }
(Proposition<out e> ";" (. post.Add(new Ensures(tok, free, e, null, kv)); .)
|
@@ -645,16 +677,16 @@ SpecBlock<out Block! b>
cs.Add(c);
} else {
assert label != null;
- SemErr("SpecBlock's can only have one label");
+ this.SemErr("SpecBlock's can only have one label");
}
.)
}
- ( "goto" (. y = token; .)
+ ( "goto" (. y = t; .)
Idents<out xs> (. foreach (IToken! s in xs) { ss.Add(s.val); }
b = new Block(x,x.val,cs,new GotoCmd(y,ss));
.)
| "return" Expression<out e>
- (. b = new Block(x,x.val,cs,new ReturnExprCmd(token,e)); .)
+ (. b = new Block(x,x.val,cs,new ReturnExprCmd(t,e)); .)
) ";"
.
@@ -724,9 +756,9 @@ StmtList<out StmtList! stmtList>
)
}
"}"
- (. IToken! endCurly = token;
+ (. IToken! endCurly = t;
if (startToken == null && bigblocks.Count == 0) {
- startToken = token; cs = new CmdSeq();
+ startToken = t; cs = new CmdSeq();
}
if (startToken != null) {
assert cs != null;
@@ -743,11 +775,11 @@ TransferCmd<out TransferCmd! tc>
Token y; TokenSeq! xs;
StringSeq ss = new StringSeq();
.)
- ( "goto" (. y = token; .)
+ ( "goto" (. y = t; .)
Idents<out xs> (. foreach (IToken! s in xs) { ss.Add(s.val); }
tc = new GotoCmd(y, ss);
.)
- | "return" (. tc = new ReturnCmd(token); .)
+ | "return" (. tc = new ReturnCmd(t); .)
) ";"
.
@@ -768,7 +800,7 @@ IfCmd<out IfCmd! ifcmd>
IfCmd! elseIf; IfCmd elseIfOption = null;
StmtList! els; StmtList elseOption = null;
.)
- "if" (. x = token; .)
+ "if" (. x = t; .)
Guard<out guard>
"{" StmtList<out thn>
[ "else"
@@ -786,9 +818,9 @@ WhileCmd<out WhileCmd! wcmd>
List<PredicateCmd!> invariants = new List<PredicateCmd!>();
StmtList! body;
.)
- "while" (. x = token; .)
+ "while" (. x = t; .)
Guard<out guard> (. assume guard == null || Owner.None(guard); .)
- { (. isFree = false; z = t/*lookahead token*/; .)
+ { (. isFree = false; z = la/*lookahead token*/; .)
[ "free" (. isFree = true; .)
]
"invariant"
@@ -817,7 +849,7 @@ BreakCmd<out BreakCmd! bcmd>
= (. IToken! x; IToken! y;
string breakLabel = null;
.)
- "break" (. x = token; .)
+ "break" (. x = t; .)
[ Ident<out y> (. breakLabel = y.val; .)
] ";" (. bcmd = new BreakCmd(x, breakLabel); .)
.
@@ -834,14 +866,14 @@ LabelOrCmd<out Cmd c, out IToken label>
QKeyValue kv = null;
.)
( LabelOrAssign<out c, out label>
- | "assert" (. x = token; .)
+ | "assert" (. x = t; .)
{ Attribute<ref kv> }
Proposition<out e> (. c = new AssertCmd(x,e, kv); .)
";"
- | "assume" (. x = token; .)
+ | "assume" (. x = t; .)
Proposition<out e> (. c = new AssumeCmd(x,e); .)
";"
- | "havoc" (. x = token; .)
+ | "havoc" (. x = t; .)
Idents<out xs> ";" (. ids = new IdentifierExprSeq();
foreach (IToken! y in xs) {
ids.Add(new IdentifierExpr(y, y.val));
@@ -862,7 +894,7 @@ LabelOrAssign<out Cmd c, out IToken label>
List<AssignLhs!>! lhss;
List<Expr!>! rhss;
.)
- Ident<out id> (. x = token; .)
+ Ident<out id> (. x = t; .)
( ":" (. c = null; label = x; .)
|
MapAssignIndexes<id, out lhs> (. lhss = new List<AssignLhs!> ();
@@ -871,7 +903,7 @@ LabelOrAssign<out Cmd c, out IToken label>
Ident<out id>
MapAssignIndexes<id, out lhs> (. lhss.Add(lhs); .)
}
- ":=" (. x = token; /* use location of := */ .)
+ ":=" (. x = t; /* use location of := */ .)
Expression<out e0> (. rhss = new List<Expr!> ();
rhss.Add(e0); .)
{ ","
@@ -890,7 +922,7 @@ MapAssignIndexes<IToken! assignedVariable, out AssignLhs! lhs>
Expr! e0;
.)
{
- "[" (. x = token;
+ "[" (. x = t;
indexes = new List<Expr!> (); .)
[
Expression<out e0> (. indexes.Add(e0); .)
@@ -913,7 +945,7 @@ CallCmd<out Cmd! c>
Expr en; List<Expr> args;
c = dummyCmd;
.)
- "call" (. x = token; .)
+ "call" (. x = t; .)
{ Attribute<ref kv> }
( Ident<out first>
( "("
@@ -1033,7 +1065,7 @@ Expressions<out ExprSeq! es>
Expression<out Expr! e0>
= (. IToken! x; Expr! e1; .)
ImpliesExpression<false, out e0>
- { EquivOp (. x = token; .)
+ { EquivOp (. x = t; .)
ImpliesExpression<false, out e1>
(. e0 = Expr.Binary(x, BinaryOperator.Opcode.Iff, e0, e1); .)
}
@@ -1046,19 +1078,19 @@ ImpliesExpression<bool noExplies, out Expr! e0>
= (. IToken! x; Expr! e1; .)
LogicalExpression<out e0>
[
- ImpliesOp (. x = token; .)
+ ImpliesOp (. x = t; .)
/* recurse because implication is right-associative */
ImpliesExpression<true, out e1>
(. e0 = Expr.Binary(x, BinaryOperator.Opcode.Imp, e0, e1); .)
|
ExpliesOp (. if (noExplies)
- SemErr("illegal mixture of ==> and <==, use parentheses to disambiguate");
- x = token; .)
+ this.SemErr("illegal mixture of ==> and <==, use parentheses to disambiguate");
+ x = t; .)
LogicalExpression<out e1>
(. e0 = Expr.Binary(x, BinaryOperator.Opcode.Imp, e1, e0); .)
/* loop because explies is left-associative */
{
- ExpliesOp (. x = token; .)
+ ExpliesOp (. x = t; .)
LogicalExpression<out e1>
(. e0 = Expr.Binary(x, BinaryOperator.Opcode.Imp, e1, e0); .)
}
@@ -1072,17 +1104,17 @@ ExpliesOp = "<==" | '\u21d0'.
LogicalExpression<out Expr! e0>
= (. IToken! x; Expr! e1; BinaryOperator.Opcode op; .)
RelationalExpression<out e0>
- [ AndOp (. x = token; .)
+ [ AndOp (. x = t; .)
RelationalExpression<out e1>
(. e0 = Expr.Binary(x, BinaryOperator.Opcode.And, e0, e1); .)
- { AndOp (. x = token; .)
+ { AndOp (. x = t; .)
RelationalExpression<out e1>
(. e0 = Expr.Binary(x, BinaryOperator.Opcode.And, e0, e1); .)
}
- | OrOp (. x = token; .)
+ | OrOp (. x = t; .)
RelationalExpression<out e1>
(. e0 = Expr.Binary(x, BinaryOperator.Opcode.Or, e0, e1); .)
- { OrOp (. x = token; .)
+ { OrOp (. x = t; .)
RelationalExpression<out e1>
(. e0 = Expr.Binary(x, BinaryOperator.Opcode.Or, e0, e1); .)
}
@@ -1103,16 +1135,16 @@ RelationalExpression<out Expr! e0>
RelOp<out IToken! x, out BinaryOperator.Opcode op>
= (. x = Token.NoToken; op=BinaryOperator.Opcode.Add/*(dummy)*/; .)
- ( "==" (. x = token; op=BinaryOperator.Opcode.Eq; .)
- | "<" (. x = token; op=BinaryOperator.Opcode.Lt; .)
- | ">" (. x = token; op=BinaryOperator.Opcode.Gt; .)
- | "<=" (. x = token; op=BinaryOperator.Opcode.Le; .)
- | ">=" (. x = token; op=BinaryOperator.Opcode.Ge; .)
- | "!=" (. x = token; op=BinaryOperator.Opcode.Neq; .)
- | "<:" (. x = token; op=BinaryOperator.Opcode.Subtype; .)
- | '\u2260' (. x = token; op=BinaryOperator.Opcode.Neq; .)
- | '\u2264' (. x = token; op=BinaryOperator.Opcode.Le; .)
- | '\u2265' (. x = token; op=BinaryOperator.Opcode.Ge; .)
+ ( "==" (. x = t; op=BinaryOperator.Opcode.Eq; .)
+ | "<" (. x = t; op=BinaryOperator.Opcode.Lt; .)
+ | ">" (. x = t; op=BinaryOperator.Opcode.Gt; .)
+ | "<=" (. x = t; op=BinaryOperator.Opcode.Le; .)
+ | ">=" (. x = t; op=BinaryOperator.Opcode.Ge; .)
+ | "!=" (. x = t; op=BinaryOperator.Opcode.Neq; .)
+ | "<:" (. x = t; op=BinaryOperator.Opcode.Subtype; .)
+ | '\u2260' (. x = t; op=BinaryOperator.Opcode.Neq; .)
+ | '\u2264' (. x = t; op=BinaryOperator.Opcode.Le; .)
+ | '\u2265' (. x = t; op=BinaryOperator.Opcode.Ge; .)
)
.
@@ -1120,7 +1152,7 @@ RelOp<out IToken! x, out BinaryOperator.Opcode op>
BvTerm<out Expr! e0>
= (. IToken! x; Expr! e1; .)
Term<out e0>
- { "++" (. x = token; .)
+ { "++" (. x = t; .)
Term<out e1> (. e0 = new BvConcatExpr(x, e0, e1); .)
}
.
@@ -1137,8 +1169,8 @@ Term<out Expr! e0>
AddOp<out IToken! x, out BinaryOperator.Opcode op>
= (. x = Token.NoToken; op=BinaryOperator.Opcode.Add/*(dummy)*/; .)
- ( "+" (. x = token; op=BinaryOperator.Opcode.Add; .)
- | "-" (. x = token; op=BinaryOperator.Opcode.Sub; .)
+ ( "+" (. x = t; op=BinaryOperator.Opcode.Add; .)
+ | "-" (. x = t; op=BinaryOperator.Opcode.Sub; .)
)
.
@@ -1153,9 +1185,9 @@ Factor<out Expr! e0>
MulOp<out IToken! x, out BinaryOperator.Opcode op>
= (. x = Token.NoToken; op=BinaryOperator.Opcode.Add/*(dummy)*/; .)
- ( "*" (. x = token; op=BinaryOperator.Opcode.Mul; .)
- | "/" (. x = token; op=BinaryOperator.Opcode.Div; .)
- | "%" (. x = token; op=BinaryOperator.Opcode.Mod; .)
+ ( "*" (. x = t; op=BinaryOperator.Opcode.Mul; .)
+ | "/" (. x = t; op=BinaryOperator.Opcode.Div; .)
+ | "%" (. x = t; op=BinaryOperator.Opcode.Mod; .)
)
.
@@ -1164,9 +1196,9 @@ UnaryExpression<out Expr! e>
= (. IToken! x;
e = dummyExpr;
.)
- ( "-" (. x = token; .)
+ ( "-" (. x = t; .)
UnaryExpression<out e> (. e = Expr.Binary(x, BinaryOperator.Opcode.Sub, new LiteralExpr(x, BigNum.ZERO), e); .)
- | NegOp (. x = token; .)
+ | NegOp (. x = t; .)
UnaryExpression<out e> (. e = Expr.Unary(x, UnaryOperator.Opcode.Not, e); .)
| CoercionExpression<out e>
)
@@ -1189,14 +1221,14 @@ CoercionExpression<out Expr! e>
BigNum bn;
.)
ArrayExpression<out e>
- { ":" (. x = token; .)
+ { ":" (. x = t; .)
(
Type<out coercedTo> (. e = Expr.CoerceType(x, e, coercedTo); .)
|
Nat<out bn> /* This means that we really look at a bitvector
expression t[a:b] */
(. if (!(e is LiteralExpr) || !((LiteralExpr)e).isBigNum) {
- SemErr("arguments of extract need to be integer literals");
+ this.SemErr("arguments of extract need to be integer literals");
e = new BvBounds(x, bn, BigNum.ZERO);
} else {
e = new BvBounds(x, bn, ((LiteralExpr)e).asBigNum);
@@ -1214,7 +1246,7 @@ ArrayExpression<out Expr! e>
ExprSeq! allArgs = dummyExprSeq;
.)
AtomExpression<out e>
- { "[" (. x = token; allArgs = new ExprSeq ();
+ { "[" (. x = t; allArgs = new ExprSeq ();
allArgs.Add(e);
store = false; bvExtract = false; .)
[
@@ -1226,13 +1258,13 @@ ArrayExpression<out Expr! e>
.)
{ "," Expression<out e1>
(. if (bvExtract || e1 is BvBounds)
- SemErr("bitvectors only have one dimension");
+ this.SemErr("bitvectors only have one dimension");
allArgs.Add(e1);
.)
}
[ ":=" Expression<out e1>
(. if (bvExtract || e1 is BvBounds)
- SemErr("assignment to bitvectors is not possible");
+ this.SemErr("assignment to bitvectors is not possible");
allArgs.Add(e1); store = true;
.)
]
@@ -1262,10 +1294,10 @@ AtomExpression<out Expr! e>
QKeyValue kv;
e = dummyExpr;
.)
- ( "false" (. e = new LiteralExpr(token, false); .)
- | "true" (. e = new LiteralExpr(token, true); .)
- | Nat<out bn> (. e = new LiteralExpr(token, bn); .)
- | BvLit<out bn, out n> (. e = new LiteralExpr(token, bn, n); .)
+ ( "false" (. e = new LiteralExpr(t, false); .)
+ | "true" (. e = new LiteralExpr(t, true); .)
+ | Nat<out bn> (. e = new LiteralExpr(t, bn); .)
+ | BvLit<out bn, out n> (. e = new LiteralExpr(t, bn, n); .)
| Ident<out x> (. id = new IdentifierExpr(x, x.val); e = id; .)
[ "("
@@ -1275,23 +1307,23 @@ AtomExpression<out Expr! e>
")"
]
- | "old" (. x = token; .)
+ | "old" (. x = t; .)
"("
Expression<out e>
")" (. e = new OldExpr(x, e); .)
| "(" ( Expression<out e> (. if (e is BvBounds)
- SemErr("parentheses around bitvector bounds " +
+ this.SemErr("parentheses around bitvector bounds " +
"are not allowed"); .)
- | Forall (. x = token; .)
+ | Forall (. x = t; .)
QuantifierBody<x, out typeParams, out ds, out kv, out trig, out e>
(. if (typeParams.Length + ds.Length > 0)
e = new ForallExpr(x, typeParams, ds, kv, trig, e); .)
- | Exists (. x = token; .)
+ | Exists (. x = t; .)
QuantifierBody<x, out typeParams, out ds, out kv, out trig, out e>
(. if (typeParams.Length + ds.Length > 0)
e = new ExistsExpr(x, typeParams, ds, kv, trig, e); .)
- | Lambda (. x = token; .)
+ | Lambda (. x = t; .)
QuantifierBody<x, out typeParams, out ds, out kv, out trig, out e>
(. if (trig != null)
SemErr("triggers not allowed in lambda expressions");
@@ -1305,7 +1337,7 @@ AtomExpression<out Expr! e>
Attribute<ref QKeyValue kv>
= (. Trigger trig = null; .)
- AttributeOrTrigger<ref kv, ref trig> (. if (trig != null) SemErr("only attributes, not triggers, allowed here"); .)
+ AttributeOrTrigger<ref kv, ref trig> (. if (trig != null) this.SemErr("only attributes, not triggers, allowed here"); .)
.
AttributeOrTrigger<ref QKeyValue kv, ref Trigger trig>
@@ -1313,9 +1345,9 @@ AttributeOrTrigger<ref QKeyValue kv, ref Trigger trig>
string key; string value;
List<object!> parameters; object! param;
.)
- "{" (. tok = token; .)
+ "{" (. tok = t; .)
(
- ":" ident (. key = token.val; parameters = new List<object!>(); .)
+ ":" ident (. key = t.val; parameters = new List<object!>(); .)
[ AttributeParameter<out param> (. parameters.Add(param); .)
{ "," AttributeParameter<out param> (. parameters.Add(param); .)
}
@@ -1329,7 +1361,7 @@ AttributeOrTrigger<ref QKeyValue kv, ref Trigger trig>
trig.AddLast(new Trigger(tok, false, new ExprSeq(e), null));
}
} else {
- SemErr("the 'nopats' quantifier attribute expects a string-literal parameter");
+ this.SemErr("the 'nopats' quantifier attribute expects a string-literal parameter");
}
} else {
if (kv==null) {
@@ -1356,7 +1388,7 @@ AttributeParameter<out object! o>
= (. o = "error";
Expr! e;
.)
- ( string (. o = token.val.Substring(1, token.val.Length-2); .)
+ ( string (. o = t.val.Substring(1, t.val.Length-2); .)
| Expression<out e> (. o = e; .)
)
.
@@ -1365,7 +1397,7 @@ IfThenElseExpression<out Expr! e>
= (. IToken! tok;
Expr! e0, e1, e2;
e = dummyExpr; .)
- "if" (. tok = token; .) Expression<out e0> "then" Expression<out e1> "else" Expression<out e2>
+ "if" (. tok = t; .) Expression<out e0> "then" Expression<out e1> "else" Expression<out e2>
(. e = new NAryExpr(tok, new IfThenElse(tok), new ExprSeq(e0, e1, e2)); .)
.
@@ -1396,7 +1428,7 @@ QSep = "::" | '\u2022'.
/*------------------------------------------------------------------------*/
Ident<out IToken! x>
=
- ident (. x = token;
+ ident (. x = t;
if (x.val.StartsWith("\\"))
x.val = x.val.Substring(1);
.)
@@ -1407,9 +1439,9 @@ Nat<out BigNum n>
=
digits
(. try {
- n = BigNum.FromString(token.val);
+ n = BigNum.FromString(t.val);
} catch (FormatException) {
- SemErr("incorrectly formatted number");
+ this.SemErr("incorrectly formatted number");
n = BigNum.ZERO;
}
.)
@@ -1420,14 +1452,14 @@ BvLit<out BigNum n, out int m>
=
bvlit
(.
- int pos = token.val.IndexOf("bv");
- string a = token.val.Substring(0, pos);
- string b = token.val.Substring(pos + 2);
+ int pos = t.val.IndexOf("bv");
+ string a = t.val.Substring(0, pos);
+ string b = t.val.Substring(pos + 2);
try {
n = BigNum.FromString(a);
m = Convert.ToInt32(b);
} catch (FormatException) {
- SemErr("incorrectly formatted bitvector");
+ this.SemErr("incorrectly formatted bitvector");
n = BigNum.ZERO;
m = 0;
}
diff --git a/Source/Core/Core.sscproj b/Source/Core/Core.sscproj
index 91bbaf47..4929e1c7 100644
--- a/Source/Core/Core.sscproj
+++ b/Source/Core/Core.sscproj
@@ -172,6 +172,10 @@
/>
<File BuildAction="Compile"
SubType="Code"
+ RelPath="ParserHelper.ssc"
+ />
+ <File BuildAction="Compile"
+ SubType="Code"
RelPath="GraphAlgorithms.ssc"
/>
<File BuildAction="Compile"
diff --git a/Source/Core/Makefile b/Source/Core/Makefile
index ee73b25d..d7236a5b 100644
--- a/Source/Core/Makefile
+++ b/Source/Core/Makefile
@@ -1,6 +1,11 @@
COCO = ..\..\Binaries\Coco.exe
ASML = ..\..\Binaries\asmlc.boot.exe
+# ###############################################################################
+# The frame files are no longer in this directory. They must be downloaded
+# from http://boogiepartners.codeplex.com/ and then copied into this directory.
+# ###############################################################################
+
# "all" depends on 2 files, really (Parser.cs and Scanner.cs), but they
# are both generated in one go and I don't know a better way to tell
# nmake that. --KRML
@@ -10,7 +15,7 @@ all: Parser.ssc
# $(ASML) /target:library Graph.as
Parser.ssc: Scanner.frame Parser.frame BoogiePL.atg
- $(COCO) BoogiePL.atg
+ $(COCO) BoogiePL.atg -namespace Microsoft.Boogie
copy Parser.cs Parser.ssc
copy Scanner.cs Scanner.ssc
diff --git a/Source/Core/Parser.ssc b/Source/Core/Parser.ssc
index 60b441cf..f23e0f9e 100644
--- a/Source/Core/Parser.ssc
+++ b/Source/Core/Parser.ssc
@@ -1,27 +1,44 @@
using PureCollections;
using System.Collections;
using System.Collections.Generic;
+using System.IO;
+using System.Text;
using Microsoft.Boogie;
using Microsoft.Basetypes;
using Bpl = Microsoft.Boogie;
using AI = Microsoft.AbstractInterpretationFramework;
+
+
+
+
using System;
using Microsoft.Contracts;
-namespace BoogiePL {
+namespace Microsoft.Boogie {
+
+
public class Parser {
- const int maxT = 88;
+ public const int _EOF = 0;
+ public const int _ident = 1;
+ public const int _bvlit = 2;
+ public const int _digits = 3;
+ public const int _string = 4;
+ public const int _float = 5;
+ public const int maxT = 88;
const bool T = true;
const bool x = false;
const int minErrDist = 2;
- static Token/*!*/ token; // last recognized token
- static Token/*!*/ t; // lookahead token
- static int errDist = minErrDist;
+ public Scanner/*!*/ scanner;
+ public Errors/*!*/ errors;
+
+ public Token/*!*/ t; // last recognized token
+ public Token/*!*/ la; // lookahead token
+ int errDist = minErrDist;
- static Program! Pgm = new Program();
+static Program! Pgm = new Program();
static Expr! dummyExpr = new LiteralExpr(Token.NoToken, false);
static Cmd! dummyCmd = new AssumeCmd(Token.NoToken, dummyExpr);
@@ -37,22 +54,24 @@ static StructuredCmd! dummyStructuredCmd = new BreakCmd(Token.NoToken, null);
///the parsed program.
///</summary>
public static int Parse (string! filename, out /*maybe null*/ Program program) /* throws System.IO.IOException */ {
- using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) {
- Buffer.Fill(reader);
- Scanner.Init(filename);
- return Parse(out program);
- }
-}
-///<summary>
-///Returns the number of parsing errors encountered. If 0, "program" returns as
-///the parsed program.
-///Note: first initialize the Scanner.
-///</summary>
-public static int Parse (out /*maybe null*/ Program program) {
+
+ FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
+// Scanner scanner = new Scanner(stream);
+
+ string s = ParserHelper.Fill(stream,new List<string!>());
+ byte[]! buffer = (!) UTF8Encoding.Default.GetBytes(s);
+ MemoryStream ms = new MemoryStream(buffer,false);
+ Errors errors = new Errors();
+ Scanner scanner = new Scanner(ms, errors, filename);
+
+/*
+ Scanner scanner = new Scanner(filename);
+*/
+ Parser parser = new Parser(scanner, errors);
Pgm = new Program(); // reset the global variable
- Parse();
- if (Errors.count == 0)
+ parser.Parse();
+ if (parser.errors.count == 0)
{
program = Pgm;
return 0;
@@ -60,22 +79,50 @@ public static int Parse (out /*maybe null*/ Program program) {
else
{
program = null;
- return Errors.count;
+ return parser.errors.count;
}
+/*
+ using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) {
+ Buffer.Fill(reader);
+ Scanner.Init(filename);
+ return Parse(out program);
+ }
+*/
}
-
+///<summary>
+///Returns the number of parsing errors encountered. If 0, "program" returns as
+///the parsed program.
+///Note: first initialize the Scanner.
+///</summary>
+//public static int Parse (out /*maybe null*/ Program program) {
+// Pgm = new Program(); // reset the global variable
+// Parse();
+// if (Errors.count == 0)
+// {
+// program = Pgm;
+// return 0;
+// }
+// else
+// {
+// program = null;
+// return Errors.count;
+// }
+//}
+
+/*
public static int ParseProposition (string! text, out Expr! expression)
{
Buffer.Fill(text);
Scanner.Init(string.Format("\"{0}\"", text));
Errors.SynErr = new ErrorProc(SynErr);
- t = new Token();
+ la = new Token();
Get();
Proposition(out expression);
return Errors.count;
}
+*/
// Class to represent the bounds of a bitvector expression t[a:b].
// Objects of this class only exist during parsing and are directly
@@ -103,61 +150,72 @@ private class BvBounds : Expr {
/*--------------------------------------------------------------------------*/
- static void Error(int n) {
- if (errDist >= minErrDist) Errors.SynErr(n, t.filename, t.line, t.col);
- errDist = 0;
+ public Parser(Scanner/*!*/ scanner, Errors/*!*/ errors) {
+ this.scanner = scanner;
+ this.errors = errors;
+ Token! tok = new Token();
+ tok.val = "";
+ this.la = tok;
+ this.t = new Token(); // just to satisfy its non-null constraint
}
-
- public static void SemErr(string! msg) {
- if (errDist >= minErrDist) Errors.SemErr(token.filename, token.line, token.col, msg);
+
+ void SynErr (int n) {
+ if (errDist >= minErrDist) errors.SynErr(la.filename, la.line, la.col, n);
errDist = 0;
}
- public static void SemErr(IToken! tok, string! msg) {
- Errors.SemErr(tok.filename, tok.line, tok.col, msg);
+ public void SemErr (string! msg) {
+ if (errDist >= minErrDist) errors.SemErr(t, msg);
+ errDist = 0;
+ }
+
+ public void SemErr(IToken! tok, string! msg) {
+ errors.SemErr(tok, msg);
}
- static void Get() {
+ void Get () {
for (;;) {
- token = t;
- t = Scanner.Scan();
- if (t.kind<=maxT) {errDist++; return;}
+ t = la;
+ la = scanner.Scan();
+ if (la.kind <= maxT) { ++errDist; break; }
- t = token;
+ la = t;
}
}
- static void Expect(int n) {
- if (t.kind==n) Get(); else Error(n);
+ void Expect (int n) {
+ if (la.kind==n) Get(); else { SynErr(n); }
}
- static bool StartOf(int s) {
- return set[s, t.kind];
+ bool StartOf (int s) {
+ return set[s, la.kind];
}
- static void ExpectWeak(int n, int follow) {
- if (t.kind == n) Get();
+ void ExpectWeak (int n, int follow) {
+ if (la.kind == n) Get();
else {
- Error(n);
+ SynErr(n);
while (!StartOf(follow)) Get();
}
}
-
- static bool WeakSeparator(int n, int syFol, int repFol) {
- bool[] s = new bool[maxT+1];
- if (t.kind == n) {Get(); return true;}
- else if (StartOf(repFol)) return false;
+
+
+ bool WeakSeparator(int n, int syFol, int repFol) {
+ int kind = la.kind;
+ if (kind == n) {Get(); return true;}
+ else if (StartOf(repFol)) {return false;}
else {
- for (int i=0; i <= maxT; i++) {
- s[i] = set[syFol, i] || set[repFol, i] || set[0, i];
+ SynErr(n);
+ while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) {
+ Get();
+ kind = la.kind;
}
- Error(n);
- while (!s[t.kind]) Get();
return StartOf(syFol);
}
}
+
- static void BoogiePL() {
+ void BoogiePL() {
VariableSeq! vs;
DeclarationSeq! ds;
Axiom! ax;
@@ -167,7 +225,7 @@ private class BvBounds : Expr {
Implementation! nnim;
while (StartOf(1)) {
- switch (t.kind) {
+ switch (la.kind) {
case 19: {
Consts(out vs);
foreach (Bpl.Variable! v in vs) { Pgm.TopLevelDeclarations.Add(v); }
@@ -214,46 +272,48 @@ private class BvBounds : Expr {
Expect(0);
}
- static void Consts(out VariableSeq! ds) {
+ void Consts(out VariableSeq! ds) {
IToken! y; TypedIdentSeq! xs;
ds = new VariableSeq();
bool u = false; QKeyValue kv = null;
bool ChildrenComplete = false;
List<ConstantParent!> Parents = null;
Expect(19);
- y = token;
- while (t.kind == 25) {
+ y = t;
+ while (la.kind == 25) {
Attribute(ref kv);
}
- if (t.kind == 20) {
+ if (la.kind == 20) {
Get();
u = true;
}
IdsType(out xs);
- if (t.kind == 21) {
+ if (la.kind == 21) {
OrderSpec(out ChildrenComplete, out Parents);
}
bool makeClone = false;
foreach(TypedIdent! x in xs) {
- // ensure that no sharing is introduced
- List<ConstantParent!> ParentsClone;
- if (makeClone && Parents != null) {
- ParentsClone = new List<ConstantParent!> ();
- foreach (ConstantParent! p in Parents)
- ParentsClone.Add(new ConstantParent (
- new IdentifierExpr (p.Parent.tok, p.Parent.Name),
- p.Unique));
- } else {
- ParentsClone = Parents;
- }
- makeClone = true;
- ds.Add(new Constant(y, x, u, ParentsClone, ChildrenComplete, kv));
- }
+ // ensure that no sharing is introduced
+ List<ConstantParent!> ParentsClone;
+ if (makeClone && Parents != null) {
+ ParentsClone = new List<ConstantParent!> ();
+ foreach (ConstantParent! p in Parents)
+ ParentsClone.Add(new ConstantParent (
+ new IdentifierExpr (p.Parent.tok, p.Parent.Name),
+ p.Unique));
+ } else {
+ ParentsClone = Parents;
+ }
+ makeClone = true;
+
+ ds.Add(new Constant(y, x, u, ParentsClone, ChildrenComplete, kv));
+ }
+
Expect(7);
}
- static void Function(out DeclarationSeq! ds) {
+ void Function(out DeclarationSeq! ds) {
ds = new DeclarationSeq(); IToken! z;
IToken! typeParamTok;
TypeVariableSeq! typeParams = new TypeVariableSeq();
@@ -266,46 +326,46 @@ private class BvBounds : Expr {
Expr! tmp;
Expect(23);
- while (t.kind == 25) {
+ while (la.kind == 25) {
Attribute(ref kv);
}
Ident(out z);
- if (t.kind == 17) {
+ if (la.kind == 17) {
TypeParams(out typeParamTok, out typeParams);
}
Expect(8);
if (StartOf(2)) {
VarOrType(out tyd);
arguments.Add(new Formal(tyd.tok, tyd, true));
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
VarOrType(out tyd);
arguments.Add(new Formal(tyd.tok, tyd, true));
}
}
Expect(9);
- if (t.kind == 24) {
+ if (la.kind == 24) {
Get();
Expect(8);
VarOrType(out tyd);
Expect(9);
retTyd = tyd;
- } else if (t.kind == 10) {
+ } else if (la.kind == 10) {
Get();
Type(out retTy);
retTyd = new TypedIdent(retTy.tok, "", retTy);
- } else Error(89);
- if (t.kind == 25) {
+ } else SynErr(89);
+ if (la.kind == 25) {
Get();
Expression(out tmp);
definition = tmp;
Expect(26);
- } else if (t.kind == 7) {
+ } else if (la.kind == 7) {
Get();
- } else Error(90);
+ } else SynErr(90);
if (retTyd == null) {
// construct a dummy type for the case of syntax error
- tyd = new TypedIdent(token, "", new BasicType(token, SimpleType.Int));
+ tyd = new TypedIdent(t, "", new BasicType(t, SimpleType.Int));
} else {
tyd = retTyd;
}
@@ -325,7 +385,7 @@ private class BvBounds : Expr {
TypedIdent! curr = ((!)arguments[i]).TypedIdent;
if (curr.Name == "") {
if (prevType == null) {
- SemErr(curr.tok, "the type of the last parameter is unspecified");
+ this.errors.SemErr(curr.tok, "the type of the last parameter is unspecified");
break;
}
Type ty = curr.Type;
@@ -334,7 +394,7 @@ private class BvBounds : Expr {
curr.Name = ((!)(ty as UnresolvedTypeIdentifier)).Name;
curr.Type = prevType;
} else {
- SemErr(curr.tok, "expecting an identifier as parameter name");
+ this.errors.SemErr(curr.tok, "expecting an identifier as parameter name");
}
} else {
prevType = curr.Type;
@@ -359,44 +419,44 @@ private class BvBounds : Expr {
foreach (TypeVariable! t in typeParams)
quantifiedTypeVars.Add(new TypeVariable (Token.NoToken, t.Name));
- Expr call = new NAryExpr(z, new FunctionCall(new IdentifierExpr(z, z.val)), callArgs);
- // specify the type of the function, because it might be that
- // type parameters only occur in the output type
- call = Expr.CoerceType(z, call, (Type)tyd.Type.Clone());
- Expr def = Expr.Eq(call, definition);
- if (quantifiedTypeVars.Length != 0 || dummies.Length != 0) {
- def = new ForallExpr(z, quantifiedTypeVars, dummies,
- kv,
- new Trigger(z, true, new ExprSeq(call), null),
- def);
- }
- ds.Add(new Axiom(z, def, "autogenerated definition axiom", null));
- }
- }
-
- }
-
- static void Axiom(out Axiom! m) {
+ Expr call = new NAryExpr(z, new FunctionCall(new IdentifierExpr(z, z.val)), callArgs);
+ // specify the type of the function, because it might be that
+ // type parameters only occur in the output type
+ call = Expr.CoerceType(z, call, (Type)tyd.Type.Clone());
+ Expr def = Expr.Eq(call, definition);
+ if (quantifiedTypeVars.Length != 0 || dummies.Length != 0) {
+ def = new ForallExpr(z, quantifiedTypeVars, dummies,
+ kv,
+ new Trigger(z, true, new ExprSeq(call), null),
+ def);
+ }
+ ds.Add(new Axiom(z, def, "autogenerated definition axiom", null));
+ }
+ }
+
+ }
+
+ void Axiom(out Axiom! m) {
Expr! e; QKeyValue kv = null;
Expect(27);
- while (t.kind == 25) {
+ while (la.kind == 25) {
Attribute(ref kv);
}
- IToken! x = token;
+ IToken! x = t;
Proposition(out e);
Expect(7);
m = new Axiom(x,e, null, kv);
}
- static void UserDefinedTypes(out List<Declaration!>! ts) {
+ void UserDefinedTypes(out List<Declaration!>! ts) {
Declaration! decl; QKeyValue kv = null; ts = new List<Declaration!> ();
Expect(28);
- while (t.kind == 25) {
+ while (la.kind == 25) {
Attribute(ref kv);
}
UserDefinedType(out decl, kv);
ts.Add(decl);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
UserDefinedType(out decl, kv);
ts.Add(decl);
@@ -404,10 +464,10 @@ private class BvBounds : Expr {
Expect(7);
}
- static void GlobalVars(out VariableSeq! ds) {
+ void GlobalVars(out VariableSeq! ds) {
TypedIdentSeq! tyds = new TypedIdentSeq(); ds = new VariableSeq(); QKeyValue kv = null;
Expect(6);
- while (t.kind == 25) {
+ while (la.kind == 25) {
Attribute(ref kv);
}
IdsTypeWheres(true, tyds);
@@ -418,21 +478,22 @@ private class BvBounds : Expr {
}
- static void Procedure(out Procedure! proc, out /*maybe null*/ Implementation impl) {
+ void Procedure(out Procedure! proc, out /*maybe null*/ Implementation impl) {
IToken! x;
TypeVariableSeq! typeParams;
VariableSeq! ins, outs;
RequiresSeq! pre = new RequiresSeq();
IdentifierExprSeq! mods = new IdentifierExprSeq();
EnsuresSeq! post = new EnsuresSeq();
- VariableSeq! locals = new VariableSeq();
- StmtList! stmtList;
- QKeyValue kv = null;
- impl = null;
+ VariableSeq! locals = new VariableSeq();
+ StmtList! stmtList;
+ QKeyValue kv = null;
+ impl = null;
+
Expect(30);
ProcSignature(true, out x, out typeParams, out ins, out outs, out kv);
- if (t.kind == 7) {
+ if (la.kind == 7) {
Get();
while (StartOf(3)) {
Spec(pre, mods, post);
@@ -442,15 +503,14 @@ private class BvBounds : Expr {
Spec(pre, mods, post);
}
ImplBody(out locals, out stmtList);
- // here we attach kv only to the Procedure, not its implementation
impl = new Implementation(x, x.val, typeParams,
- Formal.StripWhereClauses(ins), Formal.StripWhereClauses(outs), locals, stmtList, null);
+ Formal.StripWhereClauses(ins), Formal.StripWhereClauses(outs), locals, stmtList, null, this.errors);
- } else Error(91);
+ } else SynErr(91);
proc = new Procedure(x, x.val, typeParams, ins, outs, pre, mods, post, kv);
}
- static void Implementation(out Implementation! impl) {
+ void Implementation(out Implementation! impl) {
IToken! x;
TypeVariableSeq! typeParams;
VariableSeq! ins, outs;
@@ -461,27 +521,27 @@ private class BvBounds : Expr {
Expect(31);
ProcSignature(false, out x, out typeParams, out ins, out outs, out kv);
ImplBody(out locals, out stmtList);
- impl = new Implementation(x, x.val, typeParams, ins, outs, locals, stmtList, kv);
+ impl = new Implementation(x, x.val, typeParams, ins, outs, locals, stmtList, kv, this.errors);
}
- static void Attribute(ref QKeyValue kv) {
+ void Attribute(ref QKeyValue kv) {
Trigger trig = null;
AttributeOrTrigger(ref kv, ref trig);
- if (trig != null) SemErr("only attributes, not triggers, allowed here");
+ if (trig != null) this.SemErr("only attributes, not triggers, allowed here");
}
- static void IdsTypeWheres(bool allowWhereClauses, TypedIdentSeq! tyds) {
+ void IdsTypeWheres(bool allowWhereClauses, TypedIdentSeq! tyds) {
IdsTypeWhere(allowWhereClauses, tyds);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
IdsTypeWhere(allowWhereClauses, tyds);
}
}
- static void LocalVars(VariableSeq! ds) {
+ void LocalVars(VariableSeq! ds) {
TypedIdentSeq! tyds = new TypedIdentSeq(); QKeyValue kv = null;
Expect(6);
- while (t.kind == 25) {
+ while (la.kind == 25) {
Attribute(ref kv);
}
IdsTypeWheres(true, tyds);
@@ -492,10 +552,10 @@ private class BvBounds : Expr {
}
- static void ProcFormals(bool incoming, bool allowWhereClauses, out VariableSeq! ds) {
+ void ProcFormals(bool incoming, bool allowWhereClauses, out VariableSeq! ds) {
TypedIdentSeq! tyds = new TypedIdentSeq(); ds = new VariableSeq();
Expect(8);
- if (t.kind == 1) {
+ if (la.kind == 1) {
IdsTypeWheres(allowWhereClauses, tyds);
}
Expect(9);
@@ -505,7 +565,7 @@ private class BvBounds : Expr {
}
- static void BoundVars(IToken! x, out VariableSeq! ds) {
+ void BoundVars(IToken! x, out VariableSeq! ds) {
TypedIdentSeq! tyds = new TypedIdentSeq(); ds = new VariableSeq();
IdsTypeWheres(false, tyds);
foreach (TypedIdent! tyd in tyds) {
@@ -514,7 +574,7 @@ private class BvBounds : Expr {
}
- static void IdsType(out TypedIdentSeq! tyds) {
+ void IdsType(out TypedIdentSeq! tyds) {
TokenSeq! ids; Bpl.Type! ty;
Idents(out ids);
Expect(10);
@@ -526,45 +586,45 @@ private class BvBounds : Expr {
}
- static void Idents(out TokenSeq! xs) {
+ void Idents(out TokenSeq! xs) {
IToken! id; xs = new TokenSeq();
Ident(out id);
xs.Add(id);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
Ident(out id);
xs.Add(id);
}
}
- static void Type(out Bpl.Type! ty) {
+ void Type(out Bpl.Type! ty) {
IToken! tok; ty = dummyType;
- if (t.kind == 8 || t.kind == 13 || t.kind == 14) {
+ if (la.kind == 8 || la.kind == 13 || la.kind == 14) {
TypeAtom(out ty);
- } else if (t.kind == 1) {
+ } else if (la.kind == 1) {
Ident(out tok);
TypeSeq! args = new TypeSeq ();
if (StartOf(2)) {
TypeArgs(args);
}
ty = new UnresolvedTypeIdentifier (tok, tok.val, args);
- } else if (t.kind == 15 || t.kind == 17) {
+ } else if (la.kind == 15 || la.kind == 17) {
MapType(out ty);
- } else Error(92);
+ } else SynErr(92);
}
- static void IdsTypeWhere(bool allowWhereClauses, TypedIdentSeq! tyds) {
+ void IdsTypeWhere(bool allowWhereClauses, TypedIdentSeq! tyds) {
TokenSeq! ids; Bpl.Type! ty; Expr wh = null; Expr! nne;
Idents(out ids);
Expect(10);
Type(out ty);
- if (t.kind == 12) {
+ if (la.kind == 12) {
Get();
Expression(out nne);
if (allowWhereClauses) {
wh = nne;
} else {
- SemErr("where clause not allowed here");
+ this.SemErr("where clause not allowed here");
}
}
@@ -574,74 +634,74 @@ private class BvBounds : Expr {
}
- static void Expression(out Expr! e0) {
+ void Expression(out Expr! e0) {
IToken! x; Expr! e1;
ImpliesExpression(false, out e0);
- while (t.kind == 52 || t.kind == 53) {
+ while (la.kind == 52 || la.kind == 53) {
EquivOp();
- x = token;
+ x = t;
ImpliesExpression(false, out e1);
e0 = Expr.Binary(x, BinaryOperator.Opcode.Iff, e0, e1);
}
}
- static void TypeAtom(out Bpl.Type! ty) {
+ void TypeAtom(out Bpl.Type! ty) {
ty = dummyType;
- if (t.kind == 13) {
+ if (la.kind == 13) {
Get();
- ty = new BasicType(token, SimpleType.Int);
- } else if (t.kind == 14) {
+ ty = new BasicType(t, SimpleType.Int);
+ } else if (la.kind == 14) {
Get();
- ty = new BasicType(token, SimpleType.Bool);
- } else if (t.kind == 8) {
+ ty = new BasicType(t, SimpleType.Bool);
+ } else if (la.kind == 8) {
Get();
Type(out ty);
Expect(9);
- } else Error(93);
+ } else SynErr(93);
}
- static void Ident(out IToken! x) {
+ void Ident(out IToken! x) {
Expect(1);
- x = token;
+ x = t;
if (x.val.StartsWith("\\"))
x.val = x.val.Substring(1);
}
- static void TypeArgs(TypeSeq! ts) {
+ void TypeArgs(TypeSeq! ts) {
IToken! tok; Type! ty;
- if (t.kind == 8 || t.kind == 13 || t.kind == 14) {
+ if (la.kind == 8 || la.kind == 13 || la.kind == 14) {
TypeAtom(out ty);
ts.Add(ty);
if (StartOf(2)) {
TypeArgs(ts);
}
- } else if (t.kind == 1) {
+ } else if (la.kind == 1) {
Ident(out tok);
TypeSeq! args = new TypeSeq ();
ts.Add(new UnresolvedTypeIdentifier (tok, tok.val, args));
if (StartOf(2)) {
TypeArgs(ts);
}
- } else if (t.kind == 15 || t.kind == 17) {
+ } else if (la.kind == 15 || la.kind == 17) {
MapType(out ty);
ts.Add(ty);
- } else Error(94);
+ } else SynErr(94);
}
- static void MapType(out Bpl.Type! ty) {
+ void MapType(out Bpl.Type! ty) {
IToken tok = null;
IToken! nnTok;
TypeSeq! arguments = new TypeSeq();
Type! result;
TypeVariableSeq! typeParameters = new TypeVariableSeq();
- if (t.kind == 17) {
+ if (la.kind == 17) {
TypeParams(out nnTok, out typeParameters);
tok = nnTok;
}
Expect(15);
- if (tok == null) tok = token;
+ if (tok == null) tok = t;
if (StartOf(2)) {
Types(arguments);
}
@@ -651,10 +711,10 @@ private class BvBounds : Expr {
}
- static void TypeParams(out IToken! tok, out Bpl.TypeVariableSeq! typeParams) {
+ void TypeParams(out IToken! tok, out Bpl.TypeVariableSeq! typeParams) {
TokenSeq! typeParamToks;
Expect(17);
- tok = token;
+ tok = t;
Idents(out typeParamToks);
Expect(18);
typeParams = new TypeVariableSeq ();
@@ -663,18 +723,18 @@ private class BvBounds : Expr {
}
- static void Types(TypeSeq! ts) {
+ void Types(TypeSeq! ts) {
Bpl.Type! ty;
Type(out ty);
ts.Add(ty);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
Type(out ty);
ts.Add(ty);
}
}
- static void OrderSpec(out bool ChildrenComplete, out List<ConstantParent!> Parents) {
+ void OrderSpec(out bool ChildrenComplete, out List<ConstantParent!> Parents) {
ChildrenComplete = false;
Parents = null;
bool u;
@@ -682,18 +742,18 @@ private class BvBounds : Expr {
Expect(21);
Parents = new List<ConstantParent!> ();
u = false;
- if (t.kind == 1 || t.kind == 20) {
- if (t.kind == 20) {
+ if (la.kind == 1 || la.kind == 20) {
+ if (la.kind == 20) {
Get();
u = true;
}
Ident(out parent);
Parents.Add(new ConstantParent (
new IdentifierExpr(parent, parent.val), u));
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
u = false;
- if (t.kind == 20) {
+ if (la.kind == 20) {
Get();
u = true;
}
@@ -702,23 +762,23 @@ private class BvBounds : Expr {
new IdentifierExpr(parent, parent.val), u));
}
}
- if (t.kind == 22) {
+ if (la.kind == 22) {
Get();
ChildrenComplete = true;
}
}
- static void VarOrType(out TypedIdent! tyd) {
+ void VarOrType(out TypedIdent! tyd) {
string! varName = ""; Bpl.Type! ty; IToken! tok;
Type(out ty);
tok = ty.tok;
- if (t.kind == 10) {
+ if (la.kind == 10) {
Get();
if (ty is UnresolvedTypeIdentifier &&
((!)(ty as UnresolvedTypeIdentifier)).Arguments.Length == 0) {
varName = ((!)(ty as UnresolvedTypeIdentifier)).Name;
} else {
- SemErr("expected identifier before ':'");
+ this.SemErr("expected identifier before ':'");
}
Type(out ty);
@@ -726,18 +786,18 @@ private class BvBounds : Expr {
tyd = new TypedIdent(tok, varName, ty);
}
- static void Proposition(out Expr! e) {
+ void Proposition(out Expr! e) {
Expression(out e);
}
- static void UserDefinedType(out Declaration! decl, QKeyValue kv) {
+ void UserDefinedType(out Declaration! decl, QKeyValue kv) {
IToken! id; IToken! id2; TokenSeq! paramTokens = new TokenSeq ();
Type! body = dummyType; bool synonym = false;
Ident(out id);
- if (t.kind == 1) {
+ if (la.kind == 1) {
WhiteSpaceIdents(out paramTokens);
}
- if (t.kind == 29) {
+ if (la.kind == 29) {
Get();
Type(out body);
synonym = true;
@@ -753,39 +813,39 @@ private class BvBounds : Expr {
}
- static void WhiteSpaceIdents(out TokenSeq! xs) {
+ void WhiteSpaceIdents(out TokenSeq! xs) {
IToken! id; xs = new TokenSeq();
Ident(out id);
xs.Add(id);
- while (t.kind == 1) {
+ while (la.kind == 1) {
Ident(out id);
xs.Add(id);
}
}
- static void ProcSignature(bool allowWhereClausesOnFormals, out IToken! name, out TypeVariableSeq! typeParams,
+ void ProcSignature(bool allowWhereClausesOnFormals, out IToken! name, out TypeVariableSeq! typeParams,
out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
IToken! typeParamTok; typeParams = new TypeVariableSeq();
outs = new VariableSeq(); kv = null;
- while (t.kind == 25) {
+ while (la.kind == 25) {
Attribute(ref kv);
}
Ident(out name);
- if (t.kind == 17) {
+ if (la.kind == 17) {
TypeParams(out typeParamTok, out typeParams);
}
ProcFormals(true, allowWhereClausesOnFormals, out ins);
- if (t.kind == 24) {
+ if (la.kind == 24) {
Get();
ProcFormals(false, allowWhereClausesOnFormals, out outs);
}
}
- static void Spec(RequiresSeq! pre, IdentifierExprSeq! mods, EnsuresSeq! post) {
+ void Spec(RequiresSeq! pre, IdentifierExprSeq! mods, EnsuresSeq! post) {
TokenSeq! ms;
- if (t.kind == 32) {
+ if (la.kind == 32) {
Get();
- if (t.kind == 1) {
+ if (la.kind == 1) {
Idents(out ms);
foreach (IToken! m in ms) {
mods.Add(new IdentifierExpr(m, m.val));
@@ -793,74 +853,74 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
}
Expect(7);
- } else if (t.kind == 33) {
+ } else if (la.kind == 33) {
Get();
SpecPrePost(true, pre, post);
- } else if (t.kind == 34 || t.kind == 35) {
+ } else if (la.kind == 34 || la.kind == 35) {
SpecPrePost(false, pre, post);
- } else Error(95);
+ } else SynErr(95);
}
- static void ImplBody(out VariableSeq! locals, out StmtList! stmtList) {
+ void ImplBody(out VariableSeq! locals, out StmtList! stmtList) {
locals = new VariableSeq();
Expect(25);
- while (t.kind == 6) {
+ while (la.kind == 6) {
LocalVars(locals);
}
StmtList(out stmtList);
}
- static void SpecPrePost(bool free, RequiresSeq! pre, EnsuresSeq! post) {
+ void SpecPrePost(bool free, RequiresSeq! pre, EnsuresSeq! post) {
Expr! e; VariableSeq! locals; BlockSeq! blocks; Token tok = null; QKeyValue kv = null;
- if (t.kind == 34) {
+ if (la.kind == 34) {
Get();
- tok = token;
- while (t.kind == 25) {
+ tok = t;
+ while (la.kind == 25) {
Attribute(ref kv);
}
if (StartOf(5)) {
Proposition(out e);
Expect(7);
pre.Add(new Requires(tok, free, e, null, kv));
- } else if (t.kind == 36) {
+ } else if (la.kind == 36) {
SpecBody(out locals, out blocks);
Expect(7);
pre.Add(new Requires(tok, free, new BlockExpr(locals, blocks), null, kv));
- } else Error(96);
- } else if (t.kind == 35) {
+ } else SynErr(96);
+ } else if (la.kind == 35) {
Get();
- tok = token;
- while (t.kind == 25) {
+ tok = t;
+ while (la.kind == 25) {
Attribute(ref kv);
}
if (StartOf(5)) {
Proposition(out e);
Expect(7);
post.Add(new Ensures(tok, free, e, null, kv));
- } else if (t.kind == 36) {
+ } else if (la.kind == 36) {
SpecBody(out locals, out blocks);
Expect(7);
post.Add(new Ensures(tok, free, new BlockExpr(locals, blocks), null, kv));
- } else Error(97);
- } else Error(98);
+ } else SynErr(97);
+ } else SynErr(98);
}
- static void SpecBody(out VariableSeq! locals, out BlockSeq! blocks) {
+ void SpecBody(out VariableSeq! locals, out BlockSeq! blocks) {
locals = new VariableSeq(); Block! b;
Expect(36);
- while (t.kind == 6) {
+ while (la.kind == 6) {
LocalVars(locals);
}
SpecBlock(out b);
blocks = new BlockSeq(b);
- while (t.kind == 1) {
+ while (la.kind == 1) {
SpecBlock(out b);
blocks.Add(b);
}
Expect(37);
}
- static void SpecBlock(out Block! b) {
+ void SpecBlock(out Block! b) {
IToken! x; IToken! y;
Cmd c; IToken label;
CmdSeq cs = new CmdSeq();
@@ -878,26 +938,26 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
cs.Add(c);
} else {
assert label != null;
- SemErr("SpecBlock's can only have one label");
+ this.SemErr("SpecBlock's can only have one label");
}
}
- if (t.kind == 38) {
+ if (la.kind == 38) {
Get();
- y = token;
+ y = t;
Idents(out xs);
foreach (IToken! s in xs) { ss.Add(s.val); }
b = new Block(x,x.val,cs,new GotoCmd(y,ss));
- } else if (t.kind == 39) {
+ } else if (la.kind == 39) {
Get();
Expression(out e);
- b = new Block(x,x.val,cs,new ReturnExprCmd(token,e));
- } else Error(99);
+ b = new Block(x,x.val,cs,new ReturnExprCmd(t,e));
+ } else SynErr(99);
Expect(7);
}
- static void LabelOrCmd(out Cmd c, out IToken label) {
+ void LabelOrCmd(out Cmd c, out IToken label) {
IToken! x; Expr! e;
TokenSeq! xs;
IdentifierExprSeq ids;
@@ -905,26 +965,26 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
Cmd! cn;
QKeyValue kv = null;
- if (t.kind == 1) {
+ if (la.kind == 1) {
LabelOrAssign(out c, out label);
- } else if (t.kind == 46) {
+ } else if (la.kind == 46) {
Get();
- x = token;
- while (t.kind == 25) {
+ x = t;
+ while (la.kind == 25) {
Attribute(ref kv);
}
Proposition(out e);
c = new AssertCmd(x,e, kv);
Expect(7);
- } else if (t.kind == 47) {
+ } else if (la.kind == 47) {
Get();
- x = token;
+ x = t;
Proposition(out e);
c = new AssumeCmd(x,e);
Expect(7);
- } else if (t.kind == 48) {
+ } else if (la.kind == 48) {
Get();
- x = token;
+ x = t;
Idents(out xs);
Expect(7);
ids = new IdentifierExprSeq();
@@ -933,14 +993,14 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
}
c = new HavocCmd(x,ids);
- } else if (t.kind == 50) {
+ } else if (la.kind == 50) {
CallCmd(out cn);
Expect(7);
c = cn;
- } else Error(100);
+ } else SynErr(100);
}
- static void StmtList(out StmtList! stmtList) {
+ void StmtList(out StmtList! stmtList) {
List<BigBlock!> bigblocks = new List<BigBlock!>();
/* built-up state for the current BigBlock: */
IToken startToken = null; string currentLabel = null;
@@ -974,7 +1034,7 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
cs = new CmdSeq();
}
- } else if (t.kind == 40 || t.kind == 42 || t.kind == 45) {
+ } else if (la.kind == 40 || la.kind == 42 || la.kind == 45) {
StructuredCmd(out ecn);
ec = ecn;
if (startToken == null) { startToken = ec.tok; cs = new CmdSeq(); }
@@ -995,55 +1055,56 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
}
}
Expect(26);
- IToken! endCurly = token;
+ IToken! endCurly = t;
if (startToken == null && bigblocks.Count == 0) {
- startToken = token; cs = new CmdSeq();
+ startToken = t; cs = new CmdSeq();
}
if (startToken != null) {
assert cs != null;
b = new BigBlock(startToken, currentLabel, cs, null, null);
bigblocks.Add(b);
}
- stmtList = new StmtList(bigblocks, endCurly);
+ stmtList = new StmtList(bigblocks, endCurly);
+
}
- static void StructuredCmd(out StructuredCmd! ec) {
+ void StructuredCmd(out StructuredCmd! ec) {
ec = dummyStructuredCmd; assume ec.IsPeerConsistent;
IfCmd! ifcmd; WhileCmd! wcmd; BreakCmd! bcmd;
- if (t.kind == 40) {
+ if (la.kind == 40) {
IfCmd(out ifcmd);
ec = ifcmd;
- } else if (t.kind == 42) {
+ } else if (la.kind == 42) {
WhileCmd(out wcmd);
ec = wcmd;
- } else if (t.kind == 45) {
+ } else if (la.kind == 45) {
BreakCmd(out bcmd);
ec = bcmd;
- } else Error(101);
+ } else SynErr(101);
}
- static void TransferCmd(out TransferCmd! tc) {
+ void TransferCmd(out TransferCmd! tc) {
tc = dummyTransferCmd;
Token y; TokenSeq! xs;
StringSeq ss = new StringSeq();
- if (t.kind == 38) {
+ if (la.kind == 38) {
Get();
- y = token;
+ y = t;
Idents(out xs);
foreach (IToken! s in xs) { ss.Add(s.val); }
tc = new GotoCmd(y, ss);
- } else if (t.kind == 39) {
+ } else if (la.kind == 39) {
Get();
- tc = new ReturnCmd(token);
- } else Error(102);
+ tc = new ReturnCmd(t);
+ } else SynErr(102);
Expect(7);
}
- static void IfCmd(out IfCmd! ifcmd) {
+ void IfCmd(out IfCmd! ifcmd) {
IToken! x;
Expr guard;
StmtList! thn;
@@ -1051,37 +1112,37 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
StmtList! els; StmtList elseOption = null;
Expect(40);
- x = token;
+ x = t;
Guard(out guard);
Expect(25);
StmtList(out thn);
- if (t.kind == 41) {
+ if (la.kind == 41) {
Get();
- if (t.kind == 40) {
+ if (la.kind == 40) {
IfCmd(out elseIf);
elseIfOption = elseIf;
- } else if (t.kind == 25) {
+ } else if (la.kind == 25) {
Get();
StmtList(out els);
elseOption = els;
- } else Error(103);
+ } else SynErr(103);
}
ifcmd = new IfCmd(x, guard, thn, elseIfOption, elseOption);
}
- static void WhileCmd(out WhileCmd! wcmd) {
+ void WhileCmd(out WhileCmd! wcmd) {
IToken! x; Token z;
Expr guard; Expr! e; bool isFree;
List<PredicateCmd!> invariants = new List<PredicateCmd!>();
StmtList! body;
Expect(42);
- x = token;
+ x = t;
Guard(out guard);
assume guard == null || Owner.None(guard);
- while (t.kind == 33 || t.kind == 43) {
- isFree = false; z = t/*lookahead token*/;
- if (t.kind == 33) {
+ while (la.kind == 33 || la.kind == 43) {
+ isFree = false; z = la/*lookahead token*/;
+ if (la.kind == 33) {
Get();
isFree = true;
}
@@ -1100,13 +1161,13 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
wcmd = new WhileCmd(x, guard, invariants, body);
}
- static void BreakCmd(out BreakCmd! bcmd) {
+ void BreakCmd(out BreakCmd! bcmd) {
IToken! x; IToken! y;
string breakLabel = null;
Expect(45);
- x = token;
- if (t.kind == 1) {
+ x = t;
+ if (la.kind == 1) {
Ident(out y);
breakLabel = y.val;
}
@@ -1114,20 +1175,20 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
bcmd = new BreakCmd(x, breakLabel);
}
- static void Guard(out Expr e) {
+ void Guard(out Expr e) {
Expr! ee; e = null;
Expect(8);
- if (t.kind == 44) {
+ if (la.kind == 44) {
Get();
e = null;
} else if (StartOf(5)) {
Expression(out ee);
e = ee;
- } else Error(104);
+ } else SynErr(104);
Expect(9);
}
- static void LabelOrAssign(out Cmd c, out IToken label) {
+ void LabelOrAssign(out Cmd c, out IToken label) {
IToken! id; IToken! x; Expr! e, e0;
c = dummyCmd; label = null;
AssignLhs! lhs;
@@ -1135,36 +1196,36 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
List<Expr!>! rhss;
Ident(out id);
- x = token;
- if (t.kind == 10) {
+ x = t;
+ if (la.kind == 10) {
Get();
c = null; label = x;
- } else if (t.kind == 11 || t.kind == 15 || t.kind == 49) {
+ } else if (la.kind == 11 || la.kind == 15 || la.kind == 49) {
MapAssignIndexes(id, out lhs);
lhss = new List<AssignLhs!> ();
lhss.Add(lhs);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
Ident(out id);
MapAssignIndexes(id, out lhs);
lhss.Add(lhs);
}
Expect(49);
- x = token; /* use location of := */
+ x = t; /* use location of := */
Expression(out e0);
rhss = new List<Expr!> ();
rhss.Add(e0);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
Expression(out e0);
rhss.Add(e0);
}
Expect(7);
c = new AssignCmd(x, lhss, rhss);
- } else Error(105);
+ } else SynErr(105);
}
- static void CallCmd(out Cmd! c) {
+ void CallCmd(out Cmd! c) {
IToken! x; IToken! first; IToken p;
List<IdentifierExpr>! ids = new List<IdentifierExpr>();
List<Expr>! es = new List<Expr>();
@@ -1173,18 +1234,18 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
c = dummyCmd;
Expect(50);
- x = token;
- while (t.kind == 25) {
+ x = t;
+ while (la.kind == 25) {
Attribute(ref kv);
}
- if (t.kind == 1) {
+ if (la.kind == 1) {
Ident(out first);
- if (t.kind == 8) {
+ if (la.kind == 8) {
Get();
if (StartOf(8)) {
CallForallArg(out en);
es.Add(en);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
CallForallArg(out en);
es.Add(en);
@@ -1192,9 +1253,9 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
}
Expect(9);
c = new CallCmd(x, first.val, es, ids, kv);
- } else if (t.kind == 11 || t.kind == 49) {
+ } else if (la.kind == 11 || la.kind == 49) {
ids.Add(new IdentifierExpr(first, first.val));
- if (t.kind == 11) {
+ if (la.kind == 11) {
Get();
CallOutIdent(out p);
if (p==null) {
@@ -1203,7 +1264,7 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
ids.Add(new IdentifierExpr(p, p.val));
}
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
CallOutIdent(out p);
if (p==null) {
@@ -1220,7 +1281,7 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
if (StartOf(8)) {
CallForallArg(out en);
es.Add(en);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
CallForallArg(out en);
es.Add(en);
@@ -1228,8 +1289,8 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
}
Expect(9);
c = new CallCmd(x, first.val, es, ids, kv);
- } else Error(106);
- } else if (t.kind == 51) {
+ } else SynErr(106);
+ } else if (la.kind == 51) {
Get();
Ident(out first);
Expect(8);
@@ -1237,7 +1298,7 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
if (StartOf(8)) {
CallForallArg(out en);
args.Add(en);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
CallForallArg(out en);
args.Add(en);
@@ -1245,10 +1306,10 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
}
Expect(9);
c = new CallForallCmd(x, first.val, args, kv);
- } else if (t.kind == 44) {
+ } else if (la.kind == 44) {
Get();
ids.Add(null);
- if (t.kind == 11) {
+ if (la.kind == 11) {
Get();
CallOutIdent(out p);
if (p==null) {
@@ -1257,7 +1318,7 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
ids.Add(new IdentifierExpr(p, p.val));
}
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
CallOutIdent(out p);
if (p==null) {
@@ -1274,7 +1335,7 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
if (StartOf(8)) {
CallForallArg(out en);
es.Add(en);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
CallForallArg(out en);
es.Add(en);
@@ -1282,10 +1343,10 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
}
Expect(9);
c = new CallCmd(x, first.val, es, ids, kv);
- } else Error(107);
+ } else SynErr(107);
}
- static void MapAssignIndexes(IToken! assignedVariable, out AssignLhs! lhs) {
+ void MapAssignIndexes(IToken! assignedVariable, out AssignLhs! lhs) {
IToken! x;
AssignLhs! runningLhs =
new SimpleAssignLhs(assignedVariable,
@@ -1293,14 +1354,14 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
List<Expr!>! indexes;
Expr! e0;
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
- x = token;
+ x = t;
indexes = new List<Expr!> ();
if (StartOf(5)) {
Expression(out e0);
indexes.Add(e0);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
Expression(out e0);
indexes.Add(e0);
@@ -1313,60 +1374,60 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
lhs = runningLhs;
}
- static void CallForallArg(out Expr exprOptional) {
+ void CallForallArg(out Expr exprOptional) {
exprOptional = null;
Expr! e;
- if (t.kind == 44) {
+ if (la.kind == 44) {
Get();
} else if (StartOf(5)) {
Expression(out e);
exprOptional = e;
- } else Error(108);
+ } else SynErr(108);
}
- static void CallOutIdent(out IToken id) {
+ void CallOutIdent(out IToken id) {
id = null;
IToken! p;
- if (t.kind == 44) {
+ if (la.kind == 44) {
Get();
- } else if (t.kind == 1) {
+ } else if (la.kind == 1) {
Ident(out p);
id = p;
- } else Error(109);
+ } else SynErr(109);
}
- static void Expressions(out ExprSeq! es) {
+ void Expressions(out ExprSeq! es) {
Expr! e; es = new ExprSeq();
Expression(out e);
es.Add(e);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
Expression(out e);
es.Add(e);
}
}
- static void ImpliesExpression(bool noExplies, out Expr! e0) {
+ void ImpliesExpression(bool noExplies, out Expr! e0) {
IToken! x; Expr! e1;
LogicalExpression(out e0);
if (StartOf(9)) {
- if (t.kind == 54 || t.kind == 55) {
+ if (la.kind == 54 || la.kind == 55) {
ImpliesOp();
- x = token;
+ x = t;
ImpliesExpression(true, out e1);
e0 = Expr.Binary(x, BinaryOperator.Opcode.Imp, e0, e1);
} else {
ExpliesOp();
if (noExplies)
- SemErr("illegal mixture of ==> and <==, use parentheses to disambiguate");
- x = token;
+ this.SemErr("illegal mixture of ==> and <==, use parentheses to disambiguate");
+ x = t;
LogicalExpression(out e1);
e0 = Expr.Binary(x, BinaryOperator.Opcode.Imp, e1, e0);
- while (t.kind == 56 || t.kind == 57) {
+ while (la.kind == 56 || la.kind == 57) {
ExpliesOp();
- x = token;
+ x = t;
LogicalExpression(out e1);
e0 = Expr.Binary(x, BinaryOperator.Opcode.Imp, e1, e0);
}
@@ -1374,37 +1435,37 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
}
}
- static void EquivOp() {
- if (t.kind == 52) {
+ void EquivOp() {
+ if (la.kind == 52) {
Get();
- } else if (t.kind == 53) {
+ } else if (la.kind == 53) {
Get();
- } else Error(110);
+ } else SynErr(110);
}
- static void LogicalExpression(out Expr! e0) {
+ void LogicalExpression(out Expr! e0) {
IToken! x; Expr! e1; BinaryOperator.Opcode op;
RelationalExpression(out e0);
if (StartOf(10)) {
- if (t.kind == 58 || t.kind == 59) {
+ if (la.kind == 58 || la.kind == 59) {
AndOp();
- x = token;
+ x = t;
RelationalExpression(out e1);
e0 = Expr.Binary(x, BinaryOperator.Opcode.And, e0, e1);
- while (t.kind == 58 || t.kind == 59) {
+ while (la.kind == 58 || la.kind == 59) {
AndOp();
- x = token;
+ x = t;
RelationalExpression(out e1);
e0 = Expr.Binary(x, BinaryOperator.Opcode.And, e0, e1);
}
} else {
OrOp();
- x = token;
+ x = t;
RelationalExpression(out e1);
e0 = Expr.Binary(x, BinaryOperator.Opcode.Or, e0, e1);
- while (t.kind == 60 || t.kind == 61) {
+ while (la.kind == 60 || la.kind == 61) {
OrOp();
- x = token;
+ x = t;
RelationalExpression(out e1);
e0 = Expr.Binary(x, BinaryOperator.Opcode.Or, e0, e1);
}
@@ -1412,23 +1473,23 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
}
}
- static void ImpliesOp() {
- if (t.kind == 54) {
+ void ImpliesOp() {
+ if (la.kind == 54) {
Get();
- } else if (t.kind == 55) {
+ } else if (la.kind == 55) {
Get();
- } else Error(111);
+ } else SynErr(111);
}
- static void ExpliesOp() {
- if (t.kind == 56) {
+ void ExpliesOp() {
+ if (la.kind == 56) {
Get();
- } else if (t.kind == 57) {
+ } else if (la.kind == 57) {
Get();
- } else Error(112);
+ } else SynErr(112);
}
- static void RelationalExpression(out Expr! e0) {
+ void RelationalExpression(out Expr! e0) {
IToken! x; Expr! e1; BinaryOperator.Opcode op;
BvTerm(out e0);
if (StartOf(11)) {
@@ -1438,197 +1499,197 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
}
}
- static void AndOp() {
- if (t.kind == 58) {
+ void AndOp() {
+ if (la.kind == 58) {
Get();
- } else if (t.kind == 59) {
+ } else if (la.kind == 59) {
Get();
- } else Error(113);
+ } else SynErr(113);
}
- static void OrOp() {
- if (t.kind == 60) {
+ void OrOp() {
+ if (la.kind == 60) {
Get();
- } else if (t.kind == 61) {
+ } else if (la.kind == 61) {
Get();
- } else Error(114);
+ } else SynErr(114);
}
- static void BvTerm(out Expr! e0) {
+ void BvTerm(out Expr! e0) {
IToken! x; Expr! e1;
Term(out e0);
- while (t.kind == 70) {
+ while (la.kind == 70) {
Get();
- x = token;
+ x = t;
Term(out e1);
e0 = new BvConcatExpr(x, e0, e1);
}
}
- static void RelOp(out IToken! x, out BinaryOperator.Opcode op) {
+ void RelOp(out IToken! x, out BinaryOperator.Opcode op) {
x = Token.NoToken; op=BinaryOperator.Opcode.Add/*(dummy)*/;
- switch (t.kind) {
+ switch (la.kind) {
case 62: {
Get();
- x = token; op=BinaryOperator.Opcode.Eq;
+ x = t; op=BinaryOperator.Opcode.Eq;
break;
}
case 17: {
Get();
- x = token; op=BinaryOperator.Opcode.Lt;
+ x = t; op=BinaryOperator.Opcode.Lt;
break;
}
case 18: {
Get();
- x = token; op=BinaryOperator.Opcode.Gt;
+ x = t; op=BinaryOperator.Opcode.Gt;
break;
}
case 63: {
Get();
- x = token; op=BinaryOperator.Opcode.Le;
+ x = t; op=BinaryOperator.Opcode.Le;
break;
}
case 64: {
Get();
- x = token; op=BinaryOperator.Opcode.Ge;
+ x = t; op=BinaryOperator.Opcode.Ge;
break;
}
case 65: {
Get();
- x = token; op=BinaryOperator.Opcode.Neq;
+ x = t; op=BinaryOperator.Opcode.Neq;
break;
}
case 66: {
Get();
- x = token; op=BinaryOperator.Opcode.Subtype;
+ x = t; op=BinaryOperator.Opcode.Subtype;
break;
}
case 67: {
Get();
- x = token; op=BinaryOperator.Opcode.Neq;
+ x = t; op=BinaryOperator.Opcode.Neq;
break;
}
case 68: {
Get();
- x = token; op=BinaryOperator.Opcode.Le;
+ x = t; op=BinaryOperator.Opcode.Le;
break;
}
case 69: {
Get();
- x = token; op=BinaryOperator.Opcode.Ge;
+ x = t; op=BinaryOperator.Opcode.Ge;
break;
}
- default: Error(115); break;
+ default: SynErr(115); break;
}
}
- static void Term(out Expr! e0) {
+ void Term(out Expr! e0) {
IToken! x; Expr! e1; BinaryOperator.Opcode op;
Factor(out e0);
- while (t.kind == 71 || t.kind == 72) {
+ while (la.kind == 71 || la.kind == 72) {
AddOp(out x, out op);
Factor(out e1);
e0 = Expr.Binary(x, op, e0, e1);
}
}
- static void Factor(out Expr! e0) {
+ void Factor(out Expr! e0) {
IToken! x; Expr! e1; BinaryOperator.Opcode op;
UnaryExpression(out e0);
- while (t.kind == 44 || t.kind == 73 || t.kind == 74) {
+ while (la.kind == 44 || la.kind == 73 || la.kind == 74) {
MulOp(out x, out op);
UnaryExpression(out e1);
e0 = Expr.Binary(x, op, e0, e1);
}
}
- static void AddOp(out IToken! x, out BinaryOperator.Opcode op) {
+ void AddOp(out IToken! x, out BinaryOperator.Opcode op) {
x = Token.NoToken; op=BinaryOperator.Opcode.Add/*(dummy)*/;
- if (t.kind == 71) {
+ if (la.kind == 71) {
Get();
- x = token; op=BinaryOperator.Opcode.Add;
- } else if (t.kind == 72) {
+ x = t; op=BinaryOperator.Opcode.Add;
+ } else if (la.kind == 72) {
Get();
- x = token; op=BinaryOperator.Opcode.Sub;
- } else Error(116);
+ x = t; op=BinaryOperator.Opcode.Sub;
+ } else SynErr(116);
}
- static void UnaryExpression(out Expr! e) {
+ void UnaryExpression(out Expr! e) {
IToken! x;
e = dummyExpr;
- if (t.kind == 72) {
+ if (la.kind == 72) {
Get();
- x = token;
+ x = t;
UnaryExpression(out e);
e = Expr.Binary(x, BinaryOperator.Opcode.Sub, new LiteralExpr(x, BigNum.ZERO), e);
- } else if (t.kind == 75 || t.kind == 76) {
+ } else if (la.kind == 75 || la.kind == 76) {
NegOp();
- x = token;
+ x = t;
UnaryExpression(out e);
e = Expr.Unary(x, UnaryOperator.Opcode.Not, e);
} else if (StartOf(12)) {
CoercionExpression(out e);
- } else Error(117);
+ } else SynErr(117);
}
- static void MulOp(out IToken! x, out BinaryOperator.Opcode op) {
+ void MulOp(out IToken! x, out BinaryOperator.Opcode op) {
x = Token.NoToken; op=BinaryOperator.Opcode.Add/*(dummy)*/;
- if (t.kind == 44) {
+ if (la.kind == 44) {
Get();
- x = token; op=BinaryOperator.Opcode.Mul;
- } else if (t.kind == 73) {
+ x = t; op=BinaryOperator.Opcode.Mul;
+ } else if (la.kind == 73) {
Get();
- x = token; op=BinaryOperator.Opcode.Div;
- } else if (t.kind == 74) {
+ x = t; op=BinaryOperator.Opcode.Div;
+ } else if (la.kind == 74) {
Get();
- x = token; op=BinaryOperator.Opcode.Mod;
- } else Error(118);
+ x = t; op=BinaryOperator.Opcode.Mod;
+ } else SynErr(118);
}
- static void NegOp() {
- if (t.kind == 75) {
+ void NegOp() {
+ if (la.kind == 75) {
Get();
- } else if (t.kind == 76) {
+ } else if (la.kind == 76) {
Get();
- } else Error(119);
+ } else SynErr(119);
}
- static void CoercionExpression(out Expr! e) {
+ void CoercionExpression(out Expr! e) {
IToken! x;
Type! coercedTo;
BigNum bn;
ArrayExpression(out e);
- while (t.kind == 10) {
+ while (la.kind == 10) {
Get();
- x = token;
+ x = t;
if (StartOf(2)) {
Type(out coercedTo);
e = Expr.CoerceType(x, e, coercedTo);
- } else if (t.kind == 3) {
+ } else if (la.kind == 3) {
Nat(out bn);
if (!(e is LiteralExpr) || !((LiteralExpr)e).isBigNum) {
- SemErr("arguments of extract need to be integer literals");
+ this.SemErr("arguments of extract need to be integer literals");
e = new BvBounds(x, bn, BigNum.ZERO);
} else {
e = new BvBounds(x, bn, ((LiteralExpr)e).asBigNum);
}
- } else Error(120);
+ } else SynErr(120);
}
}
- static void ArrayExpression(out Expr! e) {
+ void ArrayExpression(out Expr! e) {
IToken! x;
Expr! index0 = dummyExpr; Expr! e1;
bool store; bool bvExtract;
ExprSeq! allArgs = dummyExprSeq;
AtomExpression(out e);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
- x = token; allArgs = new ExprSeq ();
+ x = t; allArgs = new ExprSeq ();
allArgs.Add(e);
store = false; bvExtract = false;
if (StartOf(13)) {
@@ -1639,19 +1700,19 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
else
allArgs.Add(index0);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
Expression(out e1);
if (bvExtract || e1 is BvBounds)
- SemErr("bitvectors only have one dimension");
+ this.SemErr("bitvectors only have one dimension");
allArgs.Add(e1);
}
- if (t.kind == 49) {
+ if (la.kind == 49) {
Get();
Expression(out e1);
if (bvExtract || e1 is BvBounds)
- SemErr("assignment to bitvectors is not possible");
+ this.SemErr("assignment to bitvectors is not possible");
allArgs.Add(e1); store = true;
}
@@ -1674,18 +1735,18 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
}
}
- static void Nat(out BigNum n) {
+ void Nat(out BigNum n) {
Expect(3);
try {
- n = BigNum.FromString(token.val);
+ n = BigNum.FromString(t.val);
} catch (FormatException) {
- SemErr("incorrectly formatted number");
+ this.SemErr("incorrectly formatted number");
n = BigNum.ZERO;
}
}
- static void AtomExpression(out Expr! e) {
+ void AtomExpression(out Expr! e) {
IToken! x; int n; BigNum bn;
ExprSeq! es; VariableSeq! ds; Trigger trig;
TypeVariableSeq! typeParams;
@@ -1694,45 +1755,45 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
QKeyValue kv;
e = dummyExpr;
- switch (t.kind) {
+ switch (la.kind) {
case 77: {
Get();
- e = new LiteralExpr(token, false);
+ e = new LiteralExpr(t, false);
break;
}
case 78: {
Get();
- e = new LiteralExpr(token, true);
+ e = new LiteralExpr(t, true);
break;
}
case 3: {
Nat(out bn);
- e = new LiteralExpr(token, bn);
+ e = new LiteralExpr(t, bn);
break;
}
case 2: {
BvLit(out bn, out n);
- e = new LiteralExpr(token, bn, n);
+ e = new LiteralExpr(t, bn, n);
break;
}
case 1: {
Ident(out x);
id = new IdentifierExpr(x, x.val); e = id;
- if (t.kind == 8) {
+ if (la.kind == 8) {
Get();
if (StartOf(5)) {
Expressions(out es);
e = new NAryExpr(x, new FunctionCall(id), es);
- } else if (t.kind == 9) {
+ } else if (la.kind == 9) {
e = new NAryExpr(x, new FunctionCall(id), new ExprSeq());
- } else Error(121);
+ } else SynErr(121);
Expect(9);
}
break;
}
case 79: {
Get();
- x = token;
+ x = t;
Expect(8);
Expression(out e);
Expect(9);
@@ -1744,29 +1805,29 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
if (StartOf(5)) {
Expression(out e);
if (e is BvBounds)
- SemErr("parentheses around bitvector bounds " +
+ this.SemErr("parentheses around bitvector bounds " +
"are not allowed");
- } else if (t.kind == 51 || t.kind == 81) {
+ } else if (la.kind == 51 || la.kind == 81) {
Forall();
- x = token;
+ x = t;
QuantifierBody(x, out typeParams, out ds, out kv, out trig, out e);
if (typeParams.Length + ds.Length > 0)
e = new ForallExpr(x, typeParams, ds, kv, trig, e);
- } else if (t.kind == 82 || t.kind == 83) {
+ } else if (la.kind == 82 || la.kind == 83) {
Exists();
- x = token;
+ x = t;
QuantifierBody(x, out typeParams, out ds, out kv, out trig, out e);
if (typeParams.Length + ds.Length > 0)
e = new ExistsExpr(x, typeParams, ds, kv, trig, e);
- } else if (t.kind == 84 || t.kind == 85) {
+ } else if (la.kind == 84 || la.kind == 85) {
Lambda();
- x = token;
+ x = t;
QuantifierBody(x, out typeParams, out ds, out kv, out trig, out e);
if (trig != null)
SemErr("triggers not allowed in lambda expressions");
if (typeParams.Length + ds.Length > 0)
e = new LambdaExpr(x, typeParams, ds, kv, e);
- } else Error(122);
+ } else SynErr(122);
Expect(9);
break;
}
@@ -1774,78 +1835,78 @@ out VariableSeq! ins, out VariableSeq! outs, out QKeyValue kv) {
IfThenElseExpression(out e);
break;
}
- default: Error(123); break;
+ default: SynErr(123); break;
}
}
- static void BvLit(out BigNum n, out int m) {
+ void BvLit(out BigNum n, out int m) {
Expect(2);
- int pos = token.val.IndexOf("bv");
- string a = token.val.Substring(0, pos);
- string b = token.val.Substring(pos + 2);
+ int pos = t.val.IndexOf("bv");
+ string a = t.val.Substring(0, pos);
+ string b = t.val.Substring(pos + 2);
try {
n = BigNum.FromString(a);
m = Convert.ToInt32(b);
} catch (FormatException) {
- SemErr("incorrectly formatted bitvector");
+ this.SemErr("incorrectly formatted bitvector");
n = BigNum.ZERO;
m = 0;
}
}
- static void Forall() {
- if (t.kind == 51) {
+ void Forall() {
+ if (la.kind == 51) {
Get();
- } else if (t.kind == 81) {
+ } else if (la.kind == 81) {
Get();
- } else Error(124);
+ } else SynErr(124);
}
- static void QuantifierBody(IToken! q, out TypeVariableSeq! typeParams, out VariableSeq! ds,
+ void QuantifierBody(IToken! q, out TypeVariableSeq! typeParams, out VariableSeq! ds,
out QKeyValue kv, out Trigger trig, out Expr! body) {
trig = null; typeParams = new TypeVariableSeq ();
IToken! tok; Expr! e; ExprSeq! es;
kv = null; string key; string value;
ds = new VariableSeq ();
- if (t.kind == 17) {
+ if (la.kind == 17) {
TypeParams(out tok, out typeParams);
- if (t.kind == 1) {
+ if (la.kind == 1) {
BoundVars(q, out ds);
}
- } else if (t.kind == 1) {
+ } else if (la.kind == 1) {
BoundVars(q, out ds);
- } else Error(125);
+ } else SynErr(125);
QSep();
- while (t.kind == 25) {
+ while (la.kind == 25) {
AttributeOrTrigger(ref kv, ref trig);
}
Expression(out body);
}
- static void Exists() {
- if (t.kind == 82) {
+ void Exists() {
+ if (la.kind == 82) {
Get();
- } else if (t.kind == 83) {
+ } else if (la.kind == 83) {
Get();
- } else Error(126);
+ } else SynErr(126);
}
- static void Lambda() {
- if (t.kind == 84) {
+ void Lambda() {
+ if (la.kind == 84) {
Get();
- } else if (t.kind == 85) {
+ } else if (la.kind == 85) {
Get();
- } else Error(127);
+ } else SynErr(127);
}
- static void IfThenElseExpression(out Expr! e) {
+ void IfThenElseExpression(out Expr! e) {
IToken! tok;
Expr! e0, e1, e2;
e = dummyExpr;
Expect(40);
- tok = token;
+ tok = t;
Expression(out e0);
Expect(80);
Expression(out e1);
@@ -1854,21 +1915,21 @@ out QKeyValue kv, out Trigger trig, out Expr! body) {
e = new NAryExpr(tok, new IfThenElse(tok), new ExprSeq(e0, e1, e2));
}
- static void AttributeOrTrigger(ref QKeyValue kv, ref Trigger trig) {
+ void AttributeOrTrigger(ref QKeyValue kv, ref Trigger trig) {
IToken! tok; Expr! e; ExprSeq! es;
string key; string value;
List<object!> parameters; object! param;
Expect(25);
- tok = token;
- if (t.kind == 10) {
+ tok = t;
+ if (la.kind == 10) {
Get();
Expect(1);
- key = token.val; parameters = new List<object!>();
+ key = t.val; parameters = new List<object!>();
if (StartOf(14)) {
AttributeParameter(out param);
parameters.Add(param);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
AttributeParameter(out param);
parameters.Add(param);
@@ -1883,7 +1944,7 @@ out QKeyValue kv, out Trigger trig, out Expr! body) {
trig.AddLast(new Trigger(tok, false, new ExprSeq(e), null));
}
} else {
- SemErr("the 'nopats' quantifier attribute expects a string-literal parameter");
+ this.SemErr("the 'nopats' quantifier attribute expects a string-literal parameter");
}
} else {
if (kv==null) {
@@ -1896,7 +1957,7 @@ out QKeyValue kv, out Trigger trig, out Expr! body) {
} else if (StartOf(5)) {
Expression(out e);
es = new ExprSeq(e);
- while (t.kind == 11) {
+ while (la.kind == 11) {
Get();
Expression(out e);
es.Add(e);
@@ -1907,46 +1968,73 @@ out QKeyValue kv, out Trigger trig, out Expr! body) {
trig.AddLast(new Trigger(tok, true, es, null));
}
- } else Error(128);
+ } else SynErr(128);
Expect(26);
}
- static void AttributeParameter(out object! o) {
+ void AttributeParameter(out object! o) {
o = "error";
Expr! e;
- if (t.kind == 4) {
+ if (la.kind == 4) {
Get();
- o = token.val.Substring(1, token.val.Length-2);
+ o = t.val.Substring(1, t.val.Length-2);
} else if (StartOf(5)) {
Expression(out e);
o = e;
- } else Error(129);
+ } else SynErr(129);
}
- static void QSep() {
- if (t.kind == 86) {
+ void QSep() {
+ if (la.kind == 86) {
Get();
- } else if (t.kind == 87) {
+ } else if (la.kind == 87) {
Get();
- } else Error(130);
+ } else SynErr(130);
}
- public static void Parse() {
- Errors.SynErr = new ErrorProc(SynErr);
- t = new Token();
+ public void Parse() {
+ la = new Token();
+ la.val = "";
Get();
BoogiePL();
+ Expect(0);
}
+
+ static readonly bool[,]! set = {
+ {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, x,x,x,T, T,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,T,x,x, x,x,x,x, T,x,x,x, x,T,T,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,T,T,T, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x},
+ {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,T,x, x,T,T,T, T,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,T,T,T, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,T,T,T, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x,x,x,x, x,x},
+ {x,T,T,T, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x},
+ {x,T,T,T, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x}
- [Microsoft.Contracts.Verify(false)]
- static void SynErr(int n, string filename, int line, int col) {
- Errors.count++;
- Console.Write("{0}({1},{2}): syntax error: ", filename, line, col);
+ };
+} // end Parser
+
+
+public class Errors {
+ public int count = 0; // number of errors detected
+ public System.IO.TextWriter! errorStream = Console.Out; // error messages go to this stream
+// public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
+ public string! errMsgFormat4 = "{0}({1},{2}): Error: {3}"; // 0=line, 1=column, 2=text
+ public string! errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
+
+ public void SynErr (string filename, int line, int col, int n) {
string s;
+ Console.Write("{0}({1},{2}): syntax error: ", filename, line, col);
switch (n) {
case 0: s = "EOF expected"; break;
case 1: s = "ident expected"; break;
@@ -1954,88 +2042,88 @@ out QKeyValue kv, out Trigger trig, out Expr! body) {
case 3: s = "digits expected"; break;
case 4: s = "string expected"; break;
case 5: s = "float expected"; break;
- case 6: s = "var expected"; break;
- case 7: s = "; expected"; break;
- case 8: s = "( expected"; break;
- case 9: s = ") expected"; break;
- case 10: s = ": expected"; break;
- case 11: s = ", expected"; break;
- case 12: s = "where expected"; break;
- case 13: s = "int expected"; break;
- case 14: s = "bool expected"; break;
- case 15: s = "[ expected"; break;
- case 16: s = "] expected"; break;
- case 17: s = "< expected"; break;
- case 18: s = "> expected"; break;
- case 19: s = "const expected"; break;
- case 20: s = "unique expected"; break;
- case 21: s = "extends expected"; break;
- case 22: s = "complete expected"; break;
- case 23: s = "function expected"; break;
- case 24: s = "returns expected"; break;
- case 25: s = "{ expected"; break;
- case 26: s = "} expected"; break;
- case 27: s = "axiom expected"; break;
- case 28: s = "type expected"; break;
- case 29: s = "= expected"; break;
- case 30: s = "procedure expected"; break;
- case 31: s = "implementation expected"; break;
- case 32: s = "modifies expected"; break;
- case 33: s = "free expected"; break;
- case 34: s = "requires expected"; break;
- case 35: s = "ensures expected"; break;
- case 36: s = "{{ expected"; break;
- case 37: s = "}} expected"; break;
- case 38: s = "goto expected"; break;
- case 39: s = "return expected"; break;
- case 40: s = "if expected"; break;
- case 41: s = "else expected"; break;
- case 42: s = "while expected"; break;
- case 43: s = "invariant expected"; break;
- case 44: s = "* expected"; break;
- case 45: s = "break expected"; break;
- case 46: s = "assert expected"; break;
- case 47: s = "assume expected"; break;
- case 48: s = "havoc expected"; break;
- case 49: s = ":= expected"; break;
- case 50: s = "call expected"; break;
- case 51: s = "forall expected"; break;
- case 52: s = "<==> expected"; break;
- case 53: s = "\\u21d4 expected"; break;
- case 54: s = "==> expected"; break;
- case 55: s = "\\u21d2 expected"; break;
- case 56: s = "<== expected"; break;
- case 57: s = "\\u21d0 expected"; break;
- case 58: s = "&& expected"; break;
- case 59: s = "\\u2227 expected"; break;
- case 60: s = "|| expected"; break;
- case 61: s = "\\u2228 expected"; break;
- case 62: s = "== expected"; break;
- case 63: s = "<= expected"; break;
- case 64: s = ">= expected"; break;
- case 65: s = "!= expected"; break;
- case 66: s = "<: expected"; break;
- case 67: s = "\\u2260 expected"; break;
- case 68: s = "\\u2264 expected"; break;
- case 69: s = "\\u2265 expected"; break;
- case 70: s = "++ expected"; break;
- case 71: s = "+ expected"; break;
- case 72: s = "- expected"; break;
- case 73: s = "/ expected"; break;
- case 74: s = "% expected"; break;
- case 75: s = "! expected"; break;
- case 76: s = "\\u00ac expected"; break;
- case 77: s = "false expected"; break;
- case 78: s = "true expected"; break;
- case 79: s = "old expected"; break;
- case 80: s = "then expected"; break;
- case 81: s = "\\u2200 expected"; break;
- case 82: s = "exists expected"; break;
- case 83: s = "\\u2203 expected"; break;
- case 84: s = "lambda expected"; break;
- case 85: s = "\\u03bb expected"; break;
- case 86: s = ":: expected"; break;
- case 87: s = "\\u2022 expected"; break;
+ case 6: s = "\"var\" expected"; break;
+ case 7: s = "\";\" expected"; break;
+ case 8: s = "\"(\" expected"; break;
+ case 9: s = "\")\" expected"; break;
+ case 10: s = "\":\" expected"; break;
+ case 11: s = "\",\" expected"; break;
+ case 12: s = "\"where\" expected"; break;
+ case 13: s = "\"int\" expected"; break;
+ case 14: s = "\"bool\" expected"; break;
+ case 15: s = "\"[\" expected"; break;
+ case 16: s = "\"]\" expected"; break;
+ case 17: s = "\"<\" expected"; break;
+ case 18: s = "\">\" expected"; break;
+ case 19: s = "\"const\" expected"; break;
+ case 20: s = "\"unique\" expected"; break;
+ case 21: s = "\"extends\" expected"; break;
+ case 22: s = "\"complete\" expected"; break;
+ case 23: s = "\"function\" expected"; break;
+ case 24: s = "\"returns\" expected"; break;
+ case 25: s = "\"{\" expected"; break;
+ case 26: s = "\"}\" expected"; break;
+ case 27: s = "\"axiom\" expected"; break;
+ case 28: s = "\"type\" expected"; break;
+ case 29: s = "\"=\" expected"; break;
+ case 30: s = "\"procedure\" expected"; break;
+ case 31: s = "\"implementation\" expected"; break;
+ case 32: s = "\"modifies\" expected"; break;
+ case 33: s = "\"free\" expected"; break;
+ case 34: s = "\"requires\" expected"; break;
+ case 35: s = "\"ensures\" expected"; break;
+ case 36: s = "\"{{\" expected"; break;
+ case 37: s = "\"}}\" expected"; break;
+ case 38: s = "\"goto\" expected"; break;
+ case 39: s = "\"return\" expected"; break;
+ case 40: s = "\"if\" expected"; break;
+ case 41: s = "\"else\" expected"; break;
+ case 42: s = "\"while\" expected"; break;
+ case 43: s = "\"invariant\" expected"; break;
+ case 44: s = "\"*\" expected"; break;
+ case 45: s = "\"break\" expected"; break;
+ case 46: s = "\"assert\" expected"; break;
+ case 47: s = "\"assume\" expected"; break;
+ case 48: s = "\"havoc\" expected"; break;
+ case 49: s = "\":=\" expected"; break;
+ case 50: s = "\"call\" expected"; break;
+ case 51: s = "\"forall\" expected"; break;
+ case 52: s = "\"<==>\" expected"; break;
+ case 53: s = "\"\\u21d4\" expected"; break;
+ case 54: s = "\"==>\" expected"; break;
+ case 55: s = "\"\\u21d2\" expected"; break;
+ case 56: s = "\"<==\" expected"; break;
+ case 57: s = "\"\\u21d0\" expected"; break;
+ case 58: s = "\"&&\" expected"; break;
+ case 59: s = "\"\\u2227\" expected"; break;
+ case 60: s = "\"||\" expected"; break;
+ case 61: s = "\"\\u2228\" expected"; break;
+ case 62: s = "\"==\" expected"; break;
+ case 63: s = "\"<=\" expected"; break;
+ case 64: s = "\">=\" expected"; break;
+ case 65: s = "\"!=\" expected"; break;
+ case 66: s = "\"<:\" expected"; break;
+ case 67: s = "\"\\u2260\" expected"; break;
+ case 68: s = "\"\\u2264\" expected"; break;
+ case 69: s = "\"\\u2265\" expected"; break;
+ case 70: s = "\"++\" expected"; break;
+ case 71: s = "\"+\" expected"; break;
+ case 72: s = "\"-\" expected"; break;
+ case 73: s = "\"/\" expected"; break;
+ case 74: s = "\"%\" expected"; break;
+ case 75: s = "\"!\" expected"; break;
+ case 76: s = "\"\\u00ac\" expected"; break;
+ case 77: s = "\"false\" expected"; break;
+ case 78: s = "\"true\" expected"; break;
+ case 79: s = "\"old\" expected"; break;
+ case 80: s = "\"then\" expected"; break;
+ case 81: s = "\"\\u2200\" expected"; break;
+ case 82: s = "\"exists\" expected"; break;
+ case 83: s = "\"\\u2203\" expected"; break;
+ case 84: s = "\"lambda\" expected"; break;
+ case 85: s = "\"\\u03bb\" expected"; break;
+ case 86: s = "\"::\" expected"; break;
+ case 87: s = "\"\\u2022\" expected"; break;
case 88: s = "??? expected"; break;
case 89: s = "invalid Function"; break;
case 90: s = "invalid Function"; break;
@@ -2082,30 +2170,42 @@ out QKeyValue kv, out Trigger trig, out Expr! body) {
default: s = "error " + n; break;
}
- Console.WriteLine(s);
- }
-
- static bool[,]! set = {
- {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, x,x,x,T, T,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,T,x,x, x,x,x,x, T,x,x,x, x,T,T,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,T,T,T, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x},
- {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,T,x, x,T,T,T, T,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,T,T,T, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,T,T,T, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x,x,x,x, x,x},
- {x,T,T,T, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x},
- {x,T,T,T, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x}
+ //errorStream.WriteLine(errMsgFormat, line, col, s);
+ errorStream.WriteLine(s);
+ count++;
+ }
- };
+ public void SemErr (int line, int col, string! s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
- [Microsoft.Contracts.Verify(false)]
- static Parser() {}
-} // end Parser
+ public void SemErr (string filename, int line, int col, string! s) {
+ errorStream.WriteLine(errMsgFormat4, filename, line, col, s);
+ count++;
+ }
+
+ public void SemErr (string s) {
+ errorStream.WriteLine(s);
+ count++;
+ }
+
+ public void SemErr(IToken! tok, string! msg) { // semantic errors
+ SemErr(tok.filename, tok.line, tok.col, msg);
+ }
+
+ public void Warning (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ }
+
+ public void Warning(string s) {
+ errorStream.WriteLine(s);
+ }
+} // Errors
+
+
+public class FatalError: Exception {
+ public FatalError(string m): base(m) {}
+}
-} // end namespace
+} \ No newline at end of file
diff --git a/Source/Core/ParserHelper.ssc b/Source/Core/ParserHelper.ssc
new file mode 100644
index 00000000..ee01880a
--- /dev/null
+++ b/Source/Core/ParserHelper.ssc
@@ -0,0 +1,116 @@
+using System.Text;
+using System.Collections.Generic;
+using System.IO;
+namespace Microsoft.Boogie {
+public static class ParserHelper {
+ struct ReadState {
+ public bool hasSeenElse;
+ public bool mayStillIncludeAnotherAlternative;
+ public ReadState(bool hasSeenElse, bool mayStillIncludeAnotherAlternative) {
+ this.hasSeenElse = hasSeenElse;
+ this.mayStillIncludeAnotherAlternative = mayStillIncludeAnotherAlternative;
+ }
+ }
+ // "arg" is assumed to be trimmed
+ private static bool IfdefConditionSaysToInclude(string! arg, List<string!>! defines) {
+ bool sense = true;
+ while (arg.StartsWith("!")) {
+ sense = !sense;
+ arg = arg.Substring(1).TrimStart();
+ }
+ return defines.Contains(arg) == sense;
+ }
+
+ public static string! Fill(FileStream! fileStream, List<string!>! defines) {
+ StreamReader! reader = new StreamReader(fileStream);
+ return Fill(reader, defines);
+ }
+ public static string! Fill(TextReader! reader, List<string!>! defines) {
+ StringBuilder sb = new StringBuilder();
+ List<ReadState>! readState = new List<ReadState>(); // readState.Count is the current nesting level of #if's
+ int ignoreCutoff = -1; // -1 means we're not ignoring; for 0<=n, n means we're ignoring because of something at nesting level n
+ while (true)
+ //invariant -1 <= ignoreCutoff && ignoreCutoff < readState.Count;
+ {
+ string s = reader.ReadLine();
+ if (s == null) {
+ if (readState.Count != 0) {
+ sb.AppendLine("#MalformedInput: missing #endif");
+ }
+ break;
+ }
+ string t = s.Trim();
+ if (t.StartsWith("#if")) {
+ ReadState rs = new ReadState(false, false);
+ if (ignoreCutoff != -1) {
+ // we're already in a state of ignoring, so continue to ignore
+ } else if (IfdefConditionSaysToInclude(t.Substring(3).TrimStart(), defines)) {
+ // include this branch
+ } else {
+ ignoreCutoff = readState.Count; // start ignoring
+ rs.mayStillIncludeAnotherAlternative = true; // allow some later "elsif" or "else" branch to be included
+ }
+ readState.Add(rs);
+ sb.AppendLine(); // ignore the #if line
+
+ } else if (t.StartsWith("#elsif")) {
+ ReadState rs;
+ if (readState.Count == 0 || (rs = readState[readState.Count-1]).hasSeenElse) {
+ sb.AppendLine("#MalformedInput: misplaced #elsif"); // malformed input
+ break;
+ }
+ if (ignoreCutoff == -1) {
+ // we had included the previous branch
+ //assert !rs.mayStillIncludeAnotherAlternative;
+ ignoreCutoff = readState.Count-1; // start ignoring
+ } else if (rs.mayStillIncludeAnotherAlternative && IfdefConditionSaysToInclude(t.Substring(6).TrimStart(), defines)) {
+ // include this branch, but no subsequent branch at this level
+ ignoreCutoff = -1;
+ rs.mayStillIncludeAnotherAlternative = false;
+ readState[readState.Count-1] = rs;
+ }
+ sb.AppendLine(); // ignore the #elsif line
+
+ } else if (t == "#else") {
+ ReadState rs;
+ if (readState.Count == 0 || (rs = readState[readState.Count-1]).hasSeenElse) {
+ sb.AppendLine("#MalformedInput: misplaced #else"); // malformed input
+ break;
+ }
+ rs.hasSeenElse = true;
+ if (ignoreCutoff == -1) {
+ // we had included the previous branch
+ //assert !rs.mayStillIncludeAnotherAlternative;
+ ignoreCutoff = readState.Count-1; // start ignoring
+ } else if (rs.mayStillIncludeAnotherAlternative) {
+ // include this branch
+ ignoreCutoff = -1;
+ rs.mayStillIncludeAnotherAlternative = false;
+ }
+ readState[readState.Count-1] = rs;
+ sb.AppendLine(); // ignore the #else line
+
+ } else if (t == "#endif") {
+ if (readState.Count == 0) {
+ sb.AppendLine("#MalformedInput: misplaced #endif"); // malformed input
+ break;
+ }
+ readState.RemoveAt(readState.Count-1); // pop
+ if (ignoreCutoff == readState.Count) {
+ // we had ignored the branch that ends here; so, now we start including again
+ ignoreCutoff = -1;
+ }
+ sb.AppendLine(); // ignore the #endif line
+
+ } else if (ignoreCutoff == -1) {
+ sb.AppendLine(s); // included line
+
+ } else {
+ sb.AppendLine(); // ignore the line
+ }
+ }
+
+ return sb.ToString();
+ }
+}
+} \ No newline at end of file
diff --git a/Source/Core/Scanner.ssc b/Source/Core/Scanner.ssc
index a6f2c0a4..3765574e 100644
--- a/Source/Core/Scanner.ssc
+++ b/Source/Core/Scanner.ssc
@@ -1,3 +1,4 @@
+
using System;
using System.IO;
using System.Collections;
@@ -5,7 +6,6 @@ using System.Collections.Generic;
using System.Text;
using Microsoft.Contracts;
-
namespace Microsoft.Boogie {
[Immutable]
@@ -19,26 +19,30 @@ namespace Microsoft.Boogie {
bool IsValid { get; }
}
-
+
[Immutable]
public class Token : IToken {
- int _kind; // token kind
+ public int _kind; // token kind
string _filename; // token file
- int _pos; // token position in the source text (starting at 0)
- int _col; // token column (starting at 0)
- int _line; // token line (starting at 1)
- string/*!*/ _val = "foo"; // token value
-
+ public int _pos; // token position in the source text (starting at 0)
+ public int _col; // token column (starting at 1)
+ public int _line; // token line (starting at 1)
+ public string/*!*/ _val; // token value
+ public Token next; // ML 2005-03-11 Tokens are kept in linked list
+
public static IToken! NoToken = new Token();
- public Token();
+ public Token() {
+ this._val = "anything so that it is nonnull";
+ }
public Token(int linenum, int colnum) {
this._line = linenum;
this._col = colnum;
+ this._val = "anything so that it is nonnull";
base();
}
- public int kind {
+ public int kind {
get { return this._kind; }
set { this._kind = value; }
}
@@ -47,7 +51,7 @@ namespace Microsoft.Boogie {
get { return this._filename; }
set { this._filename = value; }
}
-
+
public int pos{
get { return this._pos; }
set { this._pos = value; }
@@ -67,394 +71,435 @@ namespace Microsoft.Boogie {
get { return this._val; }
set { this._val = value; }
}
-
+
public bool IsValid { get { return this._filename != null; } }
- }
+
}
-namespace BoogiePL {
-
-using Microsoft.Boogie;
-
+//-----------------------------------------------------------------------------------
+// Buffer
+//-----------------------------------------------------------------------------------
public class Buffer {
- static string/*!*/ buf;
- static int bufLen;
- static int pos;
- public const int eof = '\uffff';
+ // This Buffer supports the following cases:
+ // 1) seekable stream (file)
+ // a) whole stream in buffer
+ // b) part of stream in buffer
+ // 2) non seekable stream (network, console)
- public static void Fill(TextReader! reader) {
- List<string!> defines = new List<string!>();
- Fill(reader, defines);
- }
-
- struct ReadState {
- public bool hasSeenElse;
- public bool mayStillIncludeAnotherAlternative;
- public ReadState(bool hasSeenElse, bool mayStillIncludeAnotherAlternative) {
- this.hasSeenElse = hasSeenElse;
- this.mayStillIncludeAnotherAlternative = mayStillIncludeAnotherAlternative;
- }
- }
-
- public static void Fill(TextReader! reader, List<string!>! defines) {
- StringBuilder sb = new StringBuilder();
- List<ReadState>! readState = new List<ReadState>(); // readState.Count is the current nesting level of #if's
- int ignoreCutoff = -1; // -1 means we're not ignoring; for 0<=n, n means we're ignoring because of something at nesting level n
- while (true)
- invariant -1 <= ignoreCutoff && ignoreCutoff < readState.Count;
- {
- string s = reader.ReadLine();
- if (s == null) {
- if (readState.Count != 0) {
- sb.AppendLine("#MalformedInput: missing #endif");
- }
- break;
- }
- string t = s.Trim();
- if (t.StartsWith("#if")) {
- ReadState rs = new ReadState(false, false);
- if (ignoreCutoff != -1) {
- // we're already in a state of ignoring, so continue to ignore
- } else if (IfdefConditionSaysToInclude(t.Substring(3).TrimStart(), defines)) {
- // include this branch
- } else {
- ignoreCutoff = readState.Count; // start ignoring
- rs.mayStillIncludeAnotherAlternative = true; // allow some later "elsif" or "else" branch to be included
- }
- readState.Add(rs);
- sb.AppendLine(); // ignore the #if line
-
- } else if (t.StartsWith("#elsif")) {
- ReadState rs;
- if (readState.Count == 0 || (rs = readState[readState.Count-1]).hasSeenElse) {
- sb.AppendLine("#MalformedInput: misplaced #elsif"); // malformed input
- break;
- }
- if (ignoreCutoff == -1) {
- // we had included the previous branch
- assert !rs.mayStillIncludeAnotherAlternative;
- ignoreCutoff = readState.Count-1; // start ignoring
- } else if (rs.mayStillIncludeAnotherAlternative && IfdefConditionSaysToInclude(t.Substring(6).TrimStart(), defines)) {
- // include this branch, but no subsequent branch at this level
- ignoreCutoff = -1;
- rs.mayStillIncludeAnotherAlternative = false;
- readState[readState.Count-1] = rs;
- }
- sb.AppendLine(); // ignore the #elsif line
-
- } else if (t == "#else") {
- ReadState rs;
- if (readState.Count == 0 || (rs = readState[readState.Count-1]).hasSeenElse) {
- sb.AppendLine("#MalformedInput: misplaced #else"); // malformed input
- break;
- }
- rs.hasSeenElse = true;
- if (ignoreCutoff == -1) {
- // we had included the previous branch
- assert !rs.mayStillIncludeAnotherAlternative;
- ignoreCutoff = readState.Count-1; // start ignoring
- } else if (rs.mayStillIncludeAnotherAlternative) {
- // include this branch
- ignoreCutoff = -1;
- rs.mayStillIncludeAnotherAlternative = false;
- }
- readState[readState.Count-1] = rs;
- sb.AppendLine(); // ignore the #else line
-
- } else if (t == "#endif") {
- if (readState.Count == 0) {
- sb.AppendLine("#MalformedInput: misplaced #endif"); // malformed input
- break;
- }
- readState.RemoveAt(readState.Count-1); // pop
- if (ignoreCutoff == readState.Count) {
- // we had ignored the branch that ends here; so, now we start including again
- ignoreCutoff = -1;
- }
- sb.AppendLine(); // ignore the #endif line
-
- } else if (ignoreCutoff == -1) {
- sb.AppendLine(s); // included line
-
- } else {
- sb.AppendLine(); // ignore the line
- }
- }
-
- Fill(sb.ToString());
- }
+ public const int EOF = 65535 + 1; // char.MaxValue + 1;
+ const int MIN_BUFFER_LENGTH = 1024; // 1KB
+ const int MAX_BUFFER_LENGTH = MIN_BUFFER_LENGTH * 64; // 64KB
+ byte[]! buf; // input buffer
+ int bufStart; // position of first byte in buffer relative to input stream
+ int bufLen; // length of buffer
+ int fileLen; // length of input stream (may change if the stream is no file)
+ int bufPos; // current position in buffer
+ Stream! stream; // input stream (seekable)
+ bool isUserStream; // was the stream opened by the user?
+
+ [NotDelayed]
+ public Buffer (Stream! s, bool isUserStream) {
+ stream = s; this.isUserStream = isUserStream;
+
+ int fl, bl;
+ if (s.CanSeek) {
+ fl = (int) s.Length;
+ bl = fl < MAX_BUFFER_LENGTH ? fl : MAX_BUFFER_LENGTH; // Math.Min(fileLen, MAX_BUFFER_LENGTH);
+ bufStart = Int32.MaxValue; // nothing in the buffer so far
+ } else {
+ fl = bl = bufStart = 0;
+ }
- // "arg" is assumed to be trimmed
- private static bool IfdefConditionSaysToInclude(string! arg, List<string!>! defines) {
- bool sense = true;
- while (arg.StartsWith("!")) {
- sense = !sense;
- arg = arg.Substring(1).TrimStart();
- }
- return defines.Contains(arg) == sense;
- }
-
- public static void Fill(string! text) {
- buf = text;
- bufLen = buf.Length;
- pos = 0;
- }
-
- public static int Read() {
- if (pos < bufLen) {
- return buf[pos++];
- } else {
- return eof;
- }
- }
+ buf = new byte[(bl>0) ? bl : MIN_BUFFER_LENGTH];
+ fileLen = fl; bufLen = bl;
+ base();
+ if (fileLen > 0) Pos = 0; // setup buffer to position 0 (start)
+ else bufPos = 0; // index 0 is already after the file, thus Pos = 0 is invalid
+ if (bufLen == fileLen && s.CanSeek) Close();
+ }
+
+ protected Buffer(Buffer! b) { // called in UTF8Buffer constructor
+ buf = b.buf;
+ bufStart = b.bufStart;
+ bufLen = b.bufLen;
+ fileLen = b.fileLen;
+ bufPos = b.bufPos;
+ stream = b.stream;
+ // keep destructor from closing the stream
+ //b.stream = null;
+ isUserStream = b.isUserStream;
+ // keep destructor from closing the stream
+ b.isUserStream = true;
+ }
- public static string/*!*/ ReadToEOL() {
- int x = buf.IndexOf('\n', pos);
- if (x == -1) {
- string s = buf.Substring(pos);
- pos = buf.Length;
- return s;
- } else {
- string s = buf.Substring(pos, x+1 - pos); // also include the '\n'
- pos = x+1;
- return s;
- }
- }
+ ~Buffer() { Close(); }
+
+ protected void Close() {
+ if (!isUserStream && stream != null) {
+ stream.Close();
+ //stream = null;
+ }
+ }
+
+ public virtual int Read () {
+ if (bufPos < bufLen) {
+ return buf[bufPos++];
+ } else if (Pos < fileLen) {
+ Pos = Pos; // shift buffer start to Pos
+ return buf[bufPos++];
+ } else if (stream != null && !stream.CanSeek && ReadNextStreamChunk() > 0) {
+ return buf[bufPos++];
+ } else {
+ return EOF;
+ }
+ }
- public static int Pos {
- get { return pos; }
- set {
- if (value < 0) pos = 0; else if (value >= bufLen) pos = bufLen; else pos = value;
- }
- }
-}
+ public int Peek () {
+ int curPos = Pos;
+ int ch = Read();
+ Pos = curPos;
+ return ch;
+ }
+
+ public string! GetString (int beg, int end) {
+ int len = 0;
+ char[] buf = new char[end - beg];
+ int oldPos = Pos;
+ Pos = beg;
+ while (Pos < end) buf[len++] = (char) Read();
+ Pos = oldPos;
+ return new String(buf, 0, len);
+ }
+ public int Pos {
+ get { return bufPos + bufStart; }
+ set {
+ if (value >= fileLen && stream != null && !stream.CanSeek) {
+ // Wanted position is after buffer and the stream
+ // is not seek-able e.g. network or console,
+ // thus we have to read the stream manually till
+ // the wanted position is in sight.
+ while (value >= fileLen && ReadNextStreamChunk() > 0);
+ }
+ if (value < 0 || value > fileLen) {
+ throw new FatalError("buffer out of bounds access, position: " + value);
+ }
+ if (value >= bufStart && value < bufStart + bufLen) { // already in buffer
+ bufPos = value - bufStart;
+ } else if (stream != null) { // must be swapped in
+ stream.Seek(value, SeekOrigin.Begin);
+ bufLen = stream.Read(buf, 0, buf.Length);
+ bufStart = value; bufPos = 0;
+ } else {
+ // set the position to the end of the file, Pos will return fileLen.
+ bufPos = fileLen - bufStart;
+ }
+ }
+ }
+
+ // Read the next chunk of bytes from the stream, increases the buffer
+ // if needed and updates the fields fileLen and bufLen.
+ // Returns the number of bytes read.
+ private int ReadNextStreamChunk() {
+ int free = buf.Length - bufLen;
+ if (free == 0) {
+ // in the case of a growing input stream
+ // we can neither seek in the stream, nor can we
+ // foresee the maximum length, thus we must adapt
+ // the buffer size on demand.
+ byte[] newBuf = new byte[bufLen * 2];
+ Array.Copy(buf, newBuf, bufLen);
+ buf = newBuf;
+ free = bufLen;
+ }
+ int read = stream.Read(buf, bufLen, free);
+ if (read > 0) {
+ fileLen = bufLen = (bufLen + read);
+ return read;
+ }
+ // end of stream reached
+ return 0;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// UTF8Buffer
+//-----------------------------------------------------------------------------------
+public class UTF8Buffer: Buffer {
+ public UTF8Buffer(Buffer! b): base(b) {}
+
+ public override int Read() {
+ int ch;
+ do {
+ ch = base.Read();
+ // until we find a utf8 start (0xxxxxxx or 11xxxxxx)
+ } while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EOF));
+ if (ch < 128 || ch == EOF) {
+ // nothing to do, first 127 chars are the same in ascii and utf8
+ // 0xxxxxxx or end of file character
+ } else if ((ch & 0xF0) == 0xF0) {
+ // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x07; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F; ch = base.Read();
+ int c4 = ch & 0x3F;
+ ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
+ } else if ((ch & 0xE0) == 0xE0) {
+ // 1110xxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x0F; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F;
+ ch = (((c1 << 6) | c2) << 6) | c3;
+ } else if ((ch & 0xC0) == 0xC0) {
+ // 110xxxxx 10xxxxxx
+ int c1 = ch & 0x1F; ch = base.Read();
+ int c2 = ch & 0x3F;
+ ch = (c1 << 6) | c2;
+ }
+ return ch;
+ }
+}
+
+//-----------------------------------------------------------------------------------
+// Scanner
+//-----------------------------------------------------------------------------------
public class Scanner {
- const char EOF = '\0';
- const char CR = '\r';
- const char LF = '\n';
- [Microsoft.Contracts.Verify(false)]
+ const char EOL = '\n';
+ const int eofSym = 0; /* pdt */
+ const int maxT = 88;
+ const int noSym = 88;
+
+
+ public Buffer! buffer; // scanner buffer
+
+ Token! t; // current token
+ int ch; // current input character
+ int pos; // byte position of current character
+ int col; // column number of current character
+ int line; // line number of current character
+ int oldEols; // EOLs that appeared in a comment;
+ static readonly Hashtable! start; // maps first token character to start state
+
+ Token! tokens; // list of tokens already peeked (first token is a dummy)
+ Token! pt; // current peek token
+
+ char[]! tval = new char[128]; // text of current token
+ int tlen; // length of current token
+
+ private string! Filename;
+ private Errors! errorHandler;
+
static Scanner() {
- start[0] = 58;
- start[33] = 41;
- start[34] = 6;
- start[35] = 2;
- start[36] = 2;
- start[37] = 51;
- start[38] = 34;
- start[39] = 2;
- start[40] = 11;
- start[41] = 12;
- start[42] = 24;
- start[43] = 47;
- start[44] = 14;
- start[45] = 49;
- start[46] = 2;
- start[47] = 50;
- start[48] = 9;
- start[49] = 9;
- start[50] = 9;
- start[51] = 9;
- start[52] = 9;
- start[53] = 9;
- start[54] = 9;
- start[55] = 9;
- start[56] = 9;
- start[57] = 9;
- start[58] = 13;
- start[59] = 10;
- start[60] = 17;
- start[61] = 21;
- start[62] = 18;
- start[63] = 2;
- start[65] = 2;
- start[66] = 2;
- start[67] = 2;
- start[68] = 2;
- start[69] = 2;
- start[70] = 2;
- start[71] = 2;
- start[72] = 2;
- start[73] = 2;
- start[74] = 2;
- start[75] = 2;
- start[76] = 2;
- start[77] = 2;
- start[78] = 2;
- start[79] = 2;
- start[80] = 2;
- start[81] = 2;
- start[82] = 2;
- start[83] = 2;
- start[84] = 2;
- start[85] = 2;
- start[86] = 2;
- start[87] = 2;
- start[88] = 2;
- start[89] = 2;
- start[90] = 2;
- start[91] = 15;
- start[92] = 1;
- start[93] = 16;
- start[94] = 2;
- start[95] = 2;
- start[96] = 2;
- start[97] = 2;
- start[98] = 2;
- start[99] = 2;
- start[100] = 2;
- start[101] = 2;
- start[102] = 2;
- start[103] = 2;
- start[104] = 2;
- start[105] = 2;
- start[106] = 2;
- start[107] = 2;
- start[108] = 2;
- start[109] = 2;
- start[110] = 2;
- start[111] = 2;
- start[112] = 2;
- start[113] = 2;
- start[114] = 2;
- start[115] = 2;
- start[116] = 2;
- start[117] = 2;
- start[118] = 2;
- start[119] = 2;
- start[120] = 2;
- start[121] = 2;
- start[122] = 2;
- start[123] = 19;
- start[124] = 37;
- start[125] = 20;
- start[126] = 2;
- start[172] = 52;
- start[955] = 55;
- start[8226] = 57;
- start[8656] = 33;
- start[8658] = 32;
- start[8660] = 29;
- start[8704] = 53;
- start[8707] = 54;
- start[8743] = 36;
- start[8744] = 39;
- start[8800] = 44;
- start[8804] = 45;
- start[8805] = 46;
+ start = new Hashtable(128);
+ for (int i = 35; i <= 36; ++i) start[i] = 2;
+ for (int i = 39; i <= 39; ++i) start[i] = 2;
+ for (int i = 46; i <= 46; ++i) start[i] = 2;
+ for (int i = 63; i <= 63; ++i) start[i] = 2;
+ for (int i = 65; i <= 90; ++i) start[i] = 2;
+ for (int i = 94; i <= 122; ++i) start[i] = 2;
+ for (int i = 126; i <= 126; ++i) start[i] = 2;
+ for (int i = 48; i <= 57; ++i) start[i] = 9;
+ for (int i = 34; i <= 34; ++i) start[i] = 6;
+ start[92] = 1;
+ start[59] = 10;
+ start[40] = 11;
+ start[41] = 12;
+ start[58] = 47;
+ start[44] = 13;
+ start[91] = 14;
+ start[93] = 15;
+ start[60] = 48;
+ start[62] = 49;
+ start[123] = 50;
+ start[125] = 51;
+ start[61] = 52;
+ start[42] = 18;
+ start[8660] = 21;
+ start[8658] = 23;
+ start[8656] = 24;
+ start[38] = 25;
+ start[8743] = 27;
+ start[124] = 28;
+ start[8744] = 30;
+ start[33] = 53;
+ start[8800] = 34;
+ start[8804] = 35;
+ start[8805] = 36;
+ start[43] = 54;
+ start[45] = 38;
+ start[47] = 39;
+ start[37] = 40;
+ start[172] = 41;
+ start[8704] = 42;
+ start[8707] = 43;
+ start[955] = 44;
+ start[8226] = 46;
+ start[Buffer.EOF] = -1;
+
}
- const int noSym = 88;
- static short[] start = new short[16385];
-
-
- static Token/*!*/ t; // current token
- static char ch; // current input character
- static int pos; // column number of current character
- static int line; // line number of current character
- static int lineStart; // start position of current line
- static Queue! oldEols; // EOLs that appeared in a comment;
- static BitArray/*!*/ ignore; // set of characters to be ignored by the scanner
- static string Filename;
-
- ///<summary>
- ///Initializes the scanner. Note: first fill the Buffer.
- ///</summary>
- ///<param name="filename">File name used for error reporting</param>
- public static void Init (string filename) {
- Filename = filename;
- pos = -1; line = 1; lineStart = 0;
- oldEols = new Queue();
- NextCh();
- ignore = new BitArray(16384);
- ignore[9] = true; ignore[10] = true; ignore[13] = true; ignore[32] = true;
-
- }
-
- private static void NextCh() {
- if (oldEols.Count > 0) {
- ch = (char) ((!)oldEols.Dequeue());
- } else {
- while (true) {
- ch = (char)Buffer.Read(); pos++;
- if (ch == Buffer.eof) {
- ch = EOF;
- } else if (ch == LF) {
- line++;
- lineStart = pos + 1;
-
- } else if (ch == '#' && pos == lineStart) {
- int prLine = line;
- int prColumn = pos - lineStart; // which is 0
-
- string hashLine = Buffer.ReadToEOL(); pos += hashLine.Length;
- line++;
- lineStart = pos + 1;
-
- hashLine = hashLine.TrimEnd(null);
- if (hashLine.StartsWith("line ") || hashLine == "line") {
- // parse #line pragma: #line num [filename]
- string h = hashLine.Substring(4).TrimStart(null);
- int x = h.IndexOf(' ');
- if (x == -1) {
- x = h.Length; // this will be convenient below when we look for a filename
- }
- try {
- int li = int.Parse(h.Substring(0, x));
-
- h = h.Substring(x).Trim();
-
- // act on #line
- line = li;
- if (h.Length != 0) {
- // a filename was specified
- Filename = h;
- }
- continue; // successfully parsed and acted on the #line pragma
-
- } catch (FormatException) {
- // just fall down through to produce an error message
- }
- Errors.SemErr(Filename, prLine, prColumn, "Malformed (#line num [filename]) pragma: #" + hashLine);
- continue;
- }
-
- Errors.SemErr(Filename, prLine, prColumn, "Unrecognized pragma: #" + hashLine);
- continue;
- }
- return;
- }
- }
- }
-
-
- static bool Comment0() {
- int level = 1, line0 = line, lineStart0 = lineStart;
+
+ [NotDelayed]
+ public Scanner (string! fileName, Errors! errorHandler) {
+ this.errorHandler = errorHandler;
+ pt = tokens = new Token(); // first token is a dummy
+ t = new Token(); // dummy because t is a non-null field
+ try {
+ Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
+ buffer = new Buffer(stream, false);
+ Filename = fileName;
+ base();
+ Init();
+ } catch (IOException) {
+ throw new FatalError("Cannot open file " + fileName);
+ }
+ }
+
+ [NotDelayed]
+ public Scanner (Stream! s, Errors! errorHandler, string! fileName) {
+ pt = tokens = new Token(); // first token is a dummy
+ t = new Token(); // dummy because t is a non-null field
+ buffer = new Buffer(s, true);
+ this.errorHandler = errorHandler;
+ this.Filename = fileName;
+ base();
+ Init();
+ }
+
+ void Init() {
+ pos = -1; line = 1; col = 0;
+ oldEols = 0;
+ NextCh();
+ if (ch == 0xEF) { // check optional byte order mark for UTF-8
+ NextCh(); int ch1 = ch;
+ NextCh(); int ch2 = ch;
+ if (ch1 != 0xBB || ch2 != 0xBF) {
+ throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2));
+ }
+ buffer = new UTF8Buffer(buffer); col = 0;
+ NextCh();
+ }
+ pt = tokens = new Token(); // first token is a dummy
+ }
+
+ string! ReadToEOL(){
+ int p = buffer.Pos;
+ int ch = buffer.Read();
+ // replace isolated '\r' by '\n' in order to make
+ // eol handling uniform across Windows, Unix and Mac
+ if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+ while (ch != EOL && ch != Buffer.EOF){
+ ch = buffer.Read();
+ // replace isolated '\r' by '\n' in order to make
+ // eol handling uniform across Windows, Unix and Mac
+ if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+ }
+ string! s = buffer.GetString(p, buffer.Pos);
+ return s;
+ }
+
+ void NextCh() {
+ if (oldEols > 0) { ch = EOL; oldEols--; }
+ else {
+// pos = buffer.Pos;
+// ch = buffer.Read(); col++;
+// // replace isolated '\r' by '\n' in order to make
+// // eol handling uniform across Windows, Unix and Mac
+// if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+// if (ch == EOL) { line++; col = 0; }
+
+ while (true) {
+ pos = buffer.Pos;
+ ch = buffer.Read(); col++;
+ // replace isolated '\r' by '\n' in order to make
+ // eol handling uniform across Windows, Unix and Mac
+ if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+ if (ch == EOL) {
+ line++; col = 0;
+ } else if (ch == '#' && col == 1) {
+ int prLine = line;
+ int prColumn = 0;
+
+ string! hashLine = ReadToEOL();
+ col = 0;
+ line++;
+
+ hashLine = hashLine.TrimEnd(null);
+ if (hashLine.StartsWith("line ") || hashLine == "line") {
+ // parse #line pragma: #line num [filename]
+ string h = hashLine.Substring(4).TrimStart(null);
+ int x = h.IndexOf(' ');
+ if (x == -1) {
+ x = h.Length; // this will be convenient below when we look for a filename
+ }
+ try {
+ int li = int.Parse(h.Substring(0, x));
+
+ h = h.Substring(x).Trim();
+
+ // act on #line
+ line = li;
+ if (h.Length != 0) {
+ // a filename was specified
+ Filename = h;
+ }
+ continue; // successfully parsed and acted on the #line pragma
+
+ } catch (FormatException) {
+ // just fall down through to produce an error message
+ }
+ this.errorHandler.SemErr(Filename, prLine, prColumn, "Malformed (#line num [filename]) pragma: #" + hashLine);
+ continue;
+ }
+
+ this.errorHandler.SemErr(Filename, prLine, prColumn, "Unrecognized pragma: #" + hashLine);
+ continue;
+ }
+ return;
+ }
+
+
+ }
+
+ }
+
+ void AddCh() {
+ if (tlen >= tval.Length) {
+ char[] newBuf = new char[2 * tval.Length];
+ Array.Copy(tval, 0, newBuf, 0, tval.Length);
+ tval = newBuf;
+ }
+ if (ch != Buffer.EOF) {
+ tval[tlen++] = (char) ch;
+ NextCh();
+ }
+ }
+
+
+
+ bool Comment0() {
+ int level = 1, pos0 = pos, line0 = line, col0 = col;
NextCh();
if (ch == '/') {
NextCh();
for(;;) {
if (ch == 10) {
level--;
- if (level == 0) {
- while(line0 < line) {oldEols.Enqueue('\r'); oldEols.Enqueue('\n'); line0++;}
- NextCh(); return true;
- }
+ if (level == 0) { oldEols = line - line0; NextCh(); return true; }
NextCh();
- } else if (ch == EOF) return false;
+ } else if (ch == Buffer.EOF) return false;
else NextCh();
}
} else {
- if (ch==CR) {line--; lineStart = lineStart0;}
- pos = pos - 2; Buffer.Pos = pos+1; NextCh();
+ buffer.Pos = pos0; NextCh(); line = line0; col = col0;
}
return false;
}
-
- static bool Comment1() {
- int level = 1, line0 = line, lineStart0 = lineStart;
+
+ bool Comment1() {
+ int level = 1, pos0 = pos, line0 = line, col0 = col;
NextCh();
if (ch == '*') {
NextCh();
@@ -463,10 +508,7 @@ public class Scanner {
NextCh();
if (ch == '/') {
level--;
- if (level == 0) {
- while(line0 < line) {oldEols.Enqueue('\r'); oldEols.Enqueue('\n'); line0++;}
- NextCh(); return true;
- }
+ if (level == 0) { oldEols = line - line0; NextCh(); return true; }
NextCh();
}
} else if (ch == '/') {
@@ -474,19 +516,18 @@ public class Scanner {
if (ch == '*') {
level++; NextCh();
}
- } else if (ch == EOF) return false;
+ } else if (ch == Buffer.EOF) return false;
else NextCh();
}
} else {
- if (ch==CR) {line--; lineStart = lineStart0;}
- pos = pos - 2; Buffer.Pos = pos+1; NextCh();
+ buffer.Pos = pos0; NextCh(); line = line0; col = col0;
}
return false;
}
-
- static void CheckLiteral() {
- switch (t.val) {
+
+ void CheckLiteral() {
+ switch (t.val) {
case "var": t.kind = 6; break;
case "where": t.kind = 12; break;
case "int": t.kind = 13; break;
@@ -524,197 +565,229 @@ public class Scanner {
case "exists": t.kind = 82; break;
case "lambda": t.kind = 84; break;
default: break;
+ }
+ }
- }
- }
-
- public static Token/*!*/ Scan() {
- while (ignore[ch]) { NextCh(); }
- if (ch == '/' && Comment0() || ch == '/' && Comment1() ) return Scan();
- t = new Token();
- t.pos = pos; t.col = pos - lineStart + 1; t.line = line; t.filename = Filename;
- int state = (/*^ (!) ^*/ start)[ch];
- StringBuilder buf = new StringBuilder(16);
- buf.Append(ch); NextCh();
-
- switch (state) {
- case 0: {t.kind = noSym; goto done;} // NextCh already done
+ Token! NextToken() {
+ while (ch == ' ' ||
+ ch >= 9 && ch <= 10 || ch == 13
+ ) NextCh();
+ if (ch == '/' && Comment0() ||ch == '/' && Comment1()) return NextToken();
+ int recKind = noSym;
+ int recEnd = pos;
+ t = new Token();
+ t.pos = pos; t.col = col; t.line = line;
+ t.filename = this.Filename;
+ int state;
+ if (start.ContainsKey(ch)) { state = (int) (!) start[ch]; }
+ else { state = 0; }
+ tlen = 0; AddCh();
+
+ switch (state) {
+ case -1: { t.kind = eofSym; break; } // NextCh already done
+ case 0: {
+ if (recKind != noSym) {
+ tlen = recEnd - t.pos;
+ SetScannerBehindT();
+ }
+ t.kind = recKind; break;
+ } // NextCh already done
case 1:
- if ((ch >= '#' && ch <= '$' || ch == 39 || ch == '.' || ch == '?' || ch >= 'A' && ch <= 'Z' || ch >= '^' && ch <= 'z' || ch == '~')) {buf.Append(ch); NextCh(); goto case 2;}
- else {t.kind = noSym; goto done;}
+ if (ch >= '#' && ch <= '$' || ch == 39 || ch == '.' || ch == '?' || ch >= 'A' && ch <= 'Z' || ch >= '^' && ch <= 'z' || ch == '~') {AddCh(); goto case 2;}
+ else {goto case 0;}
case 2:
- if ((ch >= '#' && ch <= '$' || ch == 39 || ch == '.' || ch >= '0' && ch <= '9' || ch == '?' || ch >= 'A' && ch <= 'Z' || ch >= '^' && ch <= 'z' || ch == '~')) {buf.Append(ch); NextCh(); goto case 2;}
- else {t.kind = 1; t.val = buf.ToString(); CheckLiteral(); return t;}
+ recEnd = pos; recKind = 1;
+ if (ch >= '#' && ch <= '$' || ch == 39 || ch == '.' || ch >= '0' && ch <= '9' || ch == '?' || ch >= 'A' && ch <= 'Z' || ch >= '^' && ch <= 'z' || ch == '~') {AddCh(); goto case 2;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
case 3:
- if (ch == 'v') {buf.Append(ch); NextCh(); goto case 4;}
- else {t.kind = noSym; goto done;}
+ if (ch == 'v') {AddCh(); goto case 4;}
+ else {goto case 0;}
case 4:
- if ((ch >= '0' && ch <= '9')) {buf.Append(ch); NextCh(); goto case 5;}
- else {t.kind = noSym; goto done;}
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 5;}
+ else {goto case 0;}
case 5:
- if ((ch >= '0' && ch <= '9')) {buf.Append(ch); NextCh(); goto case 5;}
- else {t.kind = 2; goto done;}
+ recEnd = pos; recKind = 2;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 5;}
+ else {t.kind = 2; break;}
case 6:
- if ((ch == '"')) {buf.Append(ch); NextCh(); goto case 7;}
- else if ((ch >= ' ' && ch <= '!' || ch >= '#' && ch <= '~')) {buf.Append(ch); NextCh(); goto case 6;}
- else {t.kind = noSym; goto done;}
+ if (ch == '"') {AddCh(); goto case 7;}
+ else if (ch >= ' ' && ch <= '!' || ch >= '#' && ch <= '~') {AddCh(); goto case 6;}
+ else {goto case 0;}
case 7:
- {t.kind = 4; goto done;}
+ {t.kind = 4; break;}
case 8:
- if ((ch >= '0' && ch <= '9')) {buf.Append(ch); NextCh(); goto case 8;}
- else {t.kind = 5; goto done;}
+ recEnd = pos; recKind = 5;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 8;}
+ else {t.kind = 5; break;}
case 9:
- if ((ch >= '0' && ch <= '9')) {buf.Append(ch); NextCh(); goto case 9;}
- else if (ch == 'b') {buf.Append(ch); NextCh(); goto case 3;}
- else if (ch == '.') {buf.Append(ch); NextCh(); goto case 8;}
- else {t.kind = 3; goto done;}
+ recEnd = pos; recKind = 3;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 9;}
+ else if (ch == 'b') {AddCh(); goto case 3;}
+ else if (ch == '.') {AddCh(); goto case 8;}
+ else {t.kind = 3; break;}
case 10:
- {t.kind = 7; goto done;}
+ {t.kind = 7; break;}
case 11:
- {t.kind = 8; goto done;}
+ {t.kind = 8; break;}
case 12:
- {t.kind = 9; goto done;}
+ {t.kind = 9; break;}
case 13:
- if (ch == '=') {buf.Append(ch); NextCh(); goto case 25;}
- else if (ch == ':') {buf.Append(ch); NextCh(); goto case 56;}
- else {t.kind = 10; goto done;}
+ {t.kind = 11; break;}
case 14:
- {t.kind = 11; goto done;}
+ {t.kind = 15; break;}
case 15:
- {t.kind = 15; goto done;}
+ {t.kind = 16; break;}
case 16:
- {t.kind = 16; goto done;}
+ {t.kind = 36; break;}
case 17:
- if (ch == '=') {buf.Append(ch); NextCh(); goto case 26;}
- else if (ch == ':') {buf.Append(ch); NextCh(); goto case 43;}
- else {t.kind = 17; goto done;}
+ {t.kind = 37; break;}
case 18:
- if (ch == '=') {buf.Append(ch); NextCh(); goto case 40;}
- else {t.kind = 18; goto done;}
+ {t.kind = 44; break;}
case 19:
- if (ch == '{') {buf.Append(ch); NextCh(); goto case 22;}
- else {t.kind = 25; goto done;}
+ {t.kind = 49; break;}
case 20:
- if (ch == '}') {buf.Append(ch); NextCh(); goto case 23;}
- else {t.kind = 26; goto done;}
+ {t.kind = 52; break;}
case 21:
- if (ch == '=') {buf.Append(ch); NextCh(); goto case 30;}
- else {t.kind = 29; goto done;}
+ {t.kind = 53; break;}
case 22:
- {t.kind = 36; goto done;}
+ {t.kind = 54; break;}
case 23:
- {t.kind = 37; goto done;}
+ {t.kind = 55; break;}
case 24:
- {t.kind = 44; goto done;}
+ {t.kind = 57; break;}
case 25:
- {t.kind = 49; goto done;}
+ if (ch == '&') {AddCh(); goto case 26;}
+ else {goto case 0;}
case 26:
- if (ch == '=') {buf.Append(ch); NextCh(); goto case 27;}
- else {t.kind = 63; goto done;}
+ {t.kind = 58; break;}
case 27:
- if (ch == '>') {buf.Append(ch); NextCh(); goto case 28;}
- else {t.kind = 56; goto done;}
+ {t.kind = 59; break;}
case 28:
- {t.kind = 52; goto done;}
+ if (ch == '|') {AddCh(); goto case 29;}
+ else {goto case 0;}
case 29:
- {t.kind = 53; goto done;}
+ {t.kind = 60; break;}
case 30:
- if (ch == '>') {buf.Append(ch); NextCh(); goto case 31;}
- else {t.kind = 62; goto done;}
+ {t.kind = 61; break;}
case 31:
- {t.kind = 54; goto done;}
+ {t.kind = 64; break;}
case 32:
- {t.kind = 55; goto done;}
+ {t.kind = 65; break;}
case 33:
- {t.kind = 57; goto done;}
+ {t.kind = 66; break;}
case 34:
- if (ch == '&') {buf.Append(ch); NextCh(); goto case 35;}
- else {t.kind = noSym; goto done;}
+ {t.kind = 67; break;}
case 35:
- {t.kind = 58; goto done;}
+ {t.kind = 68; break;}
case 36:
- {t.kind = 59; goto done;}
+ {t.kind = 69; break;}
case 37:
- if (ch == '|') {buf.Append(ch); NextCh(); goto case 38;}
- else {t.kind = noSym; goto done;}
+ {t.kind = 70; break;}
case 38:
- {t.kind = 60; goto done;}
+ {t.kind = 72; break;}
case 39:
- {t.kind = 61; goto done;}
+ {t.kind = 73; break;}
case 40:
- {t.kind = 64; goto done;}
+ {t.kind = 74; break;}
case 41:
- if (ch == '=') {buf.Append(ch); NextCh(); goto case 42;}
- else {t.kind = 75; goto done;}
+ {t.kind = 76; break;}
case 42:
- {t.kind = 65; goto done;}
+ {t.kind = 81; break;}
case 43:
- {t.kind = 66; goto done;}
+ {t.kind = 83; break;}
case 44:
- {t.kind = 67; goto done;}
+ {t.kind = 85; break;}
case 45:
- {t.kind = 68; goto done;}
+ {t.kind = 86; break;}
case 46:
- {t.kind = 69; goto done;}
+ {t.kind = 87; break;}
case 47:
- if (ch == '+') {buf.Append(ch); NextCh(); goto case 48;}
- else {t.kind = 71; goto done;}
+ recEnd = pos; recKind = 10;
+ if (ch == '=') {AddCh(); goto case 19;}
+ else if (ch == ':') {AddCh(); goto case 45;}
+ else {t.kind = 10; break;}
case 48:
- {t.kind = 70; goto done;}
+ recEnd = pos; recKind = 17;
+ if (ch == '=') {AddCh(); goto case 55;}
+ else if (ch == ':') {AddCh(); goto case 33;}
+ else {t.kind = 17; break;}
case 49:
- {t.kind = 72; goto done;}
+ recEnd = pos; recKind = 18;
+ if (ch == '=') {AddCh(); goto case 31;}
+ else {t.kind = 18; break;}
case 50:
- {t.kind = 73; goto done;}
+ recEnd = pos; recKind = 25;
+ if (ch == '{') {AddCh(); goto case 16;}
+ else {t.kind = 25; break;}
case 51:
- {t.kind = 74; goto done;}
+ recEnd = pos; recKind = 26;
+ if (ch == '}') {AddCh(); goto case 17;}
+ else {t.kind = 26; break;}
case 52:
- {t.kind = 76; goto done;}
+ recEnd = pos; recKind = 29;
+ if (ch == '=') {AddCh(); goto case 56;}
+ else {t.kind = 29; break;}
case 53:
- {t.kind = 81; goto done;}
+ recEnd = pos; recKind = 75;
+ if (ch == '=') {AddCh(); goto case 32;}
+ else {t.kind = 75; break;}
case 54:
- {t.kind = 83; goto done;}
+ recEnd = pos; recKind = 71;
+ if (ch == '+') {AddCh(); goto case 37;}
+ else {t.kind = 71; break;}
case 55:
- {t.kind = 85; goto done;}
+ recEnd = pos; recKind = 63;
+ if (ch == '=') {AddCh(); goto case 57;}
+ else {t.kind = 63; break;}
case 56:
- {t.kind = 86; goto done;}
+ recEnd = pos; recKind = 62;
+ if (ch == '>') {AddCh(); goto case 22;}
+ else {t.kind = 62; break;}
case 57:
- {t.kind = 87; goto done;}
- case 58: {t.kind = 0; goto done;}
- }
- done:
- t.val = buf.ToString();
- return t;
- }
+ recEnd = pos; recKind = 56;
+ if (ch == '>') {AddCh(); goto case 20;}
+ else {t.kind = 56; break;}
-} // end Scanner
+ }
+ t.val = new String(tval, 0, tlen);
+ return t;
+ }
+
+ private void SetScannerBehindT() {
+ buffer.Pos = t.pos;
+ NextCh();
+ line = t.line; col = t.col;
+ for (int i = 0; i < tlen; i++) NextCh();
+ }
+
+ // get the next token (possibly a token already seen during peeking)
+ public Token! Scan () {
+ if (tokens.next == null) {
+ return NextToken();
+ } else {
+ pt = tokens = tokens.next;
+ return tokens;
+ }
+ }
+ // peek for the next token, ignore pragmas
+ public Token! Peek () {
+ do {
+ if (pt.next == null) {
+ pt.next = NextToken();
+ }
+ pt = pt.next;
+ } while (pt.kind > maxT); // skip pragmas
+
+ return pt;
+ }
-public delegate void ErrorProc(int n, string filename, int line, int col);
+ // make sure that peeking starts at the current scan position
+ public void ResetPeek () { pt = tokens; }
-public class Errors {
- public static int count = 0; // number of errors detected
- public static ErrorProc/*!*/ SynErr; // syntactic errors
-
- public static void SemErr(string filename, int line, int col, string! msg) { // semantic errors
- ConsoleColor color = Console.ForegroundColor;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("{0}({1},{2}): Error: {3}", filename, line, col, msg);
- Console.ForegroundColor = color;
- count++;
- }
-
- public static void SemErr(IToken! tok, string! msg) { // semantic errors
- SemErr(tok.filename, tok.line, tok.col, msg);
- }
-
- public static void Exception (string s) {
- ConsoleColor color = Console.ForegroundColor;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(s);
- Console.ForegroundColor = color;
- System.Environment.Exit(0);
- }
+} // end Scanner
+
+public delegate void ErrorProc(int n, string filename, int line, int col);
-} // Errors
-} // end namespace
+} \ No newline at end of file
diff --git a/Source/Core/parser.frame b/Source/Core/parser.frame
deleted file mode 100644
index c7818e57..00000000
--- a/Source/Core/parser.frame
+++ /dev/null
@@ -1,103 +0,0 @@
-
-using System;
-using Microsoft.Contracts;
-
-namespace -->namespace {
-
-public class Parser {
--->constants
- const bool T = true;
- const bool x = false;
- const int minErrDist = 2;
-
- static Token/*!*/ token; // last recognized token
- static Token/*!*/ t; // lookahead token
- static int errDist = minErrDist;
-
- -->declarations
-
- static void Error(int n) {
- if (errDist >= minErrDist) Errors.SynErr(n, t.filename, t.line, t.col);
- errDist = 0;
- }
-
- public static void SemErr(string! msg) {
- if (errDist >= minErrDist) Errors.SemErr(token.filename, token.line, token.col, msg);
- errDist = 0;
- }
-
- public static void SemErr(IToken! tok, string! msg) {
- Errors.SemErr(tok.filename, tok.line, tok.col, msg);
- }
-
- static void Get() {
- for (;;) {
- token = t;
- t = Scanner.Scan();
- if (t.kind<=maxT) {errDist++; return;}
--->pragmas
- t = token;
- }
- }
-
- static void Expect(int n) {
- if (t.kind==n) Get(); else Error(n);
- }
-
- static bool StartOf(int s) {
- return set[s, t.kind];
- }
-
- static void ExpectWeak(int n, int follow) {
- if (t.kind == n) Get();
- else {
- Error(n);
- while (!StartOf(follow)) Get();
- }
- }
-
- static bool WeakSeparator(int n, int syFol, int repFol) {
- bool[] s = new bool[maxT+1];
- if (t.kind == n) {Get(); return true;}
- else if (StartOf(repFol)) return false;
- else {
- for (int i=0; i <= maxT; i++) {
- s[i] = set[syFol, i] || set[repFol, i] || set[0, i];
- }
- Error(n);
- while (!s[t.kind]) Get();
- return StartOf(syFol);
- }
- }
-
--->productions
-
- public static void Parse() {
- Errors.SynErr = new ErrorProc(SynErr);
- t = new Token();
- Get();
--->parseRoot
- }
-
- [Microsoft.Contracts.Verify(false)]
- static void SynErr(int n, string filename, int line, int col) {
- Errors.count++;
- Console.Write("{0}({1},{2}): syntax error: ", filename, line, col);
- string s;
- switch (n) {
--->errors
- default: s = "error " + n; break;
- }
- Console.WriteLine(s);
- }
-
- static bool[,]! set = {
--->initialization
- };
-
- [Microsoft.Contracts.Verify(false)]
- static Parser() {}
-} // end Parser
-
-} // end namespace
-$$$
diff --git a/Source/Core/scanner.frame b/Source/Core/scanner.frame
deleted file mode 100644
index b9a2ce02..00000000
--- a/Source/Core/scanner.frame
+++ /dev/null
@@ -1,377 +0,0 @@
-using System;
-using System.IO;
-using System.Collections;
-using System.Collections.Generic;
-using System.Text;
-using Microsoft.Contracts;
-
-
-namespace Microsoft.Boogie {
-
- [Immutable]
- public interface IToken {
- int kind {get; set; } // token kind
- string filename {get; set; } // token file
- int pos {get; set; } // token position in the source text (starting at 0)
- int col {get; set; } // token column (starting at 0)
- int line {get; set; } // token line (starting at 1)
- string/*!*/ val {get; set; } // token value
-
- bool IsValid { get; }
- }
-
- [Immutable]
- public class Token : IToken {
- int _kind; // token kind
- string _filename; // token file
- int _pos; // token position in the source text (starting at 0)
- int _col; // token column (starting at 0)
- int _line; // token line (starting at 1)
- string/*!*/ _val = "foo"; // token value
-
- public static IToken! NoToken = new Token();
-
- public Token();
- public Token(int linenum, int colnum) {
- this._line = linenum;
- this._col = colnum;
- base();
- }
-
- public int kind {
- get { return this._kind; }
- set { this._kind = value; }
- }
-
- public string filename{
- get { return this._filename; }
- set { this._filename = value; }
- }
-
- public int pos{
- get { return this._pos; }
- set { this._pos = value; }
- }
-
- public int col{
- get { return this._col; }
- set { this._col = value; }
- }
-
- public int line{
- get { return this._line; }
- set { this._line = value; }
- }
-
- public string/*!*/ val{
- get { return this._val; }
- set { this._val = value; }
- }
-
- public bool IsValid { get { return this._filename != null; } }
- }
-
-}
-
-namespace -->namespace {
-
-using Microsoft.Boogie;
-
-public class Buffer {
- static string/*!*/ buf;
- static int bufLen;
- static int pos;
- public const int eof = '\uffff';
-
- public static void Fill(TextReader! reader) {
- List<string!> defines = new List<string!>();
- Fill(reader, defines);
- }
-
- struct ReadState {
- public bool hasSeenElse;
- public bool mayStillIncludeAnotherAlternative;
- public ReadState(bool hasSeenElse, bool mayStillIncludeAnotherAlternative) {
- this.hasSeenElse = hasSeenElse;
- this.mayStillIncludeAnotherAlternative = mayStillIncludeAnotherAlternative;
- }
- }
-
- public static void Fill(TextReader! reader, List<string!>! defines) {
- StringBuilder sb = new StringBuilder();
- List<ReadState>! readState = new List<ReadState>(); // readState.Count is the current nesting level of #if's
- int ignoreCutoff = -1; // -1 means we're not ignoring; for 0<=n, n means we're ignoring because of something at nesting level n
- while (true)
- invariant -1 <= ignoreCutoff && ignoreCutoff < readState.Count;
- {
- string s = reader.ReadLine();
- if (s == null) {
- if (readState.Count != 0) {
- sb.AppendLine("#MalformedInput: missing #endif");
- }
- break;
- }
- string t = s.Trim();
- if (t.StartsWith("#if")) {
- ReadState rs = new ReadState(false, false);
- if (ignoreCutoff != -1) {
- // we're already in a state of ignoring, so continue to ignore
- } else if (IfdefConditionSaysToInclude(t.Substring(3).TrimStart(), defines)) {
- // include this branch
- } else {
- ignoreCutoff = readState.Count; // start ignoring
- rs.mayStillIncludeAnotherAlternative = true; // allow some later "elsif" or "else" branch to be included
- }
- readState.Add(rs);
- sb.AppendLine(); // ignore the #if line
-
- } else if (t.StartsWith("#elsif")) {
- ReadState rs;
- if (readState.Count == 0 || (rs = readState[readState.Count-1]).hasSeenElse) {
- sb.AppendLine("#MalformedInput: misplaced #elsif"); // malformed input
- break;
- }
- if (ignoreCutoff == -1) {
- // we had included the previous branch
- assert !rs.mayStillIncludeAnotherAlternative;
- ignoreCutoff = readState.Count-1; // start ignoring
- } else if (rs.mayStillIncludeAnotherAlternative && IfdefConditionSaysToInclude(t.Substring(6).TrimStart(), defines)) {
- // include this branch, but no subsequent branch at this level
- ignoreCutoff = -1;
- rs.mayStillIncludeAnotherAlternative = false;
- readState[readState.Count-1] = rs;
- }
- sb.AppendLine(); // ignore the #elsif line
-
- } else if (t == "#else") {
- ReadState rs;
- if (readState.Count == 0 || (rs = readState[readState.Count-1]).hasSeenElse) {
- sb.AppendLine("#MalformedInput: misplaced #else"); // malformed input
- break;
- }
- rs.hasSeenElse = true;
- if (ignoreCutoff == -1) {
- // we had included the previous branch
- assert !rs.mayStillIncludeAnotherAlternative;
- ignoreCutoff = readState.Count-1; // start ignoring
- } else if (rs.mayStillIncludeAnotherAlternative) {
- // include this branch
- ignoreCutoff = -1;
- rs.mayStillIncludeAnotherAlternative = false;
- }
- readState[readState.Count-1] = rs;
- sb.AppendLine(); // ignore the #else line
-
- } else if (t == "#endif") {
- if (readState.Count == 0) {
- sb.AppendLine("#MalformedInput: misplaced #endif"); // malformed input
- break;
- }
- readState.RemoveAt(readState.Count-1); // pop
- if (ignoreCutoff == readState.Count) {
- // we had ignored the branch that ends here; so, now we start including again
- ignoreCutoff = -1;
- }
- sb.AppendLine(); // ignore the #endif line
-
- } else if (ignoreCutoff == -1) {
- sb.AppendLine(s); // included line
-
- } else {
- sb.AppendLine(); // ignore the line
- }
- }
-
- Fill(sb.ToString());
- }
-
- // "arg" is assumed to be trimmed
- private static bool IfdefConditionSaysToInclude(string! arg, List<string!>! defines) {
- bool sense = true;
- while (arg.StartsWith("!")) {
- sense = !sense;
- arg = arg.Substring(1).TrimStart();
- }
- return defines.Contains(arg) == sense;
- }
-
- public static void Fill(string! text) {
- buf = text;
- bufLen = buf.Length;
- pos = 0;
- }
-
- public static int Read() {
- if (pos < bufLen) {
- return buf[pos++];
- } else {
- return eof;
- }
- }
-
- public static string/*!*/ ReadToEOL() {
- int x = buf.IndexOf('\n', pos);
- if (x == -1) {
- string s = buf.Substring(pos);
- pos = buf.Length;
- return s;
- } else {
- string s = buf.Substring(pos, x+1 - pos); // also include the '\n'
- pos = x+1;
- return s;
- }
- }
-
- public static int Pos {
- get { return pos; }
- set {
- if (value < 0) pos = 0; else if (value >= bufLen) pos = bufLen; else pos = value;
- }
- }
-}
-
-
-
-public class Scanner {
- const char EOF = '\0';
- const char CR = '\r';
- const char LF = '\n';
- [Microsoft.Contracts.Verify(false)]
--->declarations
-
- static Token/*!*/ t; // current token
- static char ch; // current input character
- static int pos; // column number of current character
- static int line; // line number of current character
- static int lineStart; // start position of current line
- static Queue! oldEols; // EOLs that appeared in a comment;
- static BitArray/*!*/ ignore; // set of characters to be ignored by the scanner
- static string Filename;
-
- ///<summary>
- ///Initializes the scanner. Note: first fill the Buffer.
- ///</summary>
- ///<param name="filename">File name used for error reporting</param>
- public static void Init (string filename) {
- Filename = filename;
- pos = -1; line = 1; lineStart = 0;
- oldEols = new Queue();
- NextCh();
--->initialization
- }
-
- private static void NextCh() {
- if (oldEols.Count > 0) {
- ch = (char) ((!)oldEols.Dequeue());
- } else {
- while (true) {
- ch = (char)Buffer.Read(); pos++;
- if (ch == Buffer.eof) {
- ch = EOF;
- } else if (ch == LF) {
- line++;
- lineStart = pos + 1;
-
- } else if (ch == '#' && pos == lineStart) {
- int prLine = line;
- int prColumn = pos - lineStart; // which is 0
-
- string hashLine = Buffer.ReadToEOL(); pos += hashLine.Length;
- line++;
- lineStart = pos + 1;
-
- hashLine = hashLine.TrimEnd(null);
- if (hashLine.StartsWith("line ") || hashLine == "line") {
- // parse #line pragma: #line num [filename]
- string h = hashLine.Substring(4).TrimStart(null);
- int x = h.IndexOf(' ');
- if (x == -1) {
- x = h.Length; // this will be convenient below when we look for a filename
- }
- try {
- int li = int.Parse(h.Substring(0, x));
-
- h = h.Substring(x).Trim();
-
- // act on #line
- line = li;
- if (h.Length != 0) {
- // a filename was specified
- Filename = h;
- }
- continue; // successfully parsed and acted on the #line pragma
-
- } catch (FormatException) {
- // just fall down through to produce an error message
- }
- Errors.SemErr(Filename, prLine, prColumn, "Malformed (#line num [filename]) pragma: #" + hashLine);
- continue;
- }
-
- Errors.SemErr(Filename, prLine, prColumn, "Unrecognized pragma: #" + hashLine);
- continue;
- }
- return;
- }
- }
- }
-
--->comment
-
- static void CheckLiteral() {
- switch (t.val) {
--->literals
- }
- }
-
- public static Token/*!*/ Scan() {
- while (ignore[ch]) { NextCh(); }
--->scan1
- t = new Token();
- t.pos = pos; t.col = pos - lineStart + 1; t.line = line; t.filename = Filename;
- int state = (/*^ (!) ^*/ start)[ch];
- StringBuilder buf = new StringBuilder(16);
- buf.Append(ch); NextCh();
-
- switch (state) {
- case 0: {t.kind = noSym; goto done;} // NextCh already done
--->scan2
- }
- done:
- t.val = buf.ToString();
- return t;
- }
-
-} // end Scanner
-
-
-public delegate void ErrorProc(int n, string filename, int line, int col);
-
-public class Errors {
- public static int count = 0; // number of errors detected
- public static ErrorProc/*!*/ SynErr; // syntactic errors
-
- public static void SemErr(string filename, int line, int col, string! msg) { // semantic errors
- ConsoleColor color = Console.ForegroundColor;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("{0}({1},{2}): Error: {3}", filename, line, col, msg);
- Console.ForegroundColor = color;
- count++;
- }
-
- public static void SemErr(IToken! tok, string! msg) { // semantic errors
- SemErr(tok.filename, tok.line, tok.col, msg);
- }
-
- public static void Exception (string s) {
- ConsoleColor color = Console.ForegroundColor;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(s);
- Console.ForegroundColor = color;
- System.Environment.Exit(0);
- }
-
-} // Errors
-
-} // end namespace
-$$$
diff --git a/Source/Dafny/Dafny.atg b/Source/Dafny/Dafny.atg
index 7affe087..ca02d3cf 100644
--- a/Source/Dafny/Dafny.atg
+++ b/Source/Dafny/Dafny.atg
@@ -12,6 +12,8 @@
using System.Collections.Generic;
using System.Numerics;
using Microsoft.Boogie;
+using System.IO;
+using System.Text;
COMPILER Dafny
@@ -64,15 +66,14 @@ private static Expression! ConvertToLocal(Expression! e)
/// Note: first initialize the Scanner.
///</summary>
public static int Parse (string! filename, List<ModuleDecl!>! modules) /* throws System.IO.IOException */ {
+ string s;
if (filename == "stdin.dfy") {
- BoogiePL.Buffer.Fill(System.Console.In);
- Scanner.Init(filename);
- return Parse(modules);
+ s = Microsoft.Boogie.ParserHelper.Fill(System.Console.In, new List<string!>());
+ return Parse(s, modules);
} else {
using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) {
- BoogiePL.Buffer.Fill(reader);
- Scanner.Init(filename);
- return Parse(modules);
+ s = Microsoft.Boogie.ParserHelper.Fill(reader, new List<string!>());
+ return Parse(s, filename, modules);
}
}
}
@@ -83,12 +84,17 @@ public static int Parse (string! filename, List<ModuleDecl!>! modules) /* throws
/// Returns the number of parsing errors encountered.
/// Note: first initialize the Scanner.
///</summary>
-public static int Parse (List<ModuleDecl!>! modules) {
+public static int Parse (string! s, string! filename, List<ModuleDecl!>! modules) {
List<ModuleDecl!> oldModules = theModules;
theModules = modules;
- Parse();
+ byte[]! buffer = (!) UTF8Encoding.Default.GetBytes(s);
+ MemoryStream ms = new MemoryStream(buffer,false);
+ Errors errors = new Errors();
+ Scanner scanner = new Scanner(ms, errors, filename);
+ Parser parser = new Parser(scanner, errors);
+ parser.Parse();
theModules = oldModules;
- return Errors.count;
+ return parser.errors.count;
}
/*--------------------------------------------------------------------------*/
@@ -126,7 +132,7 @@ PRODUCTIONS
Dafny
= (. ClassDecl! c; DatatypeDecl! dt;
- Attributes attrs; Token! id; List<string!> theImports;
+ Attributes attrs; IToken! id; List<string!> theImports;
List<MemberDecl!> membersDefaultClass = new List<MemberDecl!>();
ModuleDecl module;
@@ -174,7 +180,7 @@ Dafny
.
ClassDecl<ModuleDecl! module, out ClassDecl! c>
-= (. Token! id;
+= (. IToken! id;
Attributes attrs = null;
List<TypeParameter!> typeArgs = new List<TypeParameter!>();
List<MemberDecl!> members = new List<MemberDecl!>();
@@ -189,7 +195,7 @@ ClassDecl<ModuleDecl! module, out ClassDecl! c>
"}" (. c = new ClassDecl(id, id.val, module, typeArgs, members, attrs); .)
.
-ClassMemberDecl<List<MemberDecl!\>! mm>
+ClassMemberDecl<.List<MemberDecl!>! mm.>
= (. Method! m;
Function! f;
MemberModifiers mmod = new MemberModifiers();
@@ -205,7 +211,7 @@ ClassMemberDecl<List<MemberDecl!\>! mm>
.
DatatypeDecl<ModuleDecl! module, out DatatypeDecl! dt>
-= (. Token! id;
+= (. IToken! id;
Attributes attrs = null;
List<TypeParameter!> typeArgs = new List<TypeParameter!>();
List<DatatypeCtor!> ctors = new List<DatatypeCtor!>();
@@ -220,9 +226,9 @@ DatatypeDecl<ModuleDecl! module, out DatatypeDecl! dt>
"}" (. dt = new DatatypeDecl(id, id.val, module, typeArgs, ctors, attrs); .)
.
-DatatypeMemberDecl<List<DatatypeCtor!\>! ctors>
+DatatypeMemberDecl<.List<DatatypeCtor!>! ctors.>
= (. Attributes attrs = null;
- Token! id;
+ IToken! id;
List<TypeParameter!> typeArgs = new List<TypeParameter!>();
List<Formal!> formals = new List<Formal!>();
.)
@@ -237,13 +243,13 @@ DatatypeMemberDecl<List<DatatypeCtor!\>! ctors>
";"
.
-FieldDecl<MemberModifiers mmod, List<MemberDecl!\>! mm>
+FieldDecl<.MemberModifiers mmod, List<MemberDecl!>! mm.>
= (. Attributes attrs = null;
- Token! id; Type! ty;
+ IToken! id; Type! ty;
.)
"var"
- (. if (mmod.IsUnlimited) { SemErr(token, "fields cannot be declared 'unlimited'"); }
- if (mmod.IsStatic) { SemErr(token, "fields cannot be declared 'static'"); }
+ (. if (mmod.IsUnlimited) { SemErr(t, "fields cannot be declared 'unlimited'"); }
+ if (mmod.IsStatic) { SemErr(t, "fields cannot be declared 'static'"); }
.)
{ Attribute<ref attrs> }
IdentType<out id, out ty> (. mm.Add(new Field(id, id.val, mmod.IsGhost, ty, attrs)); .)
@@ -252,22 +258,22 @@ FieldDecl<MemberModifiers mmod, List<MemberDecl!\>! mm>
";"
.
-GIdentType<bool allowGhost, out Token! id, out Type! ty, out bool isGhost>
+GIdentType<bool allowGhost, out IToken! id, out Type! ty, out bool isGhost>
/* isGhost always returns as false if allowGhost is false */
= (. isGhost = false; .)
- [ "ghost" (. if (allowGhost) { isGhost = true; } else { SemErr(token, "formal cannot be declared 'ghost' in this context"); } .)
+ [ "ghost" (. if (allowGhost) { isGhost = true; } else { SemErr(t, "formal cannot be declared 'ghost' in this context"); } .)
]
IdentType<out id, out ty>
.
-IdentType<out Token! id, out Type! ty>
+IdentType<out IToken! id, out Type! ty>
= Ident<out id>
":"
Type<out ty>
.
IdentTypeOptional<out BoundVar! var>
-= (. Token! id; Type! ty; Type optType = null;
+= (. IToken! id; Type! ty; Type optType = null;
.)
Ident<out id>
[ ":" Type<out ty> (. optType = ty; .)
@@ -275,7 +281,7 @@ IdentTypeOptional<out BoundVar! var>
(. var = new BoundVar(id, id.val, optType == null ? new InferredTypeProxy() : optType); .)
.
-TypeIdentOptional<out Token! id, out string! identName, out Type! ty, out bool isGhost>
+TypeIdentOptional<out IToken! id, out string! identName, out Type! ty, out bool isGhost>
= (. string name = null; isGhost = false; .)
[ "ghost" (. isGhost = true; .)
]
@@ -301,8 +307,8 @@ TypeIdentOptional<out Token! id, out string! identName, out Type! ty, out bool i
/*------------------------------------------------------------------------*/
-GenericParameters<List<TypeParameter!\>! typeArgs>
-= (. Token! id; .)
+GenericParameters<.List<TypeParameter!>! typeArgs.>
+= (. IToken! id; .)
"<"
Ident<out id> (. typeArgs.Add(new TypeParameter(id, id.val)); .)
{ "," Ident<out id> (. typeArgs.Add(new TypeParameter(id, id.val)); .)
@@ -313,7 +319,7 @@ GenericParameters<List<TypeParameter!\>! typeArgs>
/*------------------------------------------------------------------------*/
MethodDecl<MemberModifiers mmod, out Method! m>
-= (. Token! id;
+= (. IToken! id;
Attributes attrs = null;
List<TypeParameter!>! typeArgs = new List<TypeParameter!>();
List<Formal!> ins = new List<Formal!>();
@@ -325,7 +331,7 @@ MethodDecl<MemberModifiers mmod, out Method! m>
Statement! bb; BlockStmt body = null;
.)
"method"
- (. if (mmod.IsUnlimited) { SemErr(token, "methods cannot be declared 'unlimited'"); }
+ (. if (mmod.IsUnlimited) { SemErr(t, "methods cannot be declared 'unlimited'"); }
.)
{ Attribute<ref attrs> }
Ident<out id>
@@ -345,8 +351,8 @@ MethodDecl<MemberModifiers mmod, out Method! m>
.)
.
-MethodSpec<List<MaybeFreeExpression!\>! req, List<FrameExpression!\>! mod, List<MaybeFreeExpression!\>! ens,
- List<Expression!\>! decreases>
+MethodSpec<.List<MaybeFreeExpression!>! req, List<FrameExpression!>! mod, List<MaybeFreeExpression!>! ens,
+ List<Expression!>! decreases.>
= (. Expression! e; FrameExpression! fe; bool isFree = false;
.)
( "modifies" [ FrameExpression<out fe> (. mod.Add(fe); .)
@@ -362,8 +368,8 @@ MethodSpec<List<MaybeFreeExpression!\>! req, List<FrameExpression!\>! mod, List<
)
.
-Formals<bool incoming, bool allowGhosts, List<Formal!\>! formals>
-= (. Token! id; Type! ty; bool isGhost; .)
+Formals<.bool incoming, bool allowGhosts, List<Formal!>! formals.>
+= (. IToken! id; Type! ty; bool isGhost; .)
"("
[
GIdentType<allowGhosts, out id, out ty, out isGhost> (. formals.Add(new Formal(id, id.val, ty, incoming, isGhost)); parseVarScope.Push(id.val, id.val); .)
@@ -373,8 +379,8 @@ Formals<bool incoming, bool allowGhosts, List<Formal!\>! formals>
")"
.
-FormalsOptionalIds<List<Formal!\>! formals>
-= (. Token! id; Type! ty; string! name; bool isGhost; .)
+FormalsOptionalIds<.List<Formal!>! formals.>
+= (. IToken! id; Type! ty; string! name; bool isGhost; .)
"("
[
TypeIdentOptional<out id, out name, out ty, out isGhost> (. formals.Add(new Formal(id, name, ty, true, isGhost)); parseVarScope.Push(name, name); .)
@@ -387,24 +393,24 @@ FormalsOptionalIds<List<Formal!\>! formals>
/*------------------------------------------------------------------------*/
Type<out Type! ty>
-= (. Token! tok; .)
+= (. IToken! tok; .)
TypeAndToken<out tok, out ty>
.
-TypeAndToken<out Token! tok, out Type! ty>
+TypeAndToken<out IToken! tok, out Type! ty>
= (. tok = Token.NoToken; ty = new BoolType(); /*keep compiler happy*/
List<Type!>! gt;
.)
- ( "bool" (. tok = token; .)
- | "int" (. tok = token; ty = new IntType(); .)
- | "set" (. tok = token; gt = new List<Type!>(); .)
+ ( "bool" (. tok = t; .)
+ | "int" (. tok = t; ty = new IntType(); .)
+ | "set" (. tok = t; gt = new List<Type!>(); .)
GenericInstantiation<gt> (. if (gt.Count != 1) {
SemErr("set type expects exactly one type argument");
}
ty = new SetType(gt[0]);
.)
- | "seq" (. tok = token; gt = new List<Type!>(); .)
+ | "seq" (. tok = t; gt = new List<Type!>(); .)
GenericInstantiation<gt> (. if (gt.Count != 1) {
SemErr("seq type expects exactly one type argument");
}
@@ -414,12 +420,12 @@ TypeAndToken<out Token! tok, out Type! ty>
)
.
-ReferenceType<out Token! tok, out Type! ty>
+ReferenceType<out IToken! tok, out Type! ty>
= (. tok = Token.NoToken; ty = new BoolType(); /*keep compiler happy*/
List<Type!>! gt;
.)
- ( "object" (. tok = token; ty = new ObjectType(); .)
- | "array" (. tok = token; gt = new List<Type!>(); .)
+ ( "object" (. tok = t; ty = new ObjectType(); .)
+ | "array" (. tok = t; gt = new List<Type!>(); .)
GenericInstantiation<gt> (. if (gt.Count != 1) {
SemErr("array type expects exactly one type argument");
}
@@ -430,7 +436,7 @@ ReferenceType<out Token! tok, out Type! ty>
)
.
-GenericInstantiation<List<Type!\>! gt>
+GenericInstantiation<.List<Type!>! gt.>
= (. Type! ty; .)
"<"
Type<out ty> (. gt.Add(ty); .)
@@ -443,7 +449,7 @@ GenericInstantiation<List<Type!\>! gt>
FunctionDecl<MemberModifiers mmod, out Function! f>
= (. Attributes attrs = null;
- Token! id;
+ IToken! id;
List<TypeParameter!> typeArgs = new List<TypeParameter!>();
List<Formal!> formals = new List<Formal!>();
Type! returnType;
@@ -456,7 +462,7 @@ FunctionDecl<MemberModifiers mmod, out Function! f>
"function"
[ "method" (. isFunctionMethod = true; .)
]
- (. if (mmod.IsGhost) { SemErr(token, "functions cannot be declared 'ghost' (they are ghost by default)"); }
+ (. if (mmod.IsGhost) { SemErr(t, "functions cannot be declared 'ghost' (they are ghost by default)"); }
.)
{ Attribute<ref attrs> }
Ident<out id>
@@ -475,7 +481,7 @@ FunctionDecl<MemberModifiers mmod, out Function! f>
.)
.
-FunctionSpec<List<Expression!\>! reqs, List<FrameExpression!\>! reads, List<Expression!\>! decreases>
+FunctionSpec<.List<Expression!>! reqs, List<FrameExpression!>! reads, List<Expression!>! decreases.>
= (. Expression! e; FrameExpression! fe; .)
( "requires" Expression<out e> ";" (. reqs.Add(e); .)
| "reads" [ PossiblyWildFrameExpression<out fe> (. reads.Add(fe); .)
@@ -491,7 +497,7 @@ PossiblyWildExpression<out Expression! e>
/* A decreases clause on a loop asks that no termination check be performed.
* Use of this feature is sound only with respect to partial correctness.
*/
- ( "*" (. e = new WildcardExpr(token); .)
+ ( "*" (. e = new WildcardExpr(t); .)
| Expression<out e>
)
.
@@ -504,13 +510,13 @@ PossiblyWildFrameExpression<out FrameExpression! fe>
* any use of the function. Nevertheless, as an experimental feature, the
* language allows it (and it is sound).
*/
- ( "*" (. fe = new FrameExpression(new WildcardExpr(token), null); .)
+ ( "*" (. fe = new FrameExpression(new WildcardExpr(t), null); .)
| FrameExpression<out fe>
)
.
FrameExpression<out FrameExpression! fe>
-= (. Expression! e; Token! id; string fieldName = null; .)
+= (. Expression! e; IToken! id; string fieldName = null; .)
Expression<out e>
[ "`" Ident<out id> (. fieldName = id.val; .)
]
@@ -527,10 +533,10 @@ FunctionBody<out Expression! e>
.
MatchExpression<out Expression! e>
-= (. Token! x; MatchCaseExpr! c;
+= (. IToken! x; MatchCaseExpr! c;
List<MatchCaseExpr!> cases = new List<MatchCaseExpr!>();
.)
- "match" (. x = token; .)
+ "match" (. x = t; .)
Expression<out e>
{ CaseExpression<out c> (. cases.Add(c); .)
}
@@ -538,11 +544,11 @@ MatchExpression<out Expression! e>
.
CaseExpression<out MatchCaseExpr! c>
-= (. Token! x, id, arg;
+= (. IToken! x, id, arg;
List<BoundVar!> arguments = new List<BoundVar!>();
Expression! body;
.)
- "case" (. x = token; parseVarScope.PushMarker(); .)
+ "case" (. x = t; parseVarScope.PushMarker(); .)
Ident<out id>
[ "("
Ident<out arg> (. arguments.Add(new BoundVar(arg, arg.val, new InferredTypeProxy()));
@@ -559,19 +565,19 @@ CaseExpression<out MatchCaseExpr! c>
/*------------------------------------------------------------------------*/
BlockStmt<out Statement! block>
-= (. Token! x;
+= (. IToken! x;
List<Statement!> body = new List<Statement!>();
Statement! s;
.)
(. parseVarScope.PushMarker(); .)
- "{" (. x = token; .)
+ "{" (. x = t; .)
{ Stmt<body>
}
"}" (. block = new BlockStmt(x, body); .)
(. parseVarScope.PopMarker(); .)
.
-Stmt<List<Statement!\>! ss>
+Stmt<.List<Statement!>! ss.>
= (. Statement! s; .)
/* By first reading a sequence of block statements, we avoid problems in the generated parser, despite
the ambiguity in the grammar. See Note in ConstAtomExpression production.
@@ -584,7 +590,7 @@ Stmt<List<Statement!\>! ss>
.
OneStmt<out Statement! s>
-= (. Token! x; Token! id; string label = null;
+= (. IToken! x; IToken! id; string label = null;
s = dummyStmt; /* to please the compiler */
.)
/* This list does not contain BlockStmt, see comment above in Stmt production. */
@@ -599,25 +605,25 @@ OneStmt<out Statement! s>
| WhileStmt<out s>
| MatchStmt<out s>
| ForeachStmt<out s>
- | "label" (. x = token; .)
+ | "label" (. x = t; .)
Ident<out id> ":" (. s = new LabelStmt(x, id.val); .)
- | "break" (. x = token; .)
+ | "break" (. x = t; .)
[ Ident<out id> (. label = id.val; .)
] ";" (. s = new BreakStmt(x, label); .)
- | "return" (. x = token; .)
+ | "return" (. x = t; .)
";" (. s = new ReturnStmt(x); .)
)
.
AssignStmt<out Statement! s>
-= (. Token! x;
+= (. IToken! x;
Expression! lhs;
Expression rhs;
Type ty;
s = dummyStmt;
.)
LhsExpr<out lhs>
- ":=" (. x = token; .)
+ ":=" (. x = t; .)
AssignRhs<out rhs, out ty> (. if (ty == null) {
assert rhs != null;
s = new AssignStmt(x, lhs, rhs);
@@ -632,7 +638,7 @@ AssignStmt<out Statement! s>
AssignRhs<out Expression e, out Type ty>
/* ensures e != null || ty != null; */
-= (. Token! x; Expression! ee; Type! tt;
+= (. IToken! x; Expression! ee; Type! tt;
e = null; ty = null;
.)
( "new" TypeAndToken<out x, out tt> (. ty = tt; .)
@@ -643,8 +649,8 @@ AssignRhs<out Expression e, out Type ty>
.
HavocStmt<out Statement! s>
-= (. Token! x; Expression! lhs; .)
- "havoc" (. x = token; .)
+= (. IToken! x; Expression! lhs; .)
+ "havoc" (. x = t; .)
LhsExpr<out lhs> ";" (. s = new AssignStmt(x, lhs); .)
.
@@ -652,7 +658,7 @@ LhsExpr<out Expression! e>
= SelectExpression<out e>
.
-VarDeclStmts<List<Statement!\>! ss>
+VarDeclStmts<.List<Statement!>! ss.>
= (. VarDecl! d; bool isGhost = false; .)
[ "ghost" (. isGhost = true; .)
]
@@ -664,7 +670,7 @@ VarDeclStmts<List<Statement!\>! ss>
.
IdentTypeRhs<out VarDecl! d, bool isGhost>
-= (. Token! id; Type! ty; Expression! e;
+= (. IToken! id; Type! ty; Expression! e;
Expression rhs = null; Type newType = null;
Type optionalType = null; DeterminedAssignmentRhs optionalRhs = null;
.)
@@ -690,13 +696,13 @@ IdentTypeRhs<out VarDecl! d, bool isGhost>
.
IfStmt<out Statement! ifStmt>
-= (. Token! x;
+= (. IToken! x;
Expression guard;
Statement! thn;
Statement! s;
Statement els = null;
.)
- "if" (. x = token; .)
+ "if" (. x = t; .)
Guard<out guard>
BlockStmt<out thn>
[ "else"
@@ -708,14 +714,14 @@ IfStmt<out Statement! ifStmt>
.
WhileStmt<out Statement! stmt>
-= (. Token! x;
+= (. IToken! x;
Expression guard;
bool isFree; Expression! e;
List<MaybeFreeExpression!> invariants = new List<MaybeFreeExpression!>();
List<Expression!> decreases = new List<Expression!>();
Statement! body;
.)
- "while" (. x = token; .)
+ "while" (. x = t; .)
Guard<out guard> (. assume guard == null || Owner.None(guard); .)
{ (. isFree = false; .)
[ "free" (. isFree = true; .)
@@ -744,7 +750,7 @@ Guard<out Expression e> /* null represents demonic-choice */
MatchStmt<out Statement! s>
= (. Token x; Expression! e; MatchCaseStmt! c;
List<MatchCaseStmt!> cases = new List<MatchCaseStmt!>(); .)
- "match" (. x = token; .)
+ "match" (. x = t; .)
Expression<out e>
"{"
{ CaseStatement<out c> (. cases.Add(c); .)
@@ -754,11 +760,11 @@ MatchStmt<out Statement! s>
.
CaseStatement<out MatchCaseStmt! c>
-= (. Token! x, id, arg;
+= (. IToken! x, id, arg;
List<BoundVar!> arguments = new List<BoundVar!>();
List<Statement!> body = new List<Statement!>();
.)
- "case" (. x = token; parseVarScope.PushMarker(); .)
+ "case" (. x = t; parseVarScope.PushMarker(); .)
Ident<out id>
[ "("
Ident<out arg> (. arguments.Add(new BoundVar(arg, arg.val, new InferredTypeProxy()));
@@ -776,12 +782,12 @@ CaseStatement<out MatchCaseStmt! c>
.
CallStmt<out Statement! s>
-= (. Token! x, id;
+= (. IToken! x, id;
Expression! e;
List<IdentifierExpr!> lhs = new List<IdentifierExpr!>();
List<AutoVarDecl!> newVars = new List<AutoVarDecl!>();
.)
- "call" (. x = token; .)
+ "call" (. x = t; .)
CallStmtSubExpr<out e>
[ "," /* call a,b,c,... := ... */
@@ -829,7 +835,7 @@ CallStmt<out Statement! s>
/*------------------------------------------------------------------------*/
ForeachStmt<out Statement! s>
-= (. Token! x, boundVar;
+= (. IToken! x, boundVar;
Type! ty;
Expression! collection;
Expression! range;
@@ -837,7 +843,7 @@ ForeachStmt<out Statement! s>
AssignStmt bodyAssign = null;
.)
(. parseVarScope.PushMarker(); .)
- "foreach" (. x = token;
+ "foreach" (. x = t;
range = new LiteralExpr(x, true);
ty = new InferredTypeProxy();
.)
@@ -865,28 +871,28 @@ ForeachStmt<out Statement! s>
.
AssertStmt<out Statement! s>
-= (. Token! x; Expression! e; .)
- "assert" (. x = token; .)
+= (. IToken! x; Expression! e; .)
+ "assert" (. x = t; .)
Expression<out e> ";" (. s = new AssertStmt(x, e); .)
.
AssumeStmt<out Statement! s>
-= (. Token! x; Expression! e; .)
- "assume" (. x = token; .)
+= (. IToken! x; Expression! e; .)
+ "assume" (. x = t; .)
Expression<out e> ";" (. s = new AssumeStmt(x, e); .)
.
UseStmt<out Statement! s>
-= (. Token! x; Expression! e; .)
- "use" (. x = token; .)
+= (. IToken! x; Expression! e; .)
+ "use" (. x = t; .)
Expression<out e> ";" (. s = new UseStmt(x, e); .)
.
PrintStmt<out Statement! s>
-= (. Token! x; Attributes.Argument! arg;
+= (. IToken! x; Attributes.Argument! arg;
List<Attributes.Argument!> args = new List<Attributes.Argument!>();
.)
- "print" (. x = token; .)
+ "print" (. x = t; .)
AttributeArg<out arg> (. args.Add(arg); .)
{ "," AttributeArg<out arg> (. args.Add(arg); .)
}
@@ -895,10 +901,10 @@ PrintStmt<out Statement! s>
/*------------------------------------------------------------------------*/
Expression<out Expression! e>
-= (. Token! x; Expression! e0; Expression! e1 = dummyExpr;
+= (. IToken! x; Expression! e0; Expression! e1 = dummyExpr;
e = dummyExpr;
.)
- ( "if" (. x = token; .)
+ ( "if" (. x = t; .)
Expression<out e>
"then" Expression<out e0>
"else" Expression<out e1> (. e = new ITEExpr(x, e, e0, e1); .)
@@ -908,9 +914,9 @@ Expression<out Expression! e>
/*------------------------------------------------------------------------*/
EquivExpression<out Expression! e0>
-= (. Token! x; Expression! e1; .)
+= (. IToken! x; Expression! e1; .)
ImpliesExpression<out e0>
- { EquivOp (. x = token; .)
+ { EquivOp (. x = t; .)
ImpliesExpression<out e1> (. e0 = new BinaryExpr(x, BinaryExpr.Opcode.Iff, e0, e1); .)
}
.
@@ -919,9 +925,9 @@ EquivOp = "<==>" | '\u21d4'.
/*------------------------------------------------------------------------*/
ImpliesExpression<out Expression! e0>
-= (. Token! x; Expression! e1; .)
+= (. IToken! x; Expression! e1; .)
LogicalExpression<out e0>
- [ ImpliesOp (. x = token; .)
+ [ ImpliesOp (. x = t; .)
ImpliesExpression<out e1> (. e0 = new BinaryExpr(x, BinaryExpr.Opcode.Imp, e0, e1); .)
]
.
@@ -930,16 +936,16 @@ ImpliesOp = "==>" | '\u21d2'.
/*------------------------------------------------------------------------*/
LogicalExpression<out Expression! e0>
-= (. Token! x; Expression! e1; .)
+= (. IToken! x; Expression! e1; .)
RelationalExpression<out e0>
- [ AndOp (. x = token; .)
+ [ AndOp (. x = t; .)
RelationalExpression<out e1> (. e0 = new BinaryExpr(x, BinaryExpr.Opcode.And, e0, e1); .)
- { AndOp (. x = token; .)
+ { AndOp (. x = t; .)
RelationalExpression<out e1> (. e0 = new BinaryExpr(x, BinaryExpr.Opcode.And, e0, e1); .)
}
- | OrOp (. x = token; .)
+ | OrOp (. x = t; .)
RelationalExpression<out e1> (. e0 = new BinaryExpr(x, BinaryExpr.Opcode.Or, e0, e1); .)
- { OrOp (. x = token; .)
+ { OrOp (. x = t; .)
RelationalExpression<out e1> (. e0 = new BinaryExpr(x, BinaryExpr.Opcode.Or, e0, e1); .)
}
]
@@ -950,69 +956,69 @@ OrOp = "||" | '\u2228'.
/*------------------------------------------------------------------------*/
RelationalExpression<out Expression! e0>
-= (. Token! x; Expression! e1; BinaryExpr.Opcode op; .)
+= (. IToken! x; Expression! e1; BinaryExpr.Opcode op; .)
Term<out e0>
[ RelOp<out x, out op>
Term<out e1> (. e0 = new BinaryExpr(x, op, e0, e1); .)
]
.
-RelOp<out Token! x, out BinaryExpr.Opcode op>
+RelOp<out IToken! x, out BinaryExpr.Opcode op>
= (. x = Token.NoToken; op = BinaryExpr.Opcode.Add/*(dummy)*/; .)
- ( "==" (. x = token; op = BinaryExpr.Opcode.Eq; .)
- | "<" (. x = token; op = BinaryExpr.Opcode.Lt; .)
- | ">" (. x = token; op = BinaryExpr.Opcode.Gt; .)
- | "<=" (. x = token; op = BinaryExpr.Opcode.Le; .)
- | ">=" (. x = token; op = BinaryExpr.Opcode.Ge; .)
- | "!=" (. x = token; op = BinaryExpr.Opcode.Neq; .)
- | "!!" (. x = token; op = BinaryExpr.Opcode.Disjoint; .)
- | "in" (. x = token; op = BinaryExpr.Opcode.In; .)
- | "!in" (. x = token; op = BinaryExpr.Opcode.NotIn; .)
- | '\u2260' (. x = token; op = BinaryExpr.Opcode.Neq; .)
- | '\u2264' (. x = token; op = BinaryExpr.Opcode.Le; .)
- | '\u2265' (. x = token; op = BinaryExpr.Opcode.Ge; .)
+ ( "==" (. x = t; op = BinaryExpr.Opcode.Eq; .)
+ | "<" (. x = t; op = BinaryExpr.Opcode.Lt; .)
+ | ">" (. x = t; op = BinaryExpr.Opcode.Gt; .)
+ | "<=" (. x = t; op = BinaryExpr.Opcode.Le; .)
+ | ">=" (. x = t; op = BinaryExpr.Opcode.Ge; .)
+ | "!=" (. x = t; op = BinaryExpr.Opcode.Neq; .)
+ | "!!" (. x = t; op = BinaryExpr.Opcode.Disjoint; .)
+ | "in" (. x = t; op = BinaryExpr.Opcode.In; .)
+ | "!in" (. x = t; op = BinaryExpr.Opcode.NotIn; .)
+ | '\u2260' (. x = t; op = BinaryExpr.Opcode.Neq; .)
+ | '\u2264' (. x = t; op = BinaryExpr.Opcode.Le; .)
+ | '\u2265' (. x = t; op = BinaryExpr.Opcode.Ge; .)
)
.
/*------------------------------------------------------------------------*/
Term<out Expression! e0>
-= (. Token! x; Expression! e1; BinaryExpr.Opcode op; .)
+= (. IToken! x; Expression! e1; BinaryExpr.Opcode op; .)
Factor<out e0>
{ AddOp<out x, out op>
Factor<out e1> (. e0 = new BinaryExpr(x, op, e0, e1); .)
}
.
-AddOp<out Token! x, out BinaryExpr.Opcode op>
+AddOp<out IToken! x, out BinaryExpr.Opcode op>
= (. x = Token.NoToken; op=BinaryExpr.Opcode.Add/*(dummy)*/; .)
- ( "+" (. x = token; op = BinaryExpr.Opcode.Add; .)
- | "-" (. x = token; op = BinaryExpr.Opcode.Sub; .)
+ ( "+" (. x = t; op = BinaryExpr.Opcode.Add; .)
+ | "-" (. x = t; op = BinaryExpr.Opcode.Sub; .)
)
.
/*------------------------------------------------------------------------*/
Factor<out Expression! e0>
-= (. Token! x; Expression! e1; BinaryExpr.Opcode op; .)
+= (. IToken! x; Expression! e1; BinaryExpr.Opcode op; .)
UnaryExpression<out e0>
{ MulOp<out x, out op>
UnaryExpression<out e1> (. e0 = new BinaryExpr(x, op, e0, e1); .)
}
.
-MulOp<out Token! x, out BinaryExpr.Opcode op>
+MulOp<out IToken! x, out BinaryExpr.Opcode op>
= (. x = Token.NoToken; op = BinaryExpr.Opcode.Add/*(dummy)*/; .)
- ( "*" (. x = token; op = BinaryExpr.Opcode.Mul; .)
- | "/" (. x = token; op = BinaryExpr.Opcode.Div; .)
- | "%" (. x = token; op = BinaryExpr.Opcode.Mod; .)
+ ( "*" (. x = t; op = BinaryExpr.Opcode.Mul; .)
+ | "/" (. x = t; op = BinaryExpr.Opcode.Div; .)
+ | "%" (. x = t; op = BinaryExpr.Opcode.Mod; .)
)
.
/*------------------------------------------------------------------------*/
UnaryExpression<out Expression! e>
-= (. Token! x; e = dummyExpr; .)
- ( "-" (. x = token; .)
+= (. IToken! x; e = dummyExpr; .)
+ ( "-" (. x = t; .)
UnaryExpression<out e> (. e = new BinaryExpr(x, BinaryExpr.Opcode.Sub, new LiteralExpr(x, 0), e); .)
- | NegOp (. x = token; .)
+ | NegOp (. x = t; .)
UnaryExpression<out e> (. e = new UnaryExpr(x, UnaryExpr.Opcode.Not, e); .)
| SelectExpression<out e>
| ConstAtomExpression<out e>
@@ -1022,29 +1028,29 @@ UnaryExpression<out Expression! e>
NegOp = "!" | '\u00ac'.
ConstAtomExpression<out Expression! e>
-= (. Token! x, dtName, id; BigInteger n; List<Expression!>! elements;
+= (. IToken! x, dtName, id; BigInteger n; List<Expression!>! elements;
e = dummyExpr;
.)
- ( "false" (. e = new LiteralExpr(token, false); .)
- | "true" (. e = new LiteralExpr(token, true); .)
- | "null" (. e = new LiteralExpr(token); .)
- | Nat<out n> (. e = new LiteralExpr(token, n); .)
- | "#" (. x = token; .)
+ ( "false" (. e = new LiteralExpr(t, false); .)
+ | "true" (. e = new LiteralExpr(t, true); .)
+ | "null" (. e = new LiteralExpr(t); .)
+ | Nat<out n> (. e = new LiteralExpr(t, n); .)
+ | "#" (. x = t; .)
Ident<out dtName>
"."
Ident<out id> (. elements = new List<Expression!>(); .)
[ "("
[ Expressions<elements> ]
- ")" ] (. e = new DatatypeValue(token, dtName.val, id.val, elements); .)
- | "fresh" (. x = token; .)
+ ")" ] (. e = new DatatypeValue(t, dtName.val, id.val, elements); .)
+ | "fresh" (. x = t; .)
"(" Expression<out e> ")" (. e = new FreshExpr(x, e); .)
- | "|" (. x = token; .)
+ | "|" (. x = t; .)
Expression<out e> (. e = new UnaryExpr(x, UnaryExpr.Opcode.SeqLength, e); .)
"|"
- | "{" (. x = token; elements = new List<Expression!>(); .)
+ | "{" (. x = t; elements = new List<Expression!>(); .)
[ Expressions<elements> ] (. e = new SetDisplayExpr(x, elements); .)
"}"
- | "[" (. x = token; elements = new List<Expression!>(); .)
+ | "[" (. x = t; elements = new List<Expression!>(); .)
[ Expressions<elements> ] (. e = new SeqDisplayExpr(x, elements); .)
"]"
)
@@ -1067,7 +1073,7 @@ CallStmtSubExpr<out Expression! e>
.
SelectExpression<out Expression! e>
-= (. Token! id; e = dummyExpr; .)
+= (. IToken! id; e = dummyExpr; .)
( IdentOrFuncExpression<out e>
| ObjectExpression<out e>
)
@@ -1075,7 +1081,7 @@ SelectExpression<out Expression! e>
.
IdentOrFuncExpression<out Expression! e>
-= (. Token! id; e = dummyExpr; List<Expression!>! args; .)
+= (. IToken! id; e = dummyExpr; List<Expression!>! args; .)
Ident<out id>
[ "(" (. args = new List<Expression!>(); .)
[ Expressions<args> ]
@@ -1091,7 +1097,7 @@ IdentOrFuncExpression<out Expression! e>
.
SelectOrCallSuffix<ref Expression! e>
-= (. Token! id, x; List<Expression!>! args;
+= (. IToken! id, x; List<Expression!>! args;
Expression e0 = null; Expression e1 = null; Expression! ee; bool anyDots = false;
bool func = false;
.)
@@ -1102,7 +1108,7 @@ SelectOrCallSuffix<ref Expression! e>
")" (. e = new FunctionCallExpr(id, id.val, e, args); .)
] (. if (!func) { e = new FieldSelectExpr(id, e, id.val); } .)
- | "[" (. x = token; .)
+ | "[" (. x = t; .)
( Expression<out ee> (. e0 = ee; .)
[ ".." (. anyDots = true; .)
[ Expression<out ee> (. e1 = ee; .)
@@ -1136,9 +1142,9 @@ SelectOrCallSuffix<ref Expression! e>
parsed here. The expression returned is never an lvalue.
*/
ObjectExpression<out Expression! e>
-= (. Token! x; e = dummyExpr; .)
- ( "this" (. e = new ThisExpr(token); .)
- | "old" (. x = token; .)
+= (. IToken! x; e = dummyExpr; .)
+ ( "this" (. e = new ThisExpr(t); .)
+ | "old" (. x = t; .)
"("
Expression<out e>
")" (. e = new OldExpr(x, e); .)
@@ -1152,17 +1158,17 @@ ObjectExpression<out Expression! e>
/*------------------------------------------------------------------------*/
QuantifierGuts<out Expression! q>
-= (. Token! x = Token.NoToken;
+= (. IToken! x = Token.NoToken;
bool univ = false;
BoundVar! bv;
List<BoundVar!> bvars = new List<BoundVar!>();
- Token! tok; Expr! e; ExprSeq! es;
+ IToken! tok; Expr! e; ExprSeq! es;
Attributes attrs = null;
Triggers trigs = null;
Expression! body;
.)
- ( Forall (. x = token; univ = true; .)
- | Exists (. x = token; .)
+ ( Forall (. x = t; univ = true; .)
+ | Exists (. x = t; .)
)
(. parseVarScope.PushMarker(); .)
IdentTypeOptional<out bv> (. bvars.Add(bv); parseVarScope.Push(bv.Name, bv.Name); .)
@@ -1185,7 +1191,7 @@ Forall = "forall" | '\u2200'.
Exists = "exists" | '\u2203'.
QSep = "::" | '\u2022'.
-Expressions<List<Expression!\>! args>
+Expressions<.List<Expression!>! args.>
= (. Expression! e; .)
Expression<out e> (. args.Add(e); .)
{ "," Expression<out e> (. args.Add(e); .)
@@ -1205,7 +1211,7 @@ AttributeBody<ref Attributes attrs>
List<Attributes.Argument!> aArgs = new List<Attributes.Argument!>();
Attributes.Argument! aArg;
.)
- ":" ident (. aName = token.val; .)
+ ":" ident (. aName = t.val; .)
[ AttributeArg<out aArg> (. aArgs.Add(aArg); .)
{ "," AttributeArg<out aArg> (. aArgs.Add(aArg); .)
}
@@ -1214,7 +1220,7 @@ AttributeBody<ref Attributes attrs>
AttributeArg<out Attributes.Argument! arg>
= (. Expression! e; arg = dummyAttrArg; .)
- ( string (. arg = new Attributes.Argument(token.val.Substring(1, token.val.Length-2)); .)
+ ( string (. arg = new Attributes.Argument(t.val.Substring(1, t.val.Length-2)); .)
| Expression<out e> (. arg = new Attributes.Argument(e); .)
)
.
@@ -1232,23 +1238,23 @@ AttributeOrTrigger<ref Attributes attrs, ref Triggers trigs>
/*------------------------------------------------------------------------*/
-Idents<List<string!\>! ids>
-= (. Token! id; .)
+Idents<.List<string!>! ids.>
+= (. IToken! id; .)
Ident<out id> (. ids.Add(id.val); .)
{ "," Ident<out id> (. ids.Add(id.val); .)
}
.
-Ident<out Token! x>
+Ident<out IToken! x>
=
- ident (. x = token; .)
+ ident (. x = t; .)
.
Nat<out BigInteger n>
=
digits
(. try {
- n = BigInteger.Parse(token.val);
+ n = BigInteger.Parse(t.val);
} catch (System.FormatException) {
SemErr("incorrectly formatted number");
n = BigInteger.Zero;
diff --git a/Source/Dafny/DafnyAst.ssc b/Source/Dafny/DafnyAst.ssc
index a8a93067..1d9dfd1c 100644
--- a/Source/Dafny/DafnyAst.ssc
+++ b/Source/Dafny/DafnyAst.ssc
@@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using Microsoft.Contracts;
using System.Numerics;
+using Microsoft.Boogie;
namespace Microsoft.Dafny
{
@@ -148,14 +149,14 @@ namespace Microsoft.Dafny
}
public class UserDefinedType : Type {
- public readonly Token! tok;
+ public readonly IToken! tok;
public readonly string! Name;
[Rep] public readonly List<Type!>! TypeArgs;
public TopLevelDecl ResolvedClass; // filled in by resolution, if Name denotes a class/datatype and TypeArgs match the type parameters of that class/datatype
public TypeParameter ResolvedParam; // filled in by resolution, if Name denotes an enclosing type parameter and TypeArgs is the empty list
- public static UserDefinedType! ArrayType(Token! tok, Type! arg) {
+ public static UserDefinedType! ArrayType(IToken! tok, Type! arg) {
List<Type!> typeArgs = new List<Type!>();
typeArgs.Add(arg);
UserDefinedType udt = new UserDefinedType(tok, "array", typeArgs);
@@ -171,7 +172,7 @@ namespace Microsoft.Dafny
}
- public UserDefinedType(Token! tok, string! name, [Captured] List<Type!>! typeArgs) {
+ public UserDefinedType(IToken! tok, string! name, [Captured] List<Type!>! typeArgs) {
this.tok = tok;
this.Name = name;
this.TypeArgs = typeArgs;
@@ -180,7 +181,7 @@ namespace Microsoft.Dafny
/// <summary>
/// This constructor constructs a resolved class type
/// </summary>
- public UserDefinedType(Token! tok, string! name, TopLevelDecl! cd, [Captured] List<Type!>! typeArgs) {
+ public UserDefinedType(IToken! tok, string! name, TopLevelDecl! cd, [Captured] List<Type!>! typeArgs) {
this.tok = tok;
this.Name = name;
this.TypeArgs = typeArgs;
@@ -190,7 +191,7 @@ namespace Microsoft.Dafny
/// <summary>
/// This constructor constructs a resolved type parameter
/// </summary>
- public UserDefinedType(Token! tok, string! name, TypeParameter! tp) {
+ public UserDefinedType(IToken! tok, string! name, TypeParameter! tp) {
this.tok = tok;
this.Name = name;
this.TypeArgs = new List<Type!>();
@@ -350,11 +351,11 @@ namespace Microsoft.Dafny
// ------------------------------------------------------------------------------------------------------
public abstract class Declaration {
- public Token! tok;
+ public IToken! tok;
public readonly string! Name;
public readonly Attributes Attributes;
- public Declaration(Token! tok, string! name, Attributes attributes) {
+ public Declaration(IToken! tok, string! name, Attributes attributes) {
this.tok = tok;
this.Name = name;
this.Attributes = attributes;
@@ -386,7 +387,7 @@ namespace Microsoft.Dafny
parent = value;
}
}
- public TypeParameter(Token! tok, string! name) {
+ public TypeParameter(IToken! tok, string! name) {
base(tok, name, null);
}
}
@@ -396,7 +397,7 @@ namespace Microsoft.Dafny
public readonly List<TopLevelDecl!>! TopLevelDecls = new List<TopLevelDecl!>(); // filled in by the parser; readonly after that
public readonly Graph<MemberDecl!>! CallGraph = new Graph<MemberDecl!>(); // filled in during resolution
public int Height; // height in the topological sorting of modules; filled in during resolution
- public ModuleDecl(Token! tok, string! name, [Captured] List<string!>! imports, Attributes attributes) {
+ public ModuleDecl(IToken! tok, string! name, [Captured] List<string!>! imports, Attributes attributes) {
Imports = imports;
base(tok, name, attributes);
}
@@ -418,7 +419,7 @@ namespace Microsoft.Dafny
public readonly ModuleDecl! Module;
public readonly List<TypeParameter!>! TypeArgs;
- public TopLevelDecl(Token! tok, string! name, ModuleDecl! module, List<TypeParameter!>! typeArgs, Attributes attributes) {
+ public TopLevelDecl(IToken! tok, string! name, ModuleDecl! module, List<TypeParameter!>! typeArgs, Attributes attributes) {
Module = module;
TypeArgs = typeArgs;
base(tok, name, attributes);
@@ -428,7 +429,7 @@ namespace Microsoft.Dafny
public class ClassDecl : TopLevelDecl {
public readonly List<MemberDecl!>! Members;
- public ClassDecl(Token! tok, string! name, ModuleDecl! module, List<TypeParameter!>! typeArgs, [Captured] List<MemberDecl!>! members, Attributes attributes) {
+ public ClassDecl(IToken! tok, string! name, ModuleDecl! module, List<TypeParameter!>! typeArgs, [Captured] List<MemberDecl!>! members, Attributes attributes) {
Members = members;
base(tok, name, module, typeArgs, attributes);
}
@@ -450,7 +451,7 @@ namespace Microsoft.Dafny
public readonly List<DatatypeCtor!>! Ctors;
public DatatypeCtor DefaultCtor; // set during resolution
- public DatatypeDecl(Token! tok, string! name, ModuleDecl! module, List<TypeParameter!>! typeArgs, [Captured] List<DatatypeCtor!>! ctors, Attributes attributes) {
+ public DatatypeDecl(IToken! tok, string! name, ModuleDecl! module, List<TypeParameter!>! typeArgs, [Captured] List<DatatypeCtor!>! ctors, Attributes attributes) {
Ctors = ctors;
base(tok, name, module, typeArgs, attributes);
}
@@ -462,7 +463,7 @@ namespace Microsoft.Dafny
// Todo: One could imagine having a precondition on datatype constructors
public DatatypeDecl EnclosingDatatype; // filled in during resolution
- public DatatypeCtor(Token! tok, string! name, [Captured] List<TypeParameter!>! typeArgs, [Captured] List<Formal!>! formals,
+ public DatatypeCtor(IToken! tok, string! name, [Captured] List<TypeParameter!>! typeArgs, [Captured] List<Formal!>! formals,
Attributes attributes) {
this.TypeArgs = typeArgs;
this.Formals = formals;
@@ -481,7 +482,7 @@ namespace Microsoft.Dafny
public abstract class MemberDecl : Declaration {
public ClassDecl EnclosingClass; // filled in during resolution
- public MemberDecl(Token! tok, string! name, Attributes attributes) {
+ public MemberDecl(IToken! tok, string! name, Attributes attributes) {
base(tok, name, attributes);
}
/// <summary>
@@ -500,7 +501,7 @@ namespace Microsoft.Dafny
public readonly bool IsGhost;
public readonly Type! Type;
- public Field(Token! tok, string! name, bool isGhost, Type! type, Attributes attributes) {
+ public Field(IToken! tok, string! name, bool isGhost, Type! type, Attributes attributes) {
IsGhost = isGhost;
Type = type;
base(tok, name, attributes);
@@ -516,7 +517,7 @@ namespace Microsoft.Dafny
}
public abstract class NonglobalVariable : IVariable {
- public readonly Token! tok;
+ public readonly IToken! tok;
readonly string! name;
public string! Name { get { return name; } }
readonly int varId = varIdCount++;
@@ -544,7 +545,7 @@ namespace Microsoft.Dafny
set { isGhost = value; }
}
- public NonglobalVariable(Token! tok, string! name, Type! type, bool isGhost) {
+ public NonglobalVariable(IToken! tok, string! name, Type! type, bool isGhost) {
this.tok = tok;
this.name = name;
this.type = type;
@@ -558,7 +559,7 @@ namespace Microsoft.Dafny
public readonly bool InParam; // true to in-parameter, false for out-parameter
public override bool IsMutable { get { return !InParam; } }
- public Formal(Token! tok, string! name, Type! type, bool inParam, bool isGhost) {
+ public Formal(IToken! tok, string! name, Type! type, bool inParam, bool isGhost) {
InParam = inParam;
base(tok, name, type, isGhost);
}
@@ -567,7 +568,7 @@ namespace Microsoft.Dafny
public class BoundVar : NonglobalVariable {
public override bool IsMutable { get { return false; } }
- public BoundVar(Token! tok, string! name, Type! type) {
+ public BoundVar(IToken! tok, string! name, Type! type) {
base(tok, name, type, false);
}
}
@@ -585,7 +586,7 @@ namespace Microsoft.Dafny
public readonly List<Expression!>! Decreases;
public readonly Expression Body; // an extended expression
- public Function(Token! tok, string! name, bool isStatic, bool isGhost, bool isUnlimited, [Captured] List<TypeParameter!>! typeArgs, [Captured] List<Formal!>! formals, Type! resultType,
+ public Function(IToken! tok, string! name, bool isStatic, bool isGhost, bool isUnlimited, [Captured] List<TypeParameter!>! typeArgs, [Captured] List<Formal!>! formals, Type! resultType,
List<Expression!>! req, List<FrameExpression!>! reads, List<Expression!>! decreases, Expression body, Attributes attributes) {
this.IsStatic = isStatic;
this.IsGhost = isGhost;
@@ -613,7 +614,7 @@ namespace Microsoft.Dafny
public readonly List<Expression!>! Decreases;
public readonly BlockStmt Body;
- public Method(Token! tok, string! name,
+ public Method(IToken! tok, string! name,
bool isStatic, bool isGhost,
[Captured] List<TypeParameter!>! typeArgs,
[Captured] List<Formal!>! ins, [Captured] List<Formal!>! outs,
@@ -638,9 +639,9 @@ namespace Microsoft.Dafny
// ------------------------------------------------------------------------------------------------------
public abstract class Statement {
- public readonly Token! Tok;
+ public readonly IToken! Tok;
public bool IsGhost; // filled in by resolution
- public Statement(Token! tok) {
+ public Statement(IToken! tok) {
this.Tok = tok;
}
}
@@ -648,7 +649,7 @@ namespace Microsoft.Dafny
public abstract class PredicateStmt : Statement {
[Peer] public readonly Expression! Expr;
[Captured]
- public PredicateStmt(Token! tok, Expression! expr)
+ public PredicateStmt(IToken! tok, Expression! expr)
ensures Owner.Same(this, expr);
{
base(tok);
@@ -659,7 +660,7 @@ namespace Microsoft.Dafny
public class AssertStmt : PredicateStmt {
[Captured]
- public AssertStmt(Token! tok, Expression! expr)
+ public AssertStmt(IToken! tok, Expression! expr)
ensures Owner.Same(this, expr);
{
base(tok, expr);
@@ -668,7 +669,7 @@ namespace Microsoft.Dafny
public class AssumeStmt : PredicateStmt {
[Captured]
- public AssumeStmt(Token! tok, Expression! expr)
+ public AssumeStmt(IToken! tok, Expression! expr)
ensures Owner.Same(this, expr);
{
base(tok, expr);
@@ -677,7 +678,7 @@ namespace Microsoft.Dafny
public class UseStmt : PredicateStmt {
[Captured]
- public UseStmt(Token! tok, Expression! expr)
+ public UseStmt(IToken! tok, Expression! expr)
ensures Owner.Same(this, expr);
{
base(tok, expr);
@@ -715,7 +716,7 @@ namespace Microsoft.Dafny
public class PrintStmt : Statement {
public readonly List<Attributes.Argument!>! Args;
- public PrintStmt(Token! tok, List<Attributes.Argument!>! args)
+ public PrintStmt(IToken! tok, List<Attributes.Argument!>! args)
{
base(tok);
Args = args;
@@ -724,7 +725,7 @@ namespace Microsoft.Dafny
public class LabelStmt : Statement {
public readonly string! Label;
- public LabelStmt(Token! tok, string! label) {
+ public LabelStmt(IToken! tok, string! label) {
this.Label = label;
base(tok);
}
@@ -734,14 +735,14 @@ namespace Microsoft.Dafny
public readonly string TargetLabel;
public Statement TargetStmt; // filled in during resolution
- public BreakStmt(Token! tok, string targetLabel) {
+ public BreakStmt(IToken! tok, string targetLabel) {
this.TargetLabel = targetLabel;
base(tok);
}
}
public class ReturnStmt : Statement {
- public ReturnStmt(Token! tok) {
+ public ReturnStmt(IToken! tok) {
base(tok);
}
}
@@ -779,22 +780,22 @@ namespace Microsoft.Dafny
public class AssignStmt : Statement {
public readonly Expression! Lhs;
public readonly AssignmentRhs! Rhs;
- public AssignStmt(Token! tok, Expression! lhs, Expression! rhs) { // ordinary assignment statement
+ public AssignStmt(IToken! tok, Expression! lhs, Expression! rhs) { // ordinary assignment statement
this.Lhs = lhs;
this.Rhs = new ExprRhs(rhs);
base(tok);
}
- public AssignStmt(Token! tok, Expression! lhs, Type! type) { // alloc statement
+ public AssignStmt(IToken! tok, Expression! lhs, Type! type) { // alloc statement
this.Lhs = lhs;
this.Rhs = new TypeRhs(type);
base(tok);
}
- public AssignStmt(Token! tok, Expression! lhs, Type! type, Expression! arraySize) { // array alloc statement
+ public AssignStmt(IToken! tok, Expression! lhs, Type! type, Expression! arraySize) { // array alloc statement
this.Lhs = lhs;
this.Rhs = new TypeRhs(type, arraySize);
base(tok);
}
- public AssignStmt(Token! tok, Expression! lhs) { // havoc
+ public AssignStmt(IToken! tok, Expression! lhs) { // havoc
this.Lhs = lhs;
this.Rhs = new HavocRhs();
base(tok);
@@ -830,7 +831,7 @@ namespace Microsoft.Dafny
public readonly DeterminedAssignmentRhs Rhs;
invariant OptionalType != null || Rhs != null;
- public VarDecl(Token! tok, string! name, Type type, bool isGhost, DeterminedAssignmentRhs rhs)
+ public VarDecl(IToken! tok, string! name, Type type, bool isGhost, DeterminedAssignmentRhs rhs)
requires type != null || rhs != null;
{
this.name = name;
@@ -843,7 +844,7 @@ namespace Microsoft.Dafny
public class AutoVarDecl : VarDecl {
public readonly int Index;
- public AutoVarDecl(Token! tok, string! name, Type! type, int index)
+ public AutoVarDecl(IToken! tok, string! name, Type! type, int index)
{
Index = index;
base(tok, name, type, false, null);
@@ -864,7 +865,7 @@ namespace Microsoft.Dafny
public readonly List<Expression!>! Args;
public Method Method; // filled in by resolution
- public CallStmt(Token! tok, List<AutoVarDecl!>! newVars, List<IdentifierExpr!>! lhs, Expression! receiver, string! methodName, List<Expression!>! args) {
+ public CallStmt(IToken! tok, List<AutoVarDecl!>! newVars, List<IdentifierExpr!>! lhs, Expression! receiver, string! methodName, List<Expression!>! args) {
this.NewVars = newVars;
this.Lhs = lhs;
this.Receiver = receiver;
@@ -876,7 +877,7 @@ namespace Microsoft.Dafny
public class BlockStmt : Statement {
public readonly List<Statement!>! Body;
- public BlockStmt(Token! tok, [Captured] List<Statement!>! body) {
+ public BlockStmt(IToken! tok, [Captured] List<Statement!>! body) {
this.Body = body;
base(tok);
}
@@ -888,7 +889,7 @@ namespace Microsoft.Dafny
public readonly Statement Els;
invariant Els == null || Els is BlockStmt || Els is IfStmt;
- public IfStmt(Token! tok, Expression guard, Statement! thn, Statement els)
+ public IfStmt(IToken! tok, Expression guard, Statement! thn, Statement els)
requires els == null || els is BlockStmt || els is IfStmt;
{
this.Guard = guard;
@@ -904,7 +905,7 @@ namespace Microsoft.Dafny
public readonly List<Expression!>! Decreases;
public readonly Statement! Body;
- public WhileStmt(Token! tok, Expression guard,
+ public WhileStmt(IToken! tok, Expression guard,
List<MaybeFreeExpression!>! invariants, List<Expression!>! decreases,
Statement! body) {
this.Guard = guard;
@@ -922,7 +923,7 @@ namespace Microsoft.Dafny
public readonly List<PredicateStmt!>! BodyPrefix;
public readonly AssignStmt! BodyAssign;
- public ForeachStmt(Token! tok, BoundVar! boundVar, Expression! collection, Expression! range, List<PredicateStmt!>! bodyPrefix, AssignStmt! bodyAssign) {
+ public ForeachStmt(IToken! tok, BoundVar! boundVar, Expression! collection, Expression! range, List<PredicateStmt!>! bodyPrefix, AssignStmt! bodyAssign) {
this.BoundVar = boundVar;
this.Collection = collection;
this.Range = range;
@@ -936,7 +937,7 @@ namespace Microsoft.Dafny
public readonly Expression! Source;
public readonly List<MatchCaseStmt!>! Cases;
- public MatchStmt(Token! tok, Expression! source, [Captured] List<MatchCaseStmt!>! cases) {
+ public MatchStmt(IToken! tok, Expression! source, [Captured] List<MatchCaseStmt!>! cases) {
this.Source = source;
this.Cases = cases;
base(tok);
@@ -944,13 +945,13 @@ namespace Microsoft.Dafny
}
public class MatchCaseStmt {
- public readonly Token! tok;
+ public readonly IToken! tok;
public readonly string! Id;
public DatatypeCtor Ctor; // filled in by resolution
public readonly List<BoundVar!>! Arguments;
public readonly List<Statement!>! Body;
- public MatchCaseStmt(Token! tok, string! id, [Captured] List<BoundVar!>! arguments, [Captured] List<Statement!>! body) {
+ public MatchCaseStmt(IToken! tok, string! id, [Captured] List<BoundVar!>! arguments, [Captured] List<Statement!>! body) {
this.tok = tok;
this.Id = id;
this.Arguments = arguments;
@@ -961,7 +962,7 @@ namespace Microsoft.Dafny
// ------------------------------------------------------------------------------------------------------
public abstract class Expression {
- public readonly Token! tok;
+ public readonly IToken! tok;
protected Type type;
public Type Type { // filled in during resolution
[Verify(false)] // TODO: how do we allow Type.get to modify type and still be [Pure]?
@@ -998,7 +999,7 @@ namespace Microsoft.Dafny
}
}
- public Expression(Token! tok)
+ public Expression(IToken! tok)
ensures type == null; // we would have liked to have written Type==null, but that's not admissible or provable
{
this.tok = tok;
@@ -1017,25 +1018,25 @@ namespace Microsoft.Dafny
}
}
- public LiteralExpr(Token! tok) { // represents the Dafny literal "null"
+ public LiteralExpr(IToken! tok) { // represents the Dafny literal "null"
this.Value = null;
base(tok);
}
- public LiteralExpr(Token! tok, BigInteger n)
+ public LiteralExpr(IToken! tok, BigInteger n)
requires 0 <= n.Sign;
{
this.Value = n;
base(tok);
}
- public LiteralExpr(Token! tok, int n)
+ public LiteralExpr(IToken! tok, int n)
requires 0 <= n;
{
this(tok, new BigInteger(n));
}
- public LiteralExpr(Token! tok, bool b) {
+ public LiteralExpr(IToken! tok, bool b) {
this.Value = b;
base(tok);
}
@@ -1048,7 +1049,7 @@ namespace Microsoft.Dafny
public DatatypeCtor Ctor; // filled in by resolution
public List<Type!>! InferredTypeArgs = new List<Type!>(); // filled in by resolution
- public DatatypeValue(Token! tok, string! datatypeName, string! memberName, [Captured] List<Expression!>! arguments) {
+ public DatatypeValue(IToken! tok, string! datatypeName, string! memberName, [Captured] List<Expression!>! arguments) {
this.DatatypeName = datatypeName;
this.MemberName = memberName;
this.Arguments = arguments;
@@ -1057,13 +1058,13 @@ namespace Microsoft.Dafny
}
public class ThisExpr : Expression {
- public ThisExpr(Token! tok) {
+ public ThisExpr(IToken! tok) {
base(tok);
}
}
public class ImplicitThisExpr : ThisExpr {
- public ImplicitThisExpr(Token! tok) {
+ public ImplicitThisExpr(IToken! tok) {
base(tok);
}
}
@@ -1072,7 +1073,7 @@ namespace Microsoft.Dafny
public readonly string! Name;
public IVariable Var; // filled in by resolution
- public IdentifierExpr(Token! tok, string! name) {
+ public IdentifierExpr(IToken! tok, string! name) {
Name = name;
base(tok);
}
@@ -1080,20 +1081,20 @@ namespace Microsoft.Dafny
public abstract class DisplayExpression : Expression {
public readonly List<Expression!>! Elements;
- public DisplayExpression(Token! tok, List<Expression!>! elements) {
+ public DisplayExpression(IToken! tok, List<Expression!>! elements) {
Elements = elements;
base(tok);
}
}
public class SetDisplayExpr : DisplayExpression {
- public SetDisplayExpr(Token! tok, List<Expression!>! elements) {
+ public SetDisplayExpr(IToken! tok, List<Expression!>! elements) {
base(tok, elements);
}
}
public class SeqDisplayExpr : DisplayExpression {
- public SeqDisplayExpr(Token! tok, List<Expression!>! elements) {
+ public SeqDisplayExpr(IToken! tok, List<Expression!>! elements) {
base(tok, elements);
}
}
@@ -1103,7 +1104,7 @@ namespace Microsoft.Dafny
public readonly string! FieldName;
public Field Field; // filled in by resolution
- public FieldSelectExpr(Token! tok, Expression! obj, string! fieldName) {
+ public FieldSelectExpr(IToken! tok, Expression! obj, string! fieldName) {
this.Obj = obj;
this.FieldName = fieldName;
base(tok);
@@ -1118,7 +1119,7 @@ namespace Microsoft.Dafny
invariant SelectOne ==> E1 == null;
invariant E0 != null || E1 != null;
- public SeqSelectExpr(Token! tok, bool selectOne, Expression! seq, Expression e0, Expression e1)
+ public SeqSelectExpr(IToken! tok, bool selectOne, Expression! seq, Expression e0, Expression e1)
requires selectOne ==> e1 == null;
requires e0 != null || e1 != null;
{
@@ -1135,7 +1136,7 @@ namespace Microsoft.Dafny
public readonly Expression! Index;
public readonly Expression! Value;
- public SeqUpdateExpr(Token! tok, Expression! seq, Expression! index, Expression! val)
+ public SeqUpdateExpr(IToken! tok, Expression! seq, Expression! index, Expression! val)
{
Seq = seq;
Index = index;
@@ -1151,7 +1152,7 @@ namespace Microsoft.Dafny
public Function Function; // filled in by resolution
[Captured]
- public FunctionCallExpr(Token! tok, string! fn, Expression! receiver, [Captured] List<Expression!>! args)
+ public FunctionCallExpr(IToken! tok, string! fn, Expression! receiver, [Captured] List<Expression!>! args)
ensures type == null;
ensures Owner.Same(this, receiver);
{
@@ -1166,7 +1167,7 @@ namespace Microsoft.Dafny
public class OldExpr : Expression {
[Peer] public readonly Expression! E;
[Captured]
- public OldExpr(Token! tok, Expression! expr) {
+ public OldExpr(IToken! tok, Expression! expr) {
base(tok);
Owner.AssignSame(this, expr);
E = expr;
@@ -1175,7 +1176,7 @@ namespace Microsoft.Dafny
public class FreshExpr : Expression {
public readonly Expression! E;
- public FreshExpr(Token! tok, Expression! expr) {
+ public FreshExpr(IToken! tok, Expression! expr) {
E = expr;
base(tok);
}
@@ -1186,7 +1187,7 @@ namespace Microsoft.Dafny
public readonly Opcode Op;
public readonly Expression! E;
- public UnaryExpr(Token! tok, Opcode op, Expression! e) {
+ public UnaryExpr(IToken! tok, Opcode op, Expression! e) {
this.Op = op;
this.E = e;
base(tok);
@@ -1243,7 +1244,7 @@ namespace Microsoft.Dafny
public readonly Expression! E0;
public readonly Expression! E1;
- public BinaryExpr(Token! tok, Opcode op, Expression! e0, Expression! e1) {
+ public BinaryExpr(IToken! tok, Opcode op, Expression! e0, Expression! e1) {
this.Op = op;
this.E0 = e0;
this.E1 = e1;
@@ -1257,7 +1258,7 @@ namespace Microsoft.Dafny
public readonly Triggers Trigs;
public readonly Attributes Attributes;
- public QuantifierExpr(Token! tok, List<BoundVar!>! bvars, Expression! body, Triggers trigs, Attributes attrs) {
+ public QuantifierExpr(IToken! tok, List<BoundVar!>! bvars, Expression! body, Triggers trigs, Attributes attrs) {
this.BoundVars = bvars;
this.Body = body;
this.Trigs = trigs;
@@ -1277,19 +1278,19 @@ namespace Microsoft.Dafny
}
public class ForallExpr : QuantifierExpr {
- public ForallExpr(Token! tok, List<BoundVar!>! bvars, Expression! body, Triggers trig, Attributes attrs) {
+ public ForallExpr(IToken! tok, List<BoundVar!>! bvars, Expression! body, Triggers trig, Attributes attrs) {
base(tok, bvars, body, trig, attrs);
}
}
public class ExistsExpr : QuantifierExpr {
- public ExistsExpr(Token! tok, List<BoundVar!>! bvars, Expression! body, Triggers trig, Attributes attrs) {
+ public ExistsExpr(IToken! tok, List<BoundVar!>! bvars, Expression! body, Triggers trig, Attributes attrs) {
base(tok, bvars, body, trig, attrs);
}
}
public class WildcardExpr : Expression { // a WildcardExpr can occur only in reads clauses and a loop's decreases clauses (with different meanings)
- public WildcardExpr(Token! tok) {
+ public WildcardExpr(IToken! tok) {
base(tok);
}
}
@@ -1299,7 +1300,7 @@ namespace Microsoft.Dafny
public readonly Expression! Thn;
public readonly Expression! Els;
- public ITEExpr(Token! tok, Expression! test, Expression! thn, Expression! els) {
+ public ITEExpr(IToken! tok, Expression! test, Expression! thn, Expression! els) {
this.Test = test;
this.Thn = thn;
this.Els = els;
@@ -1311,7 +1312,7 @@ namespace Microsoft.Dafny
public readonly Expression! Source;
public readonly List<MatchCaseExpr!>! Cases;
- public MatchExpr(Token! tok, Expression! source, [Captured] List<MatchCaseExpr!>! cases) {
+ public MatchExpr(IToken! tok, Expression! source, [Captured] List<MatchCaseExpr!>! cases) {
this.Source = source;
this.Cases = cases;
base(tok);
@@ -1319,13 +1320,13 @@ namespace Microsoft.Dafny
}
public class MatchCaseExpr {
- public readonly Token! tok;
+ public readonly IToken! tok;
public readonly string! Id;
public DatatypeCtor Ctor; // filled in by resolution
public readonly List<BoundVar!>! Arguments;
public readonly Expression! Body;
- public MatchCaseExpr(Token! tok, string! id, [Captured] List<BoundVar!>! arguments, Expression! body) {
+ public MatchCaseExpr(IToken! tok, string! id, [Captured] List<BoundVar!>! arguments, Expression! body) {
this.tok = tok;
this.Id = id;
this.Arguments = arguments;
diff --git a/Source/Dafny/DafnyMain.ssc b/Source/Dafny/DafnyMain.ssc
index a7d863fe..21375145 100644
--- a/Source/Dafny/DafnyMain.ssc
+++ b/Source/Dafny/DafnyMain.ssc
@@ -18,7 +18,6 @@ namespace Microsoft.Dafny {
modifies Bpl.CommandLineOptions.Clo.XmlSink.*;
{
program = null;
- Dafny.Errors.count = 0;
List<ModuleDecl!> modules = new List<ModuleDecl!>();
foreach (string! dafnyFileName in fileNames){
if (Bpl.CommandLineOptions.Clo.XmlSink != null && Bpl.CommandLineOptions.Clo.XmlSink.IsOpen) {
@@ -35,7 +34,7 @@ namespace Microsoft.Dafny {
errorCount = Dafny.Parser.Parse(dafnyFileName, modules);
if (errorCount != 0)
{
- return string.Format("{0} parse errors detected in {1}", Dafny.Errors.count, dafnyFileName);
+ return string.Format("{0} parse errors detected in {1}", errorCount, dafnyFileName);
}
}
catch (IOException e)
diff --git a/Source/Dafny/Makefile b/Source/Dafny/Makefile
index fd2141b3..e545fbae 100644
--- a/Source/Dafny/Makefile
+++ b/Source/Dafny/Makefile
@@ -1,13 +1,18 @@
COCO = ..\..\Binaries\Coco.exe
ASML = ..\..\Binaries\asmlc.boot.exe
+# ###############################################################################
+# The frame files are no longer in this directory. They must be downloaded
+# from http://boogiepartners.codeplex.com/ and then copied into this directory.
+# ###############################################################################
+
# "all" depends on 2 files, really (Parser.cs and Scanner.cs), but they
# are both generated in one go and I don't know a better way to tell
# nmake that. --KRML
all: Parser.ssc
Parser.ssc: Scanner.frame Parser.frame Dafny.atg
- $(COCO) Dafny.atg
+ $(COCO) Dafny.atg -namespace Microsoft.Dafny
copy Parser.cs Parser.ssc
copy Scanner.cs Scanner.ssc
diff --git a/Source/Dafny/Parser.ssc b/Source/Dafny/Parser.ssc
index 3752fd33..0f85bbe8 100644
--- a/Source/Dafny/Parser.ssc
+++ b/Source/Dafny/Parser.ssc
@@ -1,22 +1,38 @@
using System.Collections.Generic;
using System.Numerics;
using Microsoft.Boogie;
+using System.IO;
+using System.Text;
+
+
+
+
+using System;
using Microsoft.Contracts;
namespace Microsoft.Dafny {
+
+
public class Parser {
- const int maxT = 100;
+ public const int _EOF = 0;
+ public const int _ident = 1;
+ public const int _digits = 2;
+ public const int _string = 3;
+ public const int maxT = 100;
const bool T = true;
const bool x = false;
const int minErrDist = 2;
- static Token/*!*/ token; // last recognized token
- static Token/*!*/ t; // lookahead token
- static int errDist = minErrDist;
+ public Scanner/*!*/ scanner;
+ public Errors/*!*/ errors;
- static List<ModuleDecl!>! theModules = new List<ModuleDecl!>();
+ public Token/*!*/ t; // last recognized token
+ public Token/*!*/ la; // lookahead token
+ int errDist = minErrDist;
+
+static List<ModuleDecl!>! theModules = new List<ModuleDecl!>();
static Expression! dummyExpr = new LiteralExpr(Token.NoToken);
@@ -62,15 +78,14 @@ private static Expression! ConvertToLocal(Expression! e)
/// Note: first initialize the Scanner.
///</summary>
public static int Parse (string! filename, List<ModuleDecl!>! modules) /* throws System.IO.IOException */ {
+ string s;
if (filename == "stdin.dfy") {
- BoogiePL.Buffer.Fill(System.Console.In);
- Scanner.Init(filename);
- return Parse(modules);
+ s = Microsoft.Boogie.ParserHelper.Fill(System.Console.In, new List<string!>());
+ return Parse(s, modules);
} else {
using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) {
- BoogiePL.Buffer.Fill(reader);
- Scanner.Init(filename);
- return Parse(modules);
+ s = Microsoft.Boogie.ParserHelper.Fill(reader, new List<string!>());
+ return Parse(s, filename, modules);
}
}
}
@@ -81,106 +96,122 @@ public static int Parse (string! filename, List<ModuleDecl!>! modules) /* throws
/// Returns the number of parsing errors encountered.
/// Note: first initialize the Scanner.
///</summary>
-public static int Parse (List<ModuleDecl!>! modules) {
+public static int Parse (string! s, string! filename, List<ModuleDecl!>! modules) {
List<ModuleDecl!> oldModules = theModules;
theModules = modules;
- Parse();
+ byte[]! buffer = (!) UTF8Encoding.Default.GetBytes(s);
+ MemoryStream ms = new MemoryStream(buffer,false);
+ Errors errors = new Errors();
+ Scanner scanner = new Scanner(ms, errors, filename);
+ Parser parser = new Parser(scanner, errors);
+ parser.Parse();
theModules = oldModules;
- return Errors.count;
+ return parser.errors.count;
}
/*--------------------------------------------------------------------------*/
- static void Error(int n) {
- if (errDist >= minErrDist) Errors.SynErr(n, t.filename, t.line, t.col);
- errDist = 0;
+ public Parser(Scanner/*!*/ scanner, Errors/*!*/ errors) {
+ this.scanner = scanner;
+ this.errors = errors;
+ Token! tok = new Token();
+ tok.val = "";
+ this.la = tok;
+ this.t = new Token(); // just to satisfy its non-null constraint
}
-
- public static void SemErr(string! msg) {
- if (errDist >= minErrDist) Errors.SemErr(token.filename, token.line, token.col, msg);
+
+ void SynErr (int n) {
+ if (errDist >= minErrDist) errors.SynErr(la.filename, la.line, la.col, n);
errDist = 0;
}
- public static void SemErr(Token! tok, string! msg) {
- if (errDist >= minErrDist) Errors.SemErr(tok.filename, tok.line, tok.col, msg);
+ public void SemErr (string! msg) {
+ if (errDist >= minErrDist) errors.SemErr(t, msg);
errDist = 0;
}
+
+ public void SemErr(IToken! tok, string! msg) {
+ errors.SemErr(tok, msg);
+ }
- static void Get() {
+ void Get () {
for (;;) {
- token = t;
- t = Scanner.Scan();
- if (t.kind<=maxT) {errDist++; return;}
+ t = la;
+ la = scanner.Scan();
+ if (la.kind <= maxT) { ++errDist; break; }
- t = token;
+ la = t;
}
}
- static void Expect(int n) {
- if (t.kind==n) Get(); else Error(n);
+ void Expect (int n) {
+ if (la.kind==n) Get(); else { SynErr(n); }
}
- static bool StartOf(int s) {
- return set[s, t.kind];
+ bool StartOf (int s) {
+ return set[s, la.kind];
}
- static void ExpectWeak(int n, int follow) {
- if (t.kind == n) Get();
+ void ExpectWeak (int n, int follow) {
+ if (la.kind == n) Get();
else {
- Error(n);
+ SynErr(n);
while (!StartOf(follow)) Get();
}
}
-
- static bool WeakSeparator(int n, int syFol, int repFol) {
- bool[] s = new bool[maxT+1];
- if (t.kind == n) {Get(); return true;}
- else if (StartOf(repFol)) return false;
+
+
+ bool WeakSeparator(int n, int syFol, int repFol) {
+ int kind = la.kind;
+ if (kind == n) {Get(); return true;}
+ else if (StartOf(repFol)) {return false;}
else {
- for (int i=0; i <= maxT; i++) {
- s[i] = set[syFol, i] || set[repFol, i] || set[0, i];
+ SynErr(n);
+ while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) {
+ Get();
+ kind = la.kind;
}
- Error(n);
- while (!s[t.kind]) Get();
return StartOf(syFol);
}
}
+
- static void Dafny() {
+ void Dafny() {
ClassDecl! c; DatatypeDecl! dt;
- Attributes attrs; Token! id; List<string!> theImports;
- List<MemberDecl!> membersDefaultClass = new List<MemberDecl!>();
- ModuleDecl module;
-
- // to support multiple files, create a default module only if theModules doesn't already contain one
- DefaultModuleDecl defaultModule = null;
- foreach (ModuleDecl mdecl in theModules) {
- defaultModule = mdecl as DefaultModuleDecl;
- if (defaultModule != null) { break; }
- }
- bool defaultModuleCreatedHere = false;
- if (defaultModule == null) {
- defaultModuleCreatedHere = true;
- defaultModule = new DefaultModuleDecl();
- }
+ Attributes attrs; IToken! id; List<string!> theImports;
+ List<MemberDecl!> membersDefaultClass = new List<MemberDecl!>();
+ ModuleDecl module;
+
+ // to support multiple files, create a default module only if theModules doesn't already contain one
+ DefaultModuleDecl defaultModule = null;
+ foreach (ModuleDecl mdecl in theModules) {
+ defaultModule = mdecl as DefaultModuleDecl;
+ if (defaultModule != null) { break; }
+ }
+ bool defaultModuleCreatedHere = false;
+ if (defaultModule == null) {
+ defaultModuleCreatedHere = true;
+ defaultModule = new DefaultModuleDecl();
+ }
+
while (StartOf(1)) {
- if (t.kind == 4) {
+ if (la.kind == 4) {
Get();
attrs = null; theImports = new List<string!>();
- while (t.kind == 6) {
+ while (la.kind == 6) {
Attribute(ref attrs);
}
Ident(out id);
- if (t.kind == 5) {
+ if (la.kind == 5) {
Get();
Idents(theImports);
}
module = new ModuleDecl(id, id.val, theImports, attrs);
Expect(6);
- while (t.kind == 8 || t.kind == 12) {
- if (t.kind == 8) {
+ while (la.kind == 8 || la.kind == 12) {
+ if (la.kind == 8) {
ClassDecl(module, out c);
module.TopLevelDecls.Add(c);
} else {
@@ -190,10 +221,10 @@ public static int Parse (List<ModuleDecl!>! modules) {
}
theModules.Add(module);
Expect(7);
- } else if (t.kind == 8) {
+ } else if (la.kind == 8) {
ClassDecl(defaultModule, out c);
defaultModule.TopLevelDecls.Add(c);
- } else if (t.kind == 12) {
+ } else if (la.kind == 12) {
DatatypeDecl(defaultModule, out dt);
defaultModule.TopLevelDecls.Add(dt);
} else {
@@ -217,40 +248,40 @@ public static int Parse (List<ModuleDecl!>! modules) {
Expect(0);
}
- static void Attribute(ref Attributes attrs) {
+ void Attribute(ref Attributes attrs) {
Expect(6);
AttributeBody(ref attrs);
Expect(7);
}
- static void Ident(out Token! x) {
+ void Ident(out IToken! x) {
Expect(1);
- x = token;
+ x = t;
}
- static void Idents(List<string!>! ids) {
- Token! id;
+ void Idents(List<string!>! ids) {
+ IToken! id;
Ident(out id);
ids.Add(id.val);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
Ident(out id);
ids.Add(id.val);
}
}
- static void ClassDecl(ModuleDecl! module, out ClassDecl! c) {
- Token! id;
+ void ClassDecl(ModuleDecl! module, out ClassDecl! c) {
+ IToken! id;
Attributes attrs = null;
List<TypeParameter!> typeArgs = new List<TypeParameter!>();
List<MemberDecl!> members = new List<MemberDecl!>();
Expect(8);
- while (t.kind == 6) {
+ while (la.kind == 6) {
Attribute(ref attrs);
}
Ident(out id);
- if (t.kind == 17) {
+ if (la.kind == 17) {
GenericParameters(typeArgs);
}
Expect(6);
@@ -261,38 +292,38 @@ public static int Parse (List<ModuleDecl!>! modules) {
c = new ClassDecl(id, id.val, module, typeArgs, members, attrs);
}
- static void DatatypeDecl(ModuleDecl! module, out DatatypeDecl! dt) {
- Token! id;
+ void DatatypeDecl(ModuleDecl! module, out DatatypeDecl! dt) {
+ IToken! id;
Attributes attrs = null;
List<TypeParameter!> typeArgs = new List<TypeParameter!>();
List<DatatypeCtor!> ctors = new List<DatatypeCtor!>();
Expect(12);
- while (t.kind == 6) {
+ while (la.kind == 6) {
Attribute(ref attrs);
}
Ident(out id);
- if (t.kind == 17) {
+ if (la.kind == 17) {
GenericParameters(typeArgs);
}
Expect(6);
- while (t.kind == 1 || t.kind == 6) {
+ while (la.kind == 1 || la.kind == 6) {
DatatypeMemberDecl(ctors);
}
Expect(7);
dt = new DatatypeDecl(id, id.val, module, typeArgs, ctors, attrs);
}
- static void ClassMemberDecl(List<MemberDecl!>! mm) {
+ void ClassMemberDecl(List<MemberDecl!>! mm) {
Method! m;
Function! f;
MemberModifiers mmod = new MemberModifiers();
- while (t.kind == 9 || t.kind == 10 || t.kind == 11) {
- if (t.kind == 9) {
+ while (la.kind == 9 || la.kind == 10 || la.kind == 11) {
+ if (la.kind == 9) {
Get();
mmod.IsGhost = true;
- } else if (t.kind == 10) {
+ } else if (la.kind == 10) {
Get();
mmod.IsStatic = true;
} else {
@@ -300,23 +331,23 @@ public static int Parse (List<ModuleDecl!>! modules) {
mmod.IsUnlimited = true;
}
}
- if (t.kind == 14) {
+ if (la.kind == 14) {
FieldDecl(mmod, mm);
- } else if (t.kind == 34) {
+ } else if (la.kind == 34) {
FunctionDecl(mmod, out f);
mm.Add(f);
- } else if (t.kind == 19) {
+ } else if (la.kind == 19) {
MethodDecl(mmod, out m);
mm.Add(m);
- } else Error(101);
+ } else SynErr(101);
}
- static void GenericParameters(List<TypeParameter!>! typeArgs) {
- Token! id;
+ void GenericParameters(List<TypeParameter!>! typeArgs) {
+ IToken! id;
Expect(17);
Ident(out id);
typeArgs.Add(new TypeParameter(id, id.val));
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
Ident(out id);
typeArgs.Add(new TypeParameter(id, id.val));
@@ -324,20 +355,20 @@ public static int Parse (List<ModuleDecl!>! modules) {
Expect(18);
}
- static void FieldDecl(MemberModifiers mmod, List<MemberDecl!>! mm) {
+ void FieldDecl(MemberModifiers mmod, List<MemberDecl!>! mm) {
Attributes attrs = null;
- Token! id; Type! ty;
+ IToken! id; Type! ty;
Expect(14);
- if (mmod.IsUnlimited) { SemErr(token, "fields cannot be declared 'unlimited'"); }
- if (mmod.IsStatic) { SemErr(token, "fields cannot be declared 'static'"); }
+ if (mmod.IsUnlimited) { SemErr(t, "fields cannot be declared 'unlimited'"); }
+ if (mmod.IsStatic) { SemErr(t, "fields cannot be declared 'static'"); }
- while (t.kind == 6) {
+ while (la.kind == 6) {
Attribute(ref attrs);
}
IdentType(out id, out ty);
mm.Add(new Field(id, id.val, mmod.IsGhost, ty, attrs));
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
IdentType(out id, out ty);
mm.Add(new Field(id, id.val, mmod.IsGhost, ty, attrs));
@@ -345,9 +376,9 @@ public static int Parse (List<ModuleDecl!>! modules) {
Expect(13);
}
- static void FunctionDecl(MemberModifiers mmod, out Function! f) {
+ void FunctionDecl(MemberModifiers mmod, out Function! f) {
Attributes attrs = null;
- Token! id;
+ IToken! id;
List<TypeParameter!> typeArgs = new List<TypeParameter!>();
List<Formal!> formals = new List<Formal!>();
Type! returnType;
@@ -358,42 +389,42 @@ public static int Parse (List<ModuleDecl!>! modules) {
bool isFunctionMethod = false;
Expect(34);
- if (t.kind == 19) {
+ if (la.kind == 19) {
Get();
isFunctionMethod = true;
}
- if (mmod.IsGhost) { SemErr(token, "functions cannot be declared 'ghost' (they are ghost by default)"); }
+ if (mmod.IsGhost) { SemErr(t, "functions cannot be declared 'ghost' (they are ghost by default)"); }
- while (t.kind == 6) {
+ while (la.kind == 6) {
Attribute(ref attrs);
}
Ident(out id);
- if (t.kind == 17) {
+ if (la.kind == 17) {
GenericParameters(typeArgs);
}
parseVarScope.PushMarker();
Formals(true, false, formals);
Expect(16);
Type(out returnType);
- if (t.kind == 13) {
+ if (la.kind == 13) {
Get();
- while (t.kind == 23 || t.kind == 25 || t.kind == 35) {
+ while (la.kind == 23 || la.kind == 25 || la.kind == 35) {
FunctionSpec(reqs, reads, decreases);
}
} else if (StartOf(3)) {
- while (t.kind == 23 || t.kind == 25 || t.kind == 35) {
+ while (la.kind == 23 || la.kind == 25 || la.kind == 35) {
FunctionSpec(reqs, reads, decreases);
}
FunctionBody(out bb);
body = bb;
- } else Error(102);
+ } else SynErr(102);
parseVarScope.PopMarker();
f = new Function(id, id.val, mmod.IsStatic, !isFunctionMethod, mmod.IsUnlimited, typeArgs, formals, returnType, reqs, reads, decreases, body, attrs);
}
- static void MethodDecl(MemberModifiers mmod, out Method! m) {
- Token! id;
+ void MethodDecl(MemberModifiers mmod, out Method! m) {
+ IToken! id;
Attributes attrs = null;
List<TypeParameter!>! typeArgs = new List<TypeParameter!>();
List<Formal!> ins = new List<Formal!>();
@@ -405,22 +436,22 @@ public static int Parse (List<ModuleDecl!>! modules) {
Statement! bb; BlockStmt body = null;
Expect(19);
- if (mmod.IsUnlimited) { SemErr(token, "methods cannot be declared 'unlimited'"); }
+ if (mmod.IsUnlimited) { SemErr(t, "methods cannot be declared 'unlimited'"); }
- while (t.kind == 6) {
+ while (la.kind == 6) {
Attribute(ref attrs);
}
Ident(out id);
- if (t.kind == 17) {
+ if (la.kind == 17) {
GenericParameters(typeArgs);
}
parseVarScope.PushMarker();
Formals(true, true, ins);
- if (t.kind == 20) {
+ if (la.kind == 20) {
Get();
Formals(false, true, outs);
}
- if (t.kind == 13) {
+ if (la.kind == 13) {
Get();
while (StartOf(4)) {
MethodSpec(req, mod, ens, dec);
@@ -431,27 +462,27 @@ public static int Parse (List<ModuleDecl!>! modules) {
}
BlockStmt(out bb);
body = (BlockStmt)bb;
- } else Error(103);
+ } else SynErr(103);
parseVarScope.PopMarker();
m = new Method(id, id.val, mmod.IsStatic, mmod.IsGhost, typeArgs, ins, outs, req, mod, ens, dec, body, attrs);
}
- static void DatatypeMemberDecl(List<DatatypeCtor!>! ctors) {
+ void DatatypeMemberDecl(List<DatatypeCtor!>! ctors) {
Attributes attrs = null;
- Token! id;
+ IToken! id;
List<TypeParameter!> typeArgs = new List<TypeParameter!>();
List<Formal!> formals = new List<Formal!>();
- while (t.kind == 6) {
+ while (la.kind == 6) {
Attribute(ref attrs);
}
Ident(out id);
- if (t.kind == 17) {
+ if (la.kind == 17) {
GenericParameters(typeArgs);
}
parseVarScope.PushMarker();
- if (t.kind == 26) {
+ if (la.kind == 26) {
FormalsOptionalIds(formals);
}
parseVarScope.PopMarker();
@@ -460,13 +491,13 @@ public static int Parse (List<ModuleDecl!>! modules) {
Expect(13);
}
- static void FormalsOptionalIds(List<Formal!>! formals) {
- Token! id; Type! ty; string! name; bool isGhost;
+ void FormalsOptionalIds(List<Formal!>! formals) {
+ IToken! id; Type! ty; string! name; bool isGhost;
Expect(26);
if (StartOf(6)) {
TypeIdentOptional(out id, out name, out ty, out isGhost);
formals.Add(new Formal(id, name, ty, true, isGhost)); parseVarScope.Push(name, name);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
TypeIdentOptional(out id, out name, out ty, out isGhost);
formals.Add(new Formal(id, name, ty, true, isGhost)); parseVarScope.Push(name, name);
@@ -475,31 +506,31 @@ public static int Parse (List<ModuleDecl!>! modules) {
Expect(27);
}
- static void IdentType(out Token! id, out Type! ty) {
+ void IdentType(out IToken! id, out Type! ty) {
Ident(out id);
Expect(16);
Type(out ty);
}
- static void GIdentType(bool allowGhost, out Token! id, out Type! ty, out bool isGhost) {
+ void GIdentType(bool allowGhost, out IToken! id, out Type! ty, out bool isGhost) {
isGhost = false;
- if (t.kind == 9) {
+ if (la.kind == 9) {
Get();
- if (allowGhost) { isGhost = true; } else { SemErr(token, "formal cannot be declared 'ghost' in this context"); }
+ if (allowGhost) { isGhost = true; } else { SemErr(t, "formal cannot be declared 'ghost' in this context"); }
}
IdentType(out id, out ty);
}
- static void Type(out Type! ty) {
- Token! tok;
+ void Type(out Type! ty) {
+ IToken! tok;
TypeAndToken(out tok, out ty);
}
- static void IdentTypeOptional(out BoundVar! var) {
- Token! id; Type! ty; Type optType = null;
+ void IdentTypeOptional(out BoundVar! var) {
+ IToken! id; Type! ty; Type optType = null;
Ident(out id);
- if (t.kind == 16) {
+ if (la.kind == 16) {
Get();
Type(out ty);
optType = ty;
@@ -507,14 +538,14 @@ public static int Parse (List<ModuleDecl!>! modules) {
var = new BoundVar(id, id.val, optType == null ? new InferredTypeProxy() : optType);
}
- static void TypeIdentOptional(out Token! id, out string! identName, out Type! ty, out bool isGhost) {
+ void TypeIdentOptional(out IToken! id, out string! identName, out Type! ty, out bool isGhost) {
string name = null; isGhost = false;
- if (t.kind == 9) {
+ if (la.kind == 9) {
Get();
isGhost = true;
}
TypeAndToken(out id, out ty);
- if (t.kind == 16) {
+ if (la.kind == 16) {
Get();
UserDefinedType udt = ty as UserDefinedType;
if (udt != null && udt.TypeArgs.Count == 0) {
@@ -533,46 +564,46 @@ public static int Parse (List<ModuleDecl!>! modules) {
}
- static void TypeAndToken(out Token! tok, out Type! ty) {
+ void TypeAndToken(out IToken! tok, out Type! ty) {
tok = Token.NoToken; ty = new BoolType(); /*keep compiler happy*/
List<Type!>! gt;
- if (t.kind == 28) {
+ if (la.kind == 28) {
Get();
- tok = token;
- } else if (t.kind == 29) {
+ tok = t;
+ } else if (la.kind == 29) {
Get();
- tok = token; ty = new IntType();
- } else if (t.kind == 30) {
+ tok = t; ty = new IntType();
+ } else if (la.kind == 30) {
Get();
- tok = token; gt = new List<Type!>();
+ tok = t; gt = new List<Type!>();
GenericInstantiation(gt);
if (gt.Count != 1) {
SemErr("set type expects exactly one type argument");
}
ty = new SetType(gt[0]);
- } else if (t.kind == 31) {
+ } else if (la.kind == 31) {
Get();
- tok = token; gt = new List<Type!>();
+ tok = t; gt = new List<Type!>();
GenericInstantiation(gt);
if (gt.Count != 1) {
SemErr("seq type expects exactly one type argument");
}
ty = new SeqType(gt[0]);
- } else if (t.kind == 1 || t.kind == 32 || t.kind == 33) {
+ } else if (la.kind == 1 || la.kind == 32 || la.kind == 33) {
ReferenceType(out tok, out ty);
- } else Error(104);
+ } else SynErr(104);
}
- static void Formals(bool incoming, bool allowGhosts, List<Formal!>! formals) {
- Token! id; Type! ty; bool isGhost;
+ void Formals(bool incoming, bool allowGhosts, List<Formal!>! formals) {
+ IToken! id; Type! ty; bool isGhost;
Expect(26);
- if (t.kind == 1 || t.kind == 9) {
+ if (la.kind == 1 || la.kind == 9) {
GIdentType(allowGhosts, out id, out ty, out isGhost);
formals.Add(new Formal(id, id.val, ty, incoming, isGhost)); parseVarScope.Push(id.val, id.val);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
GIdentType(allowGhosts, out id, out ty, out isGhost);
formals.Add(new Formal(id, id.val, ty, incoming, isGhost)); parseVarScope.Push(id.val, id.val);
@@ -581,53 +612,53 @@ public static int Parse (List<ModuleDecl!>! modules) {
Expect(27);
}
- static void MethodSpec(List<MaybeFreeExpression!>! req, List<FrameExpression!>! mod, List<MaybeFreeExpression!>! ens,
+ void MethodSpec(List<MaybeFreeExpression!>! req, List<FrameExpression!>! mod, List<MaybeFreeExpression!>! ens,
List<Expression!>! decreases) {
Expression! e; FrameExpression! fe; bool isFree = false;
- if (t.kind == 21) {
+ if (la.kind == 21) {
Get();
if (StartOf(7)) {
FrameExpression(out fe);
mod.Add(fe);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
FrameExpression(out fe);
mod.Add(fe);
}
}
Expect(13);
- } else if (t.kind == 22 || t.kind == 23 || t.kind == 24) {
- if (t.kind == 22) {
+ } else if (la.kind == 22 || la.kind == 23 || la.kind == 24) {
+ if (la.kind == 22) {
Get();
isFree = true;
}
- if (t.kind == 23) {
+ if (la.kind == 23) {
Get();
Expression(out e);
Expect(13);
req.Add(new MaybeFreeExpression(e, isFree));
- } else if (t.kind == 24) {
+ } else if (la.kind == 24) {
Get();
Expression(out e);
Expect(13);
ens.Add(new MaybeFreeExpression(e, isFree));
- } else Error(105);
- } else if (t.kind == 25) {
+ } else SynErr(105);
+ } else if (la.kind == 25) {
Get();
Expressions(decreases);
Expect(13);
- } else Error(106);
+ } else SynErr(106);
}
- static void BlockStmt(out Statement! block) {
- Token! x;
+ void BlockStmt(out Statement! block) {
+ IToken! x;
List<Statement!> body = new List<Statement!>();
Statement! s;
parseVarScope.PushMarker();
Expect(6);
- x = token;
+ x = t;
while (StartOf(8)) {
Stmt(body);
}
@@ -636,10 +667,10 @@ List<Expression!>! decreases) {
parseVarScope.PopMarker();
}
- static void FrameExpression(out FrameExpression! fe) {
- Expression! e; Token! id; string fieldName = null;
+ void FrameExpression(out FrameExpression! fe) {
+ Expression! e; IToken! id; string fieldName = null;
Expression(out e);
- if (t.kind == 37) {
+ if (la.kind == 37) {
Get();
Ident(out id);
fieldName = id.val;
@@ -647,13 +678,13 @@ List<Expression!>! decreases) {
fe = new FrameExpression(e, fieldName);
}
- static void Expression(out Expression! e) {
- Token! x; Expression! e0; Expression! e1 = dummyExpr;
+ void Expression(out Expression! e) {
+ IToken! x; Expression! e0; Expression! e1 = dummyExpr;
e = dummyExpr;
- if (t.kind == 49) {
+ if (la.kind == 49) {
Get();
- x = token;
+ x = t;
Expression(out e);
Expect(61);
Expression(out e0);
@@ -662,26 +693,26 @@ List<Expression!>! decreases) {
e = new ITEExpr(x, e, e0, e1);
} else if (StartOf(9)) {
EquivExpression(out e);
- } else Error(107);
+ } else SynErr(107);
}
- static void Expressions(List<Expression!>! args) {
+ void Expressions(List<Expression!>! args) {
Expression! e;
Expression(out e);
args.Add(e);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
Expression(out e);
args.Add(e);
}
}
- static void GenericInstantiation(List<Type!>! gt) {
+ void GenericInstantiation(List<Type!>! gt) {
Type! ty;
Expect(17);
Type(out ty);
gt.Add(ty);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
Type(out ty);
gt.Add(ty);
@@ -689,117 +720,117 @@ List<Expression!>! decreases) {
Expect(18);
}
- static void ReferenceType(out Token! tok, out Type! ty) {
+ void ReferenceType(out IToken! tok, out Type! ty) {
tok = Token.NoToken; ty = new BoolType(); /*keep compiler happy*/
List<Type!>! gt;
- if (t.kind == 32) {
+ if (la.kind == 32) {
Get();
- tok = token; ty = new ObjectType();
- } else if (t.kind == 33) {
+ tok = t; ty = new ObjectType();
+ } else if (la.kind == 33) {
Get();
- tok = token; gt = new List<Type!>();
+ tok = t; gt = new List<Type!>();
GenericInstantiation(gt);
if (gt.Count != 1) {
SemErr("array type expects exactly one type argument");
}
ty = UserDefinedType.ArrayType(tok, gt[0]);
- } else if (t.kind == 1) {
+ } else if (la.kind == 1) {
Ident(out tok);
gt = new List<Type!>();
- if (t.kind == 17) {
+ if (la.kind == 17) {
GenericInstantiation(gt);
}
ty = new UserDefinedType(tok, tok.val, gt);
- } else Error(108);
+ } else SynErr(108);
}
- static void FunctionSpec(List<Expression!>! reqs, List<FrameExpression!>! reads, List<Expression!>! decreases) {
+ void FunctionSpec(List<Expression!>! reqs, List<FrameExpression!>! reads, List<Expression!>! decreases) {
Expression! e; FrameExpression! fe;
- if (t.kind == 23) {
+ if (la.kind == 23) {
Get();
Expression(out e);
Expect(13);
reqs.Add(e);
- } else if (t.kind == 35) {
+ } else if (la.kind == 35) {
Get();
if (StartOf(10)) {
PossiblyWildFrameExpression(out fe);
reads.Add(fe);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
PossiblyWildFrameExpression(out fe);
reads.Add(fe);
}
}
Expect(13);
- } else if (t.kind == 25) {
+ } else if (la.kind == 25) {
Get();
Expressions(decreases);
Expect(13);
- } else Error(109);
+ } else SynErr(109);
}
- static void FunctionBody(out Expression! e) {
+ void FunctionBody(out Expression! e) {
e = dummyExpr;
Expect(6);
- if (t.kind == 38) {
+ if (la.kind == 38) {
MatchExpression(out e);
} else if (StartOf(7)) {
Expression(out e);
- } else Error(110);
+ } else SynErr(110);
Expect(7);
}
- static void PossiblyWildFrameExpression(out FrameExpression! fe) {
+ void PossiblyWildFrameExpression(out FrameExpression! fe) {
fe = dummyFrameExpr;
- if (t.kind == 36) {
+ if (la.kind == 36) {
Get();
- fe = new FrameExpression(new WildcardExpr(token), null);
+ fe = new FrameExpression(new WildcardExpr(t), null);
} else if (StartOf(7)) {
FrameExpression(out fe);
- } else Error(111);
+ } else SynErr(111);
}
- static void PossiblyWildExpression(out Expression! e) {
+ void PossiblyWildExpression(out Expression! e) {
e = dummyExpr;
- if (t.kind == 36) {
+ if (la.kind == 36) {
Get();
- e = new WildcardExpr(token);
+ e = new WildcardExpr(t);
} else if (StartOf(7)) {
Expression(out e);
- } else Error(112);
+ } else SynErr(112);
}
- static void MatchExpression(out Expression! e) {
- Token! x; MatchCaseExpr! c;
+ void MatchExpression(out Expression! e) {
+ IToken! x; MatchCaseExpr! c;
List<MatchCaseExpr!> cases = new List<MatchCaseExpr!>();
Expect(38);
- x = token;
+ x = t;
Expression(out e);
- while (t.kind == 39) {
+ while (la.kind == 39) {
CaseExpression(out c);
cases.Add(c);
}
e = new MatchExpr(x, e, cases);
}
- static void CaseExpression(out MatchCaseExpr! c) {
- Token! x, id, arg;
+ void CaseExpression(out MatchCaseExpr! c) {
+ IToken! x, id, arg;
List<BoundVar!> arguments = new List<BoundVar!>();
Expression! body;
Expect(39);
- x = token; parseVarScope.PushMarker();
+ x = t; parseVarScope.PushMarker();
Ident(out id);
- if (t.kind == 26) {
+ if (la.kind == 26) {
Get();
Ident(out arg);
arguments.Add(new BoundVar(arg, arg.val, new InferredTypeProxy()));
parseVarScope.Push(arg.val, arg.val);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
Ident(out arg);
arguments.Add(new BoundVar(arg, arg.val, new InferredTypeProxy()));
@@ -813,25 +844,25 @@ List<Expression!>! decreases) {
parseVarScope.PopMarker();
}
- static void Stmt(List<Statement!>! ss) {
+ void Stmt(List<Statement!>! ss) {
Statement! s;
- while (t.kind == 6) {
+ while (la.kind == 6) {
BlockStmt(out s);
ss.Add(s);
}
if (StartOf(11)) {
OneStmt(out s);
ss.Add(s);
- } else if (t.kind == 9 || t.kind == 14) {
+ } else if (la.kind == 9 || la.kind == 14) {
VarDeclStmts(ss);
- } else Error(113);
+ } else SynErr(113);
}
- static void OneStmt(out Statement! s) {
- Token! x; Token! id; string label = null;
+ void OneStmt(out Statement! s) {
+ IToken! x; IToken! id; string label = null;
s = dummyStmt; /* to please the compiler */
- switch (t.kind) {
+ switch (la.kind) {
case 57: {
AssertStmt(out s);
break;
@@ -878,7 +909,7 @@ List<Expression!>! decreases) {
}
case 41: {
Get();
- x = token;
+ x = t;
Ident(out id);
Expect(16);
s = new LabelStmt(x, id.val);
@@ -886,8 +917,8 @@ List<Expression!>! decreases) {
}
case 42: {
Get();
- x = token;
- if (t.kind == 1) {
+ x = t;
+ if (la.kind == 1) {
Ident(out id);
label = id.val;
}
@@ -897,25 +928,25 @@ List<Expression!>! decreases) {
}
case 43: {
Get();
- x = token;
+ x = t;
Expect(13);
s = new ReturnStmt(x);
break;
}
- default: Error(114); break;
+ default: SynErr(114); break;
}
}
- static void VarDeclStmts(List<Statement!>! ss) {
+ void VarDeclStmts(List<Statement!>! ss) {
VarDecl! d; bool isGhost = false;
- if (t.kind == 9) {
+ if (la.kind == 9) {
Get();
isGhost = true;
}
Expect(14);
IdentTypeRhs(out d, isGhost);
ss.Add(d); parseVarScope.Push(d.Name, d.Name);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
IdentTypeRhs(out d, isGhost);
ss.Add(d); parseVarScope.Push(d.Name, d.Name);
@@ -923,42 +954,42 @@ List<Expression!>! decreases) {
Expect(13);
}
- static void AssertStmt(out Statement! s) {
- Token! x; Expression! e;
+ void AssertStmt(out Statement! s) {
+ IToken! x; Expression! e;
Expect(57);
- x = token;
+ x = t;
Expression(out e);
Expect(13);
s = new AssertStmt(x, e);
}
- static void AssumeStmt(out Statement! s) {
- Token! x; Expression! e;
+ void AssumeStmt(out Statement! s) {
+ IToken! x; Expression! e;
Expect(58);
- x = token;
+ x = t;
Expression(out e);
Expect(13);
s = new AssumeStmt(x, e);
}
- static void UseStmt(out Statement! s) {
- Token! x; Expression! e;
+ void UseStmt(out Statement! s) {
+ IToken! x; Expression! e;
Expect(59);
- x = token;
+ x = t;
Expression(out e);
Expect(13);
s = new UseStmt(x, e);
}
- static void PrintStmt(out Statement! s) {
- Token! x; Attributes.Argument! arg;
+ void PrintStmt(out Statement! s) {
+ IToken! x; Attributes.Argument! arg;
List<Attributes.Argument!> args = new List<Attributes.Argument!>();
Expect(60);
- x = token;
+ x = t;
AttributeArg(out arg);
args.Add(arg);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
AttributeArg(out arg);
args.Add(arg);
@@ -967,8 +998,8 @@ List<Expression!>! decreases) {
s = new PrintStmt(x, args);
}
- static void AssignStmt(out Statement! s) {
- Token! x;
+ void AssignStmt(out Statement! s) {
+ IToken! x;
Expression! lhs;
Expression rhs;
Type ty;
@@ -976,7 +1007,7 @@ List<Expression!>! decreases) {
LhsExpr(out lhs);
Expect(44);
- x = token;
+ x = t;
AssignRhs(out rhs, out ty);
if (ty == null) {
assert rhs != null;
@@ -990,26 +1021,26 @@ List<Expression!>! decreases) {
Expect(13);
}
- static void HavocStmt(out Statement! s) {
- Token! x; Expression! lhs;
+ void HavocStmt(out Statement! s) {
+ IToken! x; Expression! lhs;
Expect(48);
- x = token;
+ x = t;
LhsExpr(out lhs);
Expect(13);
s = new AssignStmt(x, lhs);
}
- static void CallStmt(out Statement! s) {
- Token! x, id;
+ void CallStmt(out Statement! s) {
+ IToken! x, id;
Expression! e;
List<IdentifierExpr!> lhs = new List<IdentifierExpr!>();
List<AutoVarDecl!> newVars = new List<AutoVarDecl!>();
Expect(53);
- x = token;
+ x = t;
CallStmtSubExpr(out e);
- if (t.kind == 15 || t.kind == 44) {
- if (t.kind == 15) {
+ if (la.kind == 15 || la.kind == 44) {
+ if (la.kind == 15) {
Get();
e = ConvertToLocal(e);
if (e is IdentifierExpr) {
@@ -1022,7 +1053,7 @@ List<Expression!>! decreases) {
Ident(out id);
RecordCallLhs(new IdentifierExpr(id, id.val), lhs, newVars);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
Ident(out id);
RecordCallLhs(new IdentifierExpr(id, id.val), lhs, newVars);
@@ -1054,32 +1085,32 @@ List<Expression!>! decreases) {
}
- static void IfStmt(out Statement! ifStmt) {
- Token! x;
+ void IfStmt(out Statement! ifStmt) {
+ IToken! x;
Expression guard;
Statement! thn;
Statement! s;
Statement els = null;
Expect(49);
- x = token;
+ x = t;
Guard(out guard);
BlockStmt(out thn);
- if (t.kind == 50) {
+ if (la.kind == 50) {
Get();
- if (t.kind == 49) {
+ if (la.kind == 49) {
IfStmt(out s);
els = s;
- } else if (t.kind == 6) {
+ } else if (la.kind == 6) {
BlockStmt(out s);
els = s;
- } else Error(115);
+ } else SynErr(115);
}
ifStmt = new IfStmt(x, guard, thn, els);
}
- static void WhileStmt(out Statement! stmt) {
- Token! x;
+ void WhileStmt(out Statement! stmt) {
+ IToken! x;
Expression guard;
bool isFree; Expression! e;
List<MaybeFreeExpression!> invariants = new List<MaybeFreeExpression!>();
@@ -1087,13 +1118,13 @@ List<Expression!>! decreases) {
Statement! body;
Expect(51);
- x = token;
+ x = t;
Guard(out guard);
assume guard == null || Owner.None(guard);
- while (t.kind == 22 || t.kind == 25 || t.kind == 52) {
- if (t.kind == 22 || t.kind == 52) {
+ while (la.kind == 22 || la.kind == 25 || la.kind == 52) {
+ if (la.kind == 22 || la.kind == 52) {
isFree = false;
- if (t.kind == 22) {
+ if (la.kind == 22) {
Get();
isFree = true;
}
@@ -1105,7 +1136,7 @@ List<Expression!>! decreases) {
Get();
PossiblyWildExpression(out e);
decreases.Add(e);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
PossiblyWildExpression(out e);
decreases.Add(e);
@@ -1117,14 +1148,14 @@ List<Expression!>! decreases) {
stmt = new WhileStmt(x, guard, invariants, decreases, body);
}
- static void MatchStmt(out Statement! s) {
+ void MatchStmt(out Statement! s) {
Token x; Expression! e; MatchCaseStmt! c;
List<MatchCaseStmt!> cases = new List<MatchCaseStmt!>();
Expect(38);
- x = token;
+ x = t;
Expression(out e);
Expect(6);
- while (t.kind == 39) {
+ while (la.kind == 39) {
CaseStatement(out c);
cases.Add(c);
}
@@ -1132,8 +1163,8 @@ List<Expression!>! decreases) {
s = new MatchStmt(x, e, cases);
}
- static void ForeachStmt(out Statement! s) {
- Token! x, boundVar;
+ void ForeachStmt(out Statement! s) {
+ IToken! x, boundVar;
Type! ty;
Expression! collection;
Expression! range;
@@ -1142,30 +1173,30 @@ List<Expression!>! decreases) {
parseVarScope.PushMarker();
Expect(54);
- x = token;
+ x = t;
range = new LiteralExpr(x, true);
ty = new InferredTypeProxy();
Expect(26);
Ident(out boundVar);
- if (t.kind == 16) {
+ if (la.kind == 16) {
Get();
Type(out ty);
}
Expect(55);
Expression(out collection);
parseVarScope.Push(boundVar.val, boundVar.val);
- if (t.kind == 56) {
+ if (la.kind == 56) {
Get();
Expression(out range);
}
Expect(27);
Expect(6);
- while (t.kind == 57 || t.kind == 58 || t.kind == 59) {
- if (t.kind == 57) {
+ while (la.kind == 57 || la.kind == 58 || la.kind == 59) {
+ if (la.kind == 57) {
AssertStmt(out s);
if (s is PredicateStmt) { bodyPrefix.Add((PredicateStmt)s); }
- } else if (t.kind == 58) {
+ } else if (la.kind == 58) {
AssumeStmt(out s);
if (s is PredicateStmt) { bodyPrefix.Add((PredicateStmt)s); }
} else {
@@ -1176,10 +1207,10 @@ List<Expression!>! decreases) {
if (StartOf(12)) {
AssignStmt(out s);
if (s is AssignStmt) { bodyAssign = (AssignStmt)s; }
- } else if (t.kind == 48) {
+ } else if (la.kind == 48) {
HavocStmt(out s);
if (s is AssignStmt) { bodyAssign = (AssignStmt)s; }
- } else Error(116);
+ } else SynErr(116);
Expect(7);
if (bodyAssign != null) {
s = new ForeachStmt(x, new BoundVar(boundVar, boundVar.val, ty), collection, range, bodyPrefix, bodyAssign);
@@ -1190,19 +1221,19 @@ List<Expression!>! decreases) {
parseVarScope.PopMarker();
}
- static void LhsExpr(out Expression! e) {
+ void LhsExpr(out Expression! e) {
SelectExpression(out e);
}
- static void AssignRhs(out Expression e, out Type ty) {
- Token! x; Expression! ee; Type! tt;
+ void AssignRhs(out Expression e, out Type ty) {
+ IToken! x; Expression! ee; Type! tt;
e = null; ty = null;
- if (t.kind == 45) {
+ if (la.kind == 45) {
Get();
TypeAndToken(out x, out tt);
ty = tt;
- if (t.kind == 46) {
+ if (la.kind == 46) {
Get();
Expression(out ee);
Expect(47);
@@ -1211,34 +1242,34 @@ List<Expression!>! decreases) {
} else if (StartOf(7)) {
Expression(out ee);
e = ee;
- } else Error(117);
+ } else SynErr(117);
if (e == null && ty == null) { e = dummyExpr; }
}
- static void SelectExpression(out Expression! e) {
- Token! id; e = dummyExpr;
- if (t.kind == 1) {
+ void SelectExpression(out Expression! e) {
+ IToken! id; e = dummyExpr;
+ if (la.kind == 1) {
IdentOrFuncExpression(out e);
- } else if (t.kind == 26 || t.kind == 92 || t.kind == 93) {
+ } else if (la.kind == 26 || la.kind == 92 || la.kind == 93) {
ObjectExpression(out e);
- } else Error(118);
- while (t.kind == 46 || t.kind == 89) {
+ } else SynErr(118);
+ while (la.kind == 46 || la.kind == 89) {
SelectOrCallSuffix(ref e);
}
}
- static void IdentTypeRhs(out VarDecl! d, bool isGhost) {
- Token! id; Type! ty; Expression! e;
+ void IdentTypeRhs(out VarDecl! d, bool isGhost) {
+ IToken! id; Type! ty; Expression! e;
Expression rhs = null; Type newType = null;
Type optionalType = null; DeterminedAssignmentRhs optionalRhs = null;
Ident(out id);
- if (t.kind == 16) {
+ if (la.kind == 16) {
Get();
Type(out ty);
optionalType = ty;
}
- if (t.kind == 44) {
+ if (la.kind == 44) {
Get();
AssignRhs(out rhs, out newType);
}
@@ -1257,33 +1288,33 @@ List<Expression!>! decreases) {
}
- static void Guard(out Expression e) {
+ void Guard(out Expression e) {
Expression! ee; e = null;
Expect(26);
- if (t.kind == 36) {
+ if (la.kind == 36) {
Get();
e = null;
} else if (StartOf(7)) {
Expression(out ee);
e = ee;
- } else Error(119);
+ } else SynErr(119);
Expect(27);
}
- static void CaseStatement(out MatchCaseStmt! c) {
- Token! x, id, arg;
+ void CaseStatement(out MatchCaseStmt! c) {
+ IToken! x, id, arg;
List<BoundVar!> arguments = new List<BoundVar!>();
List<Statement!> body = new List<Statement!>();
Expect(39);
- x = token; parseVarScope.PushMarker();
+ x = t; parseVarScope.PushMarker();
Ident(out id);
- if (t.kind == 26) {
+ if (la.kind == 26) {
Get();
Ident(out arg);
arguments.Add(new BoundVar(arg, arg.val, new InferredTypeProxy()));
parseVarScope.Push(arg.val, arg.val);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
Ident(out arg);
arguments.Add(new BoundVar(arg, arg.val, new InferredTypeProxy()));
@@ -1301,83 +1332,83 @@ List<Expression!>! decreases) {
parseVarScope.PopMarker();
}
- static void CallStmtSubExpr(out Expression! e) {
+ void CallStmtSubExpr(out Expression! e) {
e = dummyExpr;
- if (t.kind == 1) {
+ if (la.kind == 1) {
IdentOrFuncExpression(out e);
- } else if (t.kind == 26 || t.kind == 92 || t.kind == 93) {
+ } else if (la.kind == 26 || la.kind == 92 || la.kind == 93) {
ObjectExpression(out e);
SelectOrCallSuffix(ref e);
- } else Error(120);
- while (t.kind == 46 || t.kind == 89) {
+ } else SynErr(120);
+ while (la.kind == 46 || la.kind == 89) {
SelectOrCallSuffix(ref e);
}
}
- static void AttributeArg(out Attributes.Argument! arg) {
+ void AttributeArg(out Attributes.Argument! arg) {
Expression! e; arg = dummyAttrArg;
- if (t.kind == 3) {
+ if (la.kind == 3) {
Get();
- arg = new Attributes.Argument(token.val.Substring(1, token.val.Length-2));
+ arg = new Attributes.Argument(t.val.Substring(1, t.val.Length-2));
} else if (StartOf(7)) {
Expression(out e);
arg = new Attributes.Argument(e);
- } else Error(121);
+ } else SynErr(121);
}
- static void EquivExpression(out Expression! e0) {
- Token! x; Expression! e1;
+ void EquivExpression(out Expression! e0) {
+ IToken! x; Expression! e1;
ImpliesExpression(out e0);
- while (t.kind == 62 || t.kind == 63) {
+ while (la.kind == 62 || la.kind == 63) {
EquivOp();
- x = token;
+ x = t;
ImpliesExpression(out e1);
e0 = new BinaryExpr(x, BinaryExpr.Opcode.Iff, e0, e1);
}
}
- static void ImpliesExpression(out Expression! e0) {
- Token! x; Expression! e1;
+ void ImpliesExpression(out Expression! e0) {
+ IToken! x; Expression! e1;
LogicalExpression(out e0);
- if (t.kind == 64 || t.kind == 65) {
+ if (la.kind == 64 || la.kind == 65) {
ImpliesOp();
- x = token;
+ x = t;
ImpliesExpression(out e1);
e0 = new BinaryExpr(x, BinaryExpr.Opcode.Imp, e0, e1);
}
}
- static void EquivOp() {
- if (t.kind == 62) {
+ void EquivOp() {
+ if (la.kind == 62) {
Get();
- } else if (t.kind == 63) {
+ } else if (la.kind == 63) {
Get();
- } else Error(122);
+ } else SynErr(122);
}
- static void LogicalExpression(out Expression! e0) {
- Token! x; Expression! e1;
+ void LogicalExpression(out Expression! e0) {
+ IToken! x; Expression! e1;
RelationalExpression(out e0);
if (StartOf(13)) {
- if (t.kind == 66 || t.kind == 67) {
+ if (la.kind == 66 || la.kind == 67) {
AndOp();
- x = token;
+ x = t;
RelationalExpression(out e1);
e0 = new BinaryExpr(x, BinaryExpr.Opcode.And, e0, e1);
- while (t.kind == 66 || t.kind == 67) {
+ while (la.kind == 66 || la.kind == 67) {
AndOp();
- x = token;
+ x = t;
RelationalExpression(out e1);
e0 = new BinaryExpr(x, BinaryExpr.Opcode.And, e0, e1);
}
} else {
OrOp();
- x = token;
+ x = t;
RelationalExpression(out e1);
e0 = new BinaryExpr(x, BinaryExpr.Opcode.Or, e0, e1);
- while (t.kind == 68 || t.kind == 69) {
+ while (la.kind == 68 || la.kind == 69) {
OrOp();
- x = token;
+ x = t;
RelationalExpression(out e1);
e0 = new BinaryExpr(x, BinaryExpr.Opcode.Or, e0, e1);
}
@@ -1385,16 +1416,16 @@ List<Expression!>! decreases) {
}
}
- static void ImpliesOp() {
- if (t.kind == 64) {
+ void ImpliesOp() {
+ if (la.kind == 64) {
Get();
- } else if (t.kind == 65) {
+ } else if (la.kind == 65) {
Get();
- } else Error(123);
+ } else SynErr(123);
}
- static void RelationalExpression(out Expression! e0) {
- Token! x; Expression! e1; BinaryExpr.Opcode op;
+ void RelationalExpression(out Expression! e0) {
+ IToken! x; Expression! e1; BinaryExpr.Opcode op;
Term(out e0);
if (StartOf(14)) {
RelOp(out x, out op);
@@ -1403,206 +1434,206 @@ List<Expression!>! decreases) {
}
}
- static void AndOp() {
- if (t.kind == 66) {
+ void AndOp() {
+ if (la.kind == 66) {
Get();
- } else if (t.kind == 67) {
+ } else if (la.kind == 67) {
Get();
- } else Error(124);
+ } else SynErr(124);
}
- static void OrOp() {
- if (t.kind == 68) {
+ void OrOp() {
+ if (la.kind == 68) {
Get();
- } else if (t.kind == 69) {
+ } else if (la.kind == 69) {
Get();
- } else Error(125);
+ } else SynErr(125);
}
- static void Term(out Expression! e0) {
- Token! x; Expression! e1; BinaryExpr.Opcode op;
+ void Term(out Expression! e0) {
+ IToken! x; Expression! e1; BinaryExpr.Opcode op;
Factor(out e0);
- while (t.kind == 79 || t.kind == 80) {
+ while (la.kind == 79 || la.kind == 80) {
AddOp(out x, out op);
Factor(out e1);
e0 = new BinaryExpr(x, op, e0, e1);
}
}
- static void RelOp(out Token! x, out BinaryExpr.Opcode op) {
+ void RelOp(out IToken! x, out BinaryExpr.Opcode op) {
x = Token.NoToken; op = BinaryExpr.Opcode.Add/*(dummy)*/;
- switch (t.kind) {
+ switch (la.kind) {
case 70: {
Get();
- x = token; op = BinaryExpr.Opcode.Eq;
+ x = t; op = BinaryExpr.Opcode.Eq;
break;
}
case 17: {
Get();
- x = token; op = BinaryExpr.Opcode.Lt;
+ x = t; op = BinaryExpr.Opcode.Lt;
break;
}
case 18: {
Get();
- x = token; op = BinaryExpr.Opcode.Gt;
+ x = t; op = BinaryExpr.Opcode.Gt;
break;
}
case 71: {
Get();
- x = token; op = BinaryExpr.Opcode.Le;
+ x = t; op = BinaryExpr.Opcode.Le;
break;
}
case 72: {
Get();
- x = token; op = BinaryExpr.Opcode.Ge;
+ x = t; op = BinaryExpr.Opcode.Ge;
break;
}
case 73: {
Get();
- x = token; op = BinaryExpr.Opcode.Neq;
+ x = t; op = BinaryExpr.Opcode.Neq;
break;
}
case 74: {
Get();
- x = token; op = BinaryExpr.Opcode.Disjoint;
+ x = t; op = BinaryExpr.Opcode.Disjoint;
break;
}
case 55: {
Get();
- x = token; op = BinaryExpr.Opcode.In;
+ x = t; op = BinaryExpr.Opcode.In;
break;
}
case 75: {
Get();
- x = token; op = BinaryExpr.Opcode.NotIn;
+ x = t; op = BinaryExpr.Opcode.NotIn;
break;
}
case 76: {
Get();
- x = token; op = BinaryExpr.Opcode.Neq;
+ x = t; op = BinaryExpr.Opcode.Neq;
break;
}
case 77: {
Get();
- x = token; op = BinaryExpr.Opcode.Le;
+ x = t; op = BinaryExpr.Opcode.Le;
break;
}
case 78: {
Get();
- x = token; op = BinaryExpr.Opcode.Ge;
+ x = t; op = BinaryExpr.Opcode.Ge;
break;
}
- default: Error(126); break;
+ default: SynErr(126); break;
}
}
- static void Factor(out Expression! e0) {
- Token! x; Expression! e1; BinaryExpr.Opcode op;
+ void Factor(out Expression! e0) {
+ IToken! x; Expression! e1; BinaryExpr.Opcode op;
UnaryExpression(out e0);
- while (t.kind == 36 || t.kind == 81 || t.kind == 82) {
+ while (la.kind == 36 || la.kind == 81 || la.kind == 82) {
MulOp(out x, out op);
UnaryExpression(out e1);
e0 = new BinaryExpr(x, op, e0, e1);
}
}
- static void AddOp(out Token! x, out BinaryExpr.Opcode op) {
+ void AddOp(out IToken! x, out BinaryExpr.Opcode op) {
x = Token.NoToken; op=BinaryExpr.Opcode.Add/*(dummy)*/;
- if (t.kind == 79) {
+ if (la.kind == 79) {
Get();
- x = token; op = BinaryExpr.Opcode.Add;
- } else if (t.kind == 80) {
+ x = t; op = BinaryExpr.Opcode.Add;
+ } else if (la.kind == 80) {
Get();
- x = token; op = BinaryExpr.Opcode.Sub;
- } else Error(127);
+ x = t; op = BinaryExpr.Opcode.Sub;
+ } else SynErr(127);
}
- static void UnaryExpression(out Expression! e) {
- Token! x; e = dummyExpr;
- if (t.kind == 80) {
+ void UnaryExpression(out Expression! e) {
+ IToken! x; e = dummyExpr;
+ if (la.kind == 80) {
Get();
- x = token;
+ x = t;
UnaryExpression(out e);
e = new BinaryExpr(x, BinaryExpr.Opcode.Sub, new LiteralExpr(x, 0), e);
- } else if (t.kind == 83 || t.kind == 84) {
+ } else if (la.kind == 83 || la.kind == 84) {
NegOp();
- x = token;
+ x = t;
UnaryExpression(out e);
e = new UnaryExpr(x, UnaryExpr.Opcode.Not, e);
} else if (StartOf(12)) {
SelectExpression(out e);
} else if (StartOf(15)) {
ConstAtomExpression(out e);
- } else Error(128);
+ } else SynErr(128);
}
- static void MulOp(out Token! x, out BinaryExpr.Opcode op) {
+ void MulOp(out IToken! x, out BinaryExpr.Opcode op) {
x = Token.NoToken; op = BinaryExpr.Opcode.Add/*(dummy)*/;
- if (t.kind == 36) {
+ if (la.kind == 36) {
Get();
- x = token; op = BinaryExpr.Opcode.Mul;
- } else if (t.kind == 81) {
+ x = t; op = BinaryExpr.Opcode.Mul;
+ } else if (la.kind == 81) {
Get();
- x = token; op = BinaryExpr.Opcode.Div;
- } else if (t.kind == 82) {
+ x = t; op = BinaryExpr.Opcode.Div;
+ } else if (la.kind == 82) {
Get();
- x = token; op = BinaryExpr.Opcode.Mod;
- } else Error(129);
+ x = t; op = BinaryExpr.Opcode.Mod;
+ } else SynErr(129);
}
- static void NegOp() {
- if (t.kind == 83) {
+ void NegOp() {
+ if (la.kind == 83) {
Get();
- } else if (t.kind == 84) {
+ } else if (la.kind == 84) {
Get();
- } else Error(130);
+ } else SynErr(130);
}
- static void ConstAtomExpression(out Expression! e) {
- Token! x, dtName, id; BigInteger n; List<Expression!>! elements;
+ void ConstAtomExpression(out Expression! e) {
+ IToken! x, dtName, id; BigInteger n; List<Expression!>! elements;
e = dummyExpr;
- switch (t.kind) {
+ switch (la.kind) {
case 85: {
Get();
- e = new LiteralExpr(token, false);
+ e = new LiteralExpr(t, false);
break;
}
case 86: {
Get();
- e = new LiteralExpr(token, true);
+ e = new LiteralExpr(t, true);
break;
}
case 87: {
Get();
- e = new LiteralExpr(token);
+ e = new LiteralExpr(t);
break;
}
case 2: {
Nat(out n);
- e = new LiteralExpr(token, n);
+ e = new LiteralExpr(t, n);
break;
}
case 88: {
Get();
- x = token;
+ x = t;
Ident(out dtName);
Expect(89);
Ident(out id);
elements = new List<Expression!>();
- if (t.kind == 26) {
+ if (la.kind == 26) {
Get();
if (StartOf(7)) {
Expressions(elements);
}
Expect(27);
}
- e = new DatatypeValue(token, dtName.val, id.val, elements);
+ e = new DatatypeValue(t, dtName.val, id.val, elements);
break;
}
case 90: {
Get();
- x = token;
+ x = t;
Expect(26);
Expression(out e);
Expect(27);
@@ -1611,7 +1642,7 @@ List<Expression!>! decreases) {
}
case 56: {
Get();
- x = token;
+ x = t;
Expression(out e);
e = new UnaryExpr(x, UnaryExpr.Opcode.SeqLength, e);
Expect(56);
@@ -1619,7 +1650,7 @@ List<Expression!>! decreases) {
}
case 6: {
Get();
- x = token; elements = new List<Expression!>();
+ x = t; elements = new List<Expression!>();
if (StartOf(7)) {
Expressions(elements);
}
@@ -1629,7 +1660,7 @@ List<Expression!>! decreases) {
}
case 46: {
Get();
- x = token; elements = new List<Expression!>();
+ x = t; elements = new List<Expression!>();
if (StartOf(7)) {
Expressions(elements);
}
@@ -1637,14 +1668,14 @@ List<Expression!>! decreases) {
Expect(47);
break;
}
- default: Error(131); break;
+ default: SynErr(131); break;
}
}
- static void Nat(out BigInteger n) {
+ void Nat(out BigInteger n) {
Expect(2);
try {
- n = BigInteger.Parse(token.val);
+ n = BigInteger.Parse(t.val);
} catch (System.FormatException) {
SemErr("incorrectly formatted number");
n = BigInteger.Zero;
@@ -1652,10 +1683,10 @@ List<Expression!>! decreases) {
}
- static void IdentOrFuncExpression(out Expression! e) {
- Token! id; e = dummyExpr; List<Expression!>! args;
+ void IdentOrFuncExpression(out Expression! e) {
+ IToken! id; e = dummyExpr; List<Expression!>! args;
Ident(out id);
- if (t.kind == 26) {
+ if (la.kind == 26) {
Get();
args = new List<Expression!>();
if (StartOf(7)) {
@@ -1674,38 +1705,38 @@ List<Expression!>! decreases) {
}
- static void ObjectExpression(out Expression! e) {
- Token! x; e = dummyExpr;
- if (t.kind == 92) {
+ void ObjectExpression(out Expression! e) {
+ IToken! x; e = dummyExpr;
+ if (la.kind == 92) {
Get();
- e = new ThisExpr(token);
- } else if (t.kind == 93) {
+ e = new ThisExpr(t);
+ } else if (la.kind == 93) {
Get();
- x = token;
+ x = t;
Expect(26);
Expression(out e);
Expect(27);
e = new OldExpr(x, e);
- } else if (t.kind == 26) {
+ } else if (la.kind == 26) {
Get();
if (StartOf(16)) {
QuantifierGuts(out e);
} else if (StartOf(7)) {
Expression(out e);
- } else Error(132);
+ } else SynErr(132);
Expect(27);
- } else Error(133);
+ } else SynErr(133);
}
- static void SelectOrCallSuffix(ref Expression! e) {
- Token! id, x; List<Expression!>! args;
+ void SelectOrCallSuffix(ref Expression! e) {
+ IToken! id, x; List<Expression!>! args;
Expression e0 = null; Expression e1 = null; Expression! ee; bool anyDots = false;
bool func = false;
- if (t.kind == 89) {
+ if (la.kind == 89) {
Get();
Ident(out id);
- if (t.kind == 26) {
+ if (la.kind == 26) {
Get();
args = new List<Expression!>(); func = true;
if (StartOf(7)) {
@@ -1715,14 +1746,14 @@ List<Expression!>! decreases) {
e = new FunctionCallExpr(id, id.val, e, args);
}
if (!func) { e = new FieldSelectExpr(id, e, id.val); }
- } else if (t.kind == 46) {
+ } else if (la.kind == 46) {
Get();
- x = token;
+ x = t;
if (StartOf(7)) {
Expression(out ee);
e0 = ee;
- if (t.kind == 44 || t.kind == 91) {
- if (t.kind == 91) {
+ if (la.kind == 44 || la.kind == 91) {
+ if (la.kind == 91) {
Get();
anyDots = true;
if (StartOf(7)) {
@@ -1735,11 +1766,11 @@ List<Expression!>! decreases) {
e1 = ee;
}
}
- } else if (t.kind == 91) {
+ } else if (la.kind == 91) {
Get();
Expression(out ee);
anyDots = true; e1 = ee;
- } else Error(134);
+ } else SynErr(134);
if (!anyDots && e0 == null) {
/* a parsing error occurred */
e0 = dummyExpr;
@@ -1757,35 +1788,35 @@ List<Expression!>! decreases) {
}
Expect(47);
- } else Error(135);
+ } else SynErr(135);
}
- static void QuantifierGuts(out Expression! q) {
- Token! x = Token.NoToken;
+ void QuantifierGuts(out Expression! q) {
+ IToken! x = Token.NoToken;
bool univ = false;
BoundVar! bv;
List<BoundVar!> bvars = new List<BoundVar!>();
- Token! tok; Expr! e; ExprSeq! es;
+ IToken! tok; Expr! e; ExprSeq! es;
Attributes attrs = null;
Triggers trigs = null;
Expression! body;
- if (t.kind == 94 || t.kind == 95) {
+ if (la.kind == 94 || la.kind == 95) {
Forall();
- x = token; univ = true;
- } else if (t.kind == 96 || t.kind == 97) {
+ x = t; univ = true;
+ } else if (la.kind == 96 || la.kind == 97) {
Exists();
- x = token;
- } else Error(136);
+ x = t;
+ } else SynErr(136);
parseVarScope.PushMarker();
IdentTypeOptional(out bv);
bvars.Add(bv); parseVarScope.Push(bv.Name, bv.Name);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
IdentTypeOptional(out bv);
bvars.Add(bv); parseVarScope.Push(bv.Name, bv.Name);
}
- while (t.kind == 6) {
+ while (la.kind == 6) {
AttributeOrTrigger(ref attrs, ref trigs);
}
QSep();
@@ -1799,56 +1830,56 @@ List<Expression!>! decreases) {
}
- static void Forall() {
- if (t.kind == 94) {
+ void Forall() {
+ if (la.kind == 94) {
Get();
- } else if (t.kind == 95) {
+ } else if (la.kind == 95) {
Get();
- } else Error(137);
+ } else SynErr(137);
}
- static void Exists() {
- if (t.kind == 96) {
+ void Exists() {
+ if (la.kind == 96) {
Get();
- } else if (t.kind == 97) {
+ } else if (la.kind == 97) {
Get();
- } else Error(138);
+ } else SynErr(138);
}
- static void AttributeOrTrigger(ref Attributes attrs, ref Triggers trigs) {
+ void AttributeOrTrigger(ref Attributes attrs, ref Triggers trigs) {
List<Expression!> es = new List<Expression!>();
Expect(6);
- if (t.kind == 16) {
+ if (la.kind == 16) {
AttributeBody(ref attrs);
} else if (StartOf(7)) {
es = new List<Expression!>();
Expressions(es);
trigs = new Triggers(es, trigs);
- } else Error(139);
+ } else SynErr(139);
Expect(7);
}
- static void QSep() {
- if (t.kind == 98) {
+ void QSep() {
+ if (la.kind == 98) {
Get();
- } else if (t.kind == 99) {
+ } else if (la.kind == 99) {
Get();
- } else Error(140);
+ } else SynErr(140);
}
- static void AttributeBody(ref Attributes attrs) {
+ void AttributeBody(ref Attributes attrs) {
string aName;
List<Attributes.Argument!> aArgs = new List<Attributes.Argument!>();
Attributes.Argument! aArg;
Expect(16);
Expect(1);
- aName = token.val;
+ aName = t.val;
if (StartOf(17)) {
AttributeArg(out aArg);
aArgs.Add(aArg);
- while (t.kind == 15) {
+ while (la.kind == 15) {
Get();
AttributeArg(out aArg);
aArgs.Add(aArg);
@@ -1859,120 +1890,150 @@ List<Expression!>! decreases) {
- public static void Parse() {
- Errors.SynErr = new ErrorProc(SynErr);
- t = new Token();
+ public void Parse() {
+ la = new Token();
+ la.val = "";
Get();
Dafny();
+ Expect(0);
}
+
+ static readonly bool[,]! set = {
+ {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, T,x,x,x, T,T,T,T, T,x,T,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,x,x, x,T,T,T, x,x,T,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,T,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,T,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, T,x,T,x, T,T,x,x, x,x,x,x, x,x},
+ {x,T,x,x, x,x,T,x, x,T,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,T,T, x,x,x,x, T,T,x,T, x,T,T,x, x,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x},
+ {x,T,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, T,x,T,x, T,T,x,x, x,x,x,x, x,x},
+ {x,T,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,T,x, x,T,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, T,x,T,x, T,T,x,x, x,x,x,x, x,x},
+ {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,T,T, x,x,x,x, T,T,x,T, x,T,T,x, x,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x},
+ {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,x,T,x, x,x,x,x, x,x,x,x, x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,x, x,x},
+ {x,T,T,T, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, T,x,T,x, T,T,x,x, x,x,x,x, x,x}
- [Microsoft.Contracts.Verify(false)]
- static void SynErr(int n, string filename, int line, int col) {
- Errors.count++;
- System.Console.Write("{0}({1},{2}): syntax error: ", filename, line, col);
+ };
+} // end Parser
+
+
+public class Errors {
+ public int count = 0; // number of errors detected
+ public System.IO.TextWriter! errorStream = Console.Out; // error messages go to this stream
+// public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
+ public string! errMsgFormat4 = "{0}({1},{2}): Error: {3}"; // 0=line, 1=column, 2=text
+ public string! errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
+
+ public void SynErr (string filename, int line, int col, int n) {
string s;
+ Console.Write("{0}({1},{2}): syntax error: ", filename, line, col);
switch (n) {
case 0: s = "EOF expected"; break;
case 1: s = "ident expected"; break;
case 2: s = "digits expected"; break;
case 3: s = "string expected"; break;
- case 4: s = "module expected"; break;
- case 5: s = "imports expected"; break;
- case 6: s = "{ expected"; break;
- case 7: s = "} expected"; break;
- case 8: s = "class expected"; break;
- case 9: s = "ghost expected"; break;
- case 10: s = "static expected"; break;
- case 11: s = "unlimited expected"; break;
- case 12: s = "datatype expected"; break;
- case 13: s = "; expected"; break;
- case 14: s = "var expected"; break;
- case 15: s = ", expected"; break;
- case 16: s = ": expected"; break;
- case 17: s = "< expected"; break;
- case 18: s = "> expected"; break;
- case 19: s = "method expected"; break;
- case 20: s = "returns expected"; break;
- case 21: s = "modifies expected"; break;
- case 22: s = "free expected"; break;
- case 23: s = "requires expected"; break;
- case 24: s = "ensures expected"; break;
- case 25: s = "decreases expected"; break;
- case 26: s = "( expected"; break;
- case 27: s = ") expected"; break;
- case 28: s = "bool expected"; break;
- case 29: s = "int expected"; break;
- case 30: s = "set expected"; break;
- case 31: s = "seq expected"; break;
- case 32: s = "object expected"; break;
- case 33: s = "array expected"; break;
- case 34: s = "function expected"; break;
- case 35: s = "reads expected"; break;
- case 36: s = "* expected"; break;
- case 37: s = "` expected"; break;
- case 38: s = "match expected"; break;
- case 39: s = "case expected"; break;
- case 40: s = "=> expected"; break;
- case 41: s = "label expected"; break;
- case 42: s = "break expected"; break;
- case 43: s = "return expected"; break;
- case 44: s = ":= expected"; break;
- case 45: s = "new expected"; break;
- case 46: s = "[ expected"; break;
- case 47: s = "] expected"; break;
- case 48: s = "havoc expected"; break;
- case 49: s = "if expected"; break;
- case 50: s = "else expected"; break;
- case 51: s = "while expected"; break;
- case 52: s = "invariant expected"; break;
- case 53: s = "call expected"; break;
- case 54: s = "foreach expected"; break;
- case 55: s = "in expected"; break;
- case 56: s = "| expected"; break;
- case 57: s = "assert expected"; break;
- case 58: s = "assume expected"; break;
- case 59: s = "use expected"; break;
- case 60: s = "print expected"; break;
- case 61: s = "then expected"; break;
- case 62: s = "<==> expected"; break;
- case 63: s = "\\u21d4 expected"; break;
- case 64: s = "==> expected"; break;
- case 65: s = "\\u21d2 expected"; break;
- case 66: s = "&& expected"; break;
- case 67: s = "\\u2227 expected"; break;
- case 68: s = "|| expected"; break;
- case 69: s = "\\u2228 expected"; break;
- case 70: s = "== expected"; break;
- case 71: s = "<= expected"; break;
- case 72: s = ">= expected"; break;
- case 73: s = "!= expected"; break;
- case 74: s = "!! expected"; break;
- case 75: s = "!in expected"; break;
- case 76: s = "\\u2260 expected"; break;
- case 77: s = "\\u2264 expected"; break;
- case 78: s = "\\u2265 expected"; break;
- case 79: s = "+ expected"; break;
- case 80: s = "- expected"; break;
- case 81: s = "/ expected"; break;
- case 82: s = "% expected"; break;
- case 83: s = "! expected"; break;
- case 84: s = "\\u00ac expected"; break;
- case 85: s = "false expected"; break;
- case 86: s = "true expected"; break;
- case 87: s = "null expected"; break;
- case 88: s = "# expected"; break;
- case 89: s = ". expected"; break;
- case 90: s = "fresh expected"; break;
- case 91: s = ".. expected"; break;
- case 92: s = "this expected"; break;
- case 93: s = "old expected"; break;
- case 94: s = "forall expected"; break;
- case 95: s = "\\u2200 expected"; break;
- case 96: s = "exists expected"; break;
- case 97: s = "\\u2203 expected"; break;
- case 98: s = ":: expected"; break;
- case 99: s = "\\u2022 expected"; break;
+ case 4: s = "\"module\" expected"; break;
+ case 5: s = "\"imports\" expected"; break;
+ case 6: s = "\"{\" expected"; break;
+ case 7: s = "\"}\" expected"; break;
+ case 8: s = "\"class\" expected"; break;
+ case 9: s = "\"ghost\" expected"; break;
+ case 10: s = "\"static\" expected"; break;
+ case 11: s = "\"unlimited\" expected"; break;
+ case 12: s = "\"datatype\" expected"; break;
+ case 13: s = "\";\" expected"; break;
+ case 14: s = "\"var\" expected"; break;
+ case 15: s = "\",\" expected"; break;
+ case 16: s = "\":\" expected"; break;
+ case 17: s = "\"<\" expected"; break;
+ case 18: s = "\">\" expected"; break;
+ case 19: s = "\"method\" expected"; break;
+ case 20: s = "\"returns\" expected"; break;
+ case 21: s = "\"modifies\" expected"; break;
+ case 22: s = "\"free\" expected"; break;
+ case 23: s = "\"requires\" expected"; break;
+ case 24: s = "\"ensures\" expected"; break;
+ case 25: s = "\"decreases\" expected"; break;
+ case 26: s = "\"(\" expected"; break;
+ case 27: s = "\")\" expected"; break;
+ case 28: s = "\"bool\" expected"; break;
+ case 29: s = "\"int\" expected"; break;
+ case 30: s = "\"set\" expected"; break;
+ case 31: s = "\"seq\" expected"; break;
+ case 32: s = "\"object\" expected"; break;
+ case 33: s = "\"array\" expected"; break;
+ case 34: s = "\"function\" expected"; break;
+ case 35: s = "\"reads\" expected"; break;
+ case 36: s = "\"*\" expected"; break;
+ case 37: s = "\"`\" expected"; break;
+ case 38: s = "\"match\" expected"; break;
+ case 39: s = "\"case\" expected"; break;
+ case 40: s = "\"=>\" expected"; break;
+ case 41: s = "\"label\" expected"; break;
+ case 42: s = "\"break\" expected"; break;
+ case 43: s = "\"return\" expected"; break;
+ case 44: s = "\":=\" expected"; break;
+ case 45: s = "\"new\" expected"; break;
+ case 46: s = "\"[\" expected"; break;
+ case 47: s = "\"]\" expected"; break;
+ case 48: s = "\"havoc\" expected"; break;
+ case 49: s = "\"if\" expected"; break;
+ case 50: s = "\"else\" expected"; break;
+ case 51: s = "\"while\" expected"; break;
+ case 52: s = "\"invariant\" expected"; break;
+ case 53: s = "\"call\" expected"; break;
+ case 54: s = "\"foreach\" expected"; break;
+ case 55: s = "\"in\" expected"; break;
+ case 56: s = "\"|\" expected"; break;
+ case 57: s = "\"assert\" expected"; break;
+ case 58: s = "\"assume\" expected"; break;
+ case 59: s = "\"use\" expected"; break;
+ case 60: s = "\"print\" expected"; break;
+ case 61: s = "\"then\" expected"; break;
+ case 62: s = "\"<==>\" expected"; break;
+ case 63: s = "\"\\u21d4\" expected"; break;
+ case 64: s = "\"==>\" expected"; break;
+ case 65: s = "\"\\u21d2\" expected"; break;
+ case 66: s = "\"&&\" expected"; break;
+ case 67: s = "\"\\u2227\" expected"; break;
+ case 68: s = "\"||\" expected"; break;
+ case 69: s = "\"\\u2228\" expected"; break;
+ case 70: s = "\"==\" expected"; break;
+ case 71: s = "\"<=\" expected"; break;
+ case 72: s = "\">=\" expected"; break;
+ case 73: s = "\"!=\" expected"; break;
+ case 74: s = "\"!!\" expected"; break;
+ case 75: s = "\"!in\" expected"; break;
+ case 76: s = "\"\\u2260\" expected"; break;
+ case 77: s = "\"\\u2264\" expected"; break;
+ case 78: s = "\"\\u2265\" expected"; break;
+ case 79: s = "\"+\" expected"; break;
+ case 80: s = "\"-\" expected"; break;
+ case 81: s = "\"/\" expected"; break;
+ case 82: s = "\"%\" expected"; break;
+ case 83: s = "\"!\" expected"; break;
+ case 84: s = "\"\\u00ac\" expected"; break;
+ case 85: s = "\"false\" expected"; break;
+ case 86: s = "\"true\" expected"; break;
+ case 87: s = "\"null\" expected"; break;
+ case 88: s = "\"#\" expected"; break;
+ case 89: s = "\".\" expected"; break;
+ case 90: s = "\"fresh\" expected"; break;
+ case 91: s = "\"..\" expected"; break;
+ case 92: s = "\"this\" expected"; break;
+ case 93: s = "\"old\" expected"; break;
+ case 94: s = "\"forall\" expected"; break;
+ case 95: s = "\"\\u2200\" expected"; break;
+ case 96: s = "\"exists\" expected"; break;
+ case 97: s = "\"\\u2203\" expected"; break;
+ case 98: s = "\"::\" expected"; break;
+ case 99: s = "\"\\u2022\" expected"; break;
case 100: s = "??? expected"; break;
case 101: s = "invalid ClassMemberDecl"; break;
case 102: s = "invalid FunctionDecl"; break;
@@ -2017,33 +2078,42 @@ List<Expression!>! decreases) {
default: s = "error " + n; break;
}
- System.Console.WriteLine(s);
- }
-
- static bool[,]! set = {
- {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, T,x,x,x, T,T,T,T, T,x,T,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,x,x, x,T,T,T, x,x,T,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,T,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,T,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, T,x,T,x, T,T,x,x, x,x,x,x, x,x},
- {x,T,x,x, x,x,T,x, x,T,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,T,T, x,x,x,x, T,T,x,T, x,T,T,x, x,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x},
- {x,T,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, T,x,T,x, T,T,x,x, x,x,x,x, x,x},
- {x,T,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,T,x, x,T,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, T,x,T,x, T,T,x,x, x,x,x,x, x,x},
- {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,T,T, x,x,x,x, T,T,x,T, x,T,T,x, x,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x},
- {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,x,T,x, x,x,x,x, x,x,x,x, x,x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,x, x,x},
- {x,T,T,T, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,T,T,T, T,x,T,x, T,T,x,x, x,x,x,x, x,x}
+ //errorStream.WriteLine(errMsgFormat, line, col, s);
+ errorStream.WriteLine(s);
+ count++;
+ }
- };
+ public void SemErr (int line, int col, string! s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ count++;
+ }
- [Microsoft.Contracts.Verify(false)]
- static Parser() {}
-} // end Parser
+ public void SemErr (string filename, int line, int col, string! s) {
+ errorStream.WriteLine(errMsgFormat4, filename, line, col, s);
+ count++;
+ }
+
+ public void SemErr (string s) {
+ errorStream.WriteLine(s);
+ count++;
+ }
+
+ public void SemErr(IToken! tok, string! msg) { // semantic errors
+ SemErr(tok.filename, tok.line, tok.col, msg);
+ }
+
+ public void Warning (int line, int col, string s) {
+ errorStream.WriteLine(errMsgFormat, line, col, s);
+ }
+
+ public void Warning(string s) {
+ errorStream.WriteLine(s);
+ }
+} // Errors
+
+
+public class FatalError: Exception {
+ public FatalError(string m): base(m) {}
+}
-} // end namespace
+} \ No newline at end of file
diff --git a/Source/Dafny/Resolver.ssc b/Source/Dafny/Resolver.ssc
index 671469f3..701668db 100644
--- a/Source/Dafny/Resolver.ssc
+++ b/Source/Dafny/Resolver.ssc
@@ -7,11 +7,12 @@ using System;
using System.Collections.Generic;
using System.Numerics;
using Microsoft.Contracts;
+using Microsoft.Boogie;
namespace Microsoft.Dafny {
public class Resolver {
public int ErrorCount = 0;
- void Error(Token! tok, string! msg, params object[] args) {
+ void Error(IToken! tok, string! msg, params object[] args) {
ConsoleColor col = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("{0}({1},{2}): Error: {3}",
@@ -1370,7 +1371,7 @@ namespace Microsoft.Dafny {
return rr.EType;
}
- MemberDecl ResolveMember(Token! tok, Type! receiverType, string! memberName, out UserDefinedType ctype)
+ MemberDecl ResolveMember(IToken! tok, Type! receiverType, string! memberName, out UserDefinedType ctype)
ensures result != null ==> ctype != null && ctype.ResolvedClass != null;
{
ctype = UserDefinedType.DenotesClass(receiverType);
@@ -1455,7 +1456,7 @@ namespace Microsoft.Dafny {
}
}
- public static UserDefinedType! GetThisType(Token! tok, ClassDecl! cl) {
+ public static UserDefinedType! GetThisType(IToken! tok, ClassDecl! cl) {
List<Type!> args = new List<Type!>();
foreach (TypeParameter tp in cl.TypeArgs) {
args.Add(new UserDefinedType(tok, tp.Name, tp));
diff --git a/Source/Dafny/Scanner.ssc b/Source/Dafny/Scanner.ssc
index 5fdeefed..98114e54 100644
--- a/Source/Dafny/Scanner.ssc
+++ b/Source/Dafny/Scanner.ssc
@@ -1,248 +1,437 @@
+
+using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Microsoft.Contracts;
-using Bpl = Microsoft.Boogie;
+using Microsoft.Boogie;
using BoogiePL;
+namespace Microsoft.Dafny {
-namespace Microsoft.Dafny {
+//-----------------------------------------------------------------------------------
+// Buffer
+//-----------------------------------------------------------------------------------
+public class Buffer {
+ // This Buffer supports the following cases:
+ // 1) seekable stream (file)
+ // a) whole stream in buffer
+ // b) part of stream in buffer
+ // 2) non seekable stream (network, console)
+
+ public const int EOF = 65535 + 1; // char.MaxValue + 1;
+ const int MIN_BUFFER_LENGTH = 1024; // 1KB
+ const int MAX_BUFFER_LENGTH = MIN_BUFFER_LENGTH * 64; // 64KB
+ byte[]! buf; // input buffer
+ int bufStart; // position of first byte in buffer relative to input stream
+ int bufLen; // length of buffer
+ int fileLen; // length of input stream (may change if the stream is no file)
+ int bufPos; // current position in buffer
+ Stream! stream; // input stream (seekable)
+ bool isUserStream; // was the stream opened by the user?
+
+ [NotDelayed]
+ public Buffer (Stream! s, bool isUserStream) {
+ stream = s; this.isUserStream = isUserStream;
+
+ int fl, bl;
+ if (s.CanSeek) {
+ fl = (int) s.Length;
+ bl = fl < MAX_BUFFER_LENGTH ? fl : MAX_BUFFER_LENGTH; // Math.Min(fileLen, MAX_BUFFER_LENGTH);
+ bufStart = Int32.MaxValue; // nothing in the buffer so far
+ } else {
+ fl = bl = bufStart = 0;
+ }
+
+ buf = new byte[(bl>0) ? bl : MIN_BUFFER_LENGTH];
+ fileLen = fl; bufLen = bl;
+ base();
+ if (fileLen > 0) Pos = 0; // setup buffer to position 0 (start)
+ else bufPos = 0; // index 0 is already after the file, thus Pos = 0 is invalid
+ if (bufLen == fileLen && s.CanSeek) Close();
+ }
+
+ protected Buffer(Buffer! b) { // called in UTF8Buffer constructor
+ buf = b.buf;
+ bufStart = b.bufStart;
+ bufLen = b.bufLen;
+ fileLen = b.fileLen;
+ bufPos = b.bufPos;
+ stream = b.stream;
+ // keep destructor from closing the stream
+ //b.stream = null;
+ isUserStream = b.isUserStream;
+ // keep destructor from closing the stream
+ b.isUserStream = true;
+ }
+
+ ~Buffer() { Close(); }
+
+ protected void Close() {
+ if (!isUserStream && stream != null) {
+ stream.Close();
+ //stream = null;
+ }
+ }
+
+ public virtual int Read () {
+ if (bufPos < bufLen) {
+ return buf[bufPos++];
+ } else if (Pos < fileLen) {
+ Pos = Pos; // shift buffer start to Pos
+ return buf[bufPos++];
+ } else if (stream != null && !stream.CanSeek && ReadNextStreamChunk() > 0) {
+ return buf[bufPos++];
+ } else {
+ return EOF;
+ }
+ }
+
+ public int Peek () {
+ int curPos = Pos;
+ int ch = Read();
+ Pos = curPos;
+ return ch;
+ }
+
+ public string! GetString (int beg, int end) {
+ int len = 0;
+ char[] buf = new char[end - beg];
+ int oldPos = Pos;
+ Pos = beg;
+ while (Pos < end) buf[len++] = (char) Read();
+ Pos = oldPos;
+ return new String(buf, 0, len);
+ }
+
+ public int Pos {
+ get { return bufPos + bufStart; }
+ set {
+ if (value >= fileLen && stream != null && !stream.CanSeek) {
+ // Wanted position is after buffer and the stream
+ // is not seek-able e.g. network or console,
+ // thus we have to read the stream manually till
+ // the wanted position is in sight.
+ while (value >= fileLen && ReadNextStreamChunk() > 0);
+ }
- [Immutable]
- public class Token : Bpl.Token {
- public Token();
- public Token(int linenum, int colnum) {
- base(linenum, colnum);
- }
- public new static Token! NoToken = new Token();
- }
+ if (value < 0 || value > fileLen) {
+ throw new FatalError("buffer out of bounds access, position: " + value);
+ }
+ if (value >= bufStart && value < bufStart + bufLen) { // already in buffer
+ bufPos = value - bufStart;
+ } else if (stream != null) { // must be swapped in
+ stream.Seek(value, SeekOrigin.Begin);
+ bufLen = stream.Read(buf, 0, buf.Length);
+ bufStart = value; bufPos = 0;
+ } else {
+ // set the position to the end of the file, Pos will return fileLen.
+ bufPos = fileLen - bufStart;
+ }
+ }
+ }
+
+ // Read the next chunk of bytes from the stream, increases the buffer
+ // if needed and updates the fields fileLen and bufLen.
+ // Returns the number of bytes read.
+ private int ReadNextStreamChunk() {
+ int free = buf.Length - bufLen;
+ if (free == 0) {
+ // in the case of a growing input stream
+ // we can neither seek in the stream, nor can we
+ // foresee the maximum length, thus we must adapt
+ // the buffer size on demand.
+ byte[] newBuf = new byte[bufLen * 2];
+ Array.Copy(buf, newBuf, bufLen);
+ buf = newBuf;
+ free = bufLen;
+ }
+ int read = stream.Read(buf, bufLen, free);
+ if (read > 0) {
+ fileLen = bufLen = (bufLen + read);
+ return read;
+ }
+ // end of stream reached
+ return 0;
+ }
}
-namespace Microsoft.Dafny {
+//-----------------------------------------------------------------------------------
+// UTF8Buffer
+//-----------------------------------------------------------------------------------
+public class UTF8Buffer: Buffer {
+ public UTF8Buffer(Buffer! b): base(b) {}
+ public override int Read() {
+ int ch;
+ do {
+ ch = base.Read();
+ // until we find a utf8 start (0xxxxxxx or 11xxxxxx)
+ } while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EOF));
+ if (ch < 128 || ch == EOF) {
+ // nothing to do, first 127 chars are the same in ascii and utf8
+ // 0xxxxxxx or end of file character
+ } else if ((ch & 0xF0) == 0xF0) {
+ // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x07; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F; ch = base.Read();
+ int c4 = ch & 0x3F;
+ ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
+ } else if ((ch & 0xE0) == 0xE0) {
+ // 1110xxxx 10xxxxxx 10xxxxxx
+ int c1 = ch & 0x0F; ch = base.Read();
+ int c2 = ch & 0x3F; ch = base.Read();
+ int c3 = ch & 0x3F;
+ ch = (((c1 << 6) | c2) << 6) | c3;
+ } else if ((ch & 0xC0) == 0xC0) {
+ // 110xxxxx 10xxxxxx
+ int c1 = ch & 0x1F; ch = base.Read();
+ int c2 = ch & 0x3F;
+ ch = (c1 << 6) | c2;
+ }
+ return ch;
+ }
+}
+//-----------------------------------------------------------------------------------
+// Scanner
+//-----------------------------------------------------------------------------------
public class Scanner {
- const char EOF = '\0';
- const char CR = '\r';
- const char LF = '\n';
+ const char EOL = '\n';
+ const int eofSym = 0; /* pdt */
+ const int maxT = 100;
+ const int noSym = 100;
+
+
+ public Buffer! buffer; // scanner buffer
+
+ Token! t; // current token
+ int ch; // current input character
+ int pos; // byte position of current character
+ int col; // column number of current character
+ int line; // line number of current character
+ int oldEols; // EOLs that appeared in a comment;
+ static readonly Hashtable! start; // maps first token character to start state
- [Microsoft.Contracts.Verify(false)]
+ Token! tokens; // list of tokens already peeked (first token is a dummy)
+ Token! pt; // current peek token
+
+ char[]! tval = new char[128]; // text of current token
+ int tlen; // length of current token
+
+ private string! Filename;
+ private Errors! errorHandler;
+
static Scanner() {
- start[0] = 55;
- start[33] = 35;
- start[34] = 3;
- start[35] = 48;
- start[37] = 46;
- start[38] = 29;
- start[39] = 1;
- start[40] = 12;
- start[41] = 13;
- start[42] = 14;
- start[43] = 43;
- start[44] = 8;
- start[45] = 44;
- start[46] = 49;
- start[47] = 45;
- start[48] = 2;
- start[49] = 2;
- start[50] = 2;
- start[51] = 2;
- start[52] = 2;
- start[53] = 2;
- start[54] = 2;
- start[55] = 2;
- start[56] = 2;
- start[57] = 2;
- start[58] = 9;
- start[59] = 7;
- start[60] = 10;
- start[61] = 16;
- start[62] = 11;
- start[63] = 1;
- start[65] = 1;
- start[66] = 1;
- start[67] = 1;
- start[68] = 1;
- start[69] = 1;
- start[70] = 1;
- start[71] = 1;
- start[72] = 1;
- start[73] = 1;
- start[74] = 1;
- start[75] = 1;
- start[76] = 1;
- start[77] = 1;
- start[78] = 1;
- start[79] = 1;
- start[80] = 1;
- start[81] = 1;
- start[82] = 1;
- start[83] = 1;
- start[84] = 1;
- start[85] = 1;
- start[86] = 1;
- start[87] = 1;
- start[88] = 1;
- start[89] = 1;
- start[90] = 1;
- start[91] = 19;
- start[92] = 1;
- start[93] = 20;
- start[95] = 1;
- start[96] = 15;
- start[97] = 1;
- start[98] = 1;
- start[99] = 1;
- start[100] = 1;
- start[101] = 1;
- start[102] = 1;
- start[103] = 1;
- start[104] = 1;
- start[105] = 1;
- start[106] = 1;
- start[107] = 1;
- start[108] = 1;
- start[109] = 1;
- start[110] = 1;
- start[111] = 1;
- start[112] = 1;
- start[113] = 1;
- start[114] = 1;
- start[115] = 1;
- start[116] = 1;
- start[117] = 1;
- start[118] = 1;
- start[119] = 1;
- start[120] = 1;
- start[121] = 1;
- start[122] = 1;
- start[123] = 5;
- start[124] = 21;
- start[125] = 6;
- start[172] = 47;
- start[8226] = 54;
- start[8658] = 28;
- start[8660] = 25;
- start[8704] = 51;
- start[8707] = 52;
- start[8743] = 31;
- start[8744] = 33;
- start[8800] = 40;
- start[8804] = 41;
- start[8805] = 42;
+ start = new Hashtable(128);
+ for (int i = 39; i <= 39; ++i) start[i] = 1;
+ for (int i = 63; i <= 63; ++i) start[i] = 1;
+ for (int i = 65; i <= 90; ++i) start[i] = 1;
+ for (int i = 92; i <= 92; ++i) start[i] = 1;
+ for (int i = 95; i <= 95; ++i) start[i] = 1;
+ for (int i = 97; i <= 122; ++i) start[i] = 1;
+ for (int i = 48; i <= 57; ++i) start[i] = 2;
+ for (int i = 34; i <= 34; ++i) start[i] = 3;
+ start[123] = 5;
+ start[125] = 6;
+ start[59] = 7;
+ start[44] = 8;
+ start[58] = 46;
+ start[60] = 47;
+ start[62] = 48;
+ start[40] = 9;
+ start[41] = 10;
+ start[42] = 11;
+ start[96] = 12;
+ start[61] = 49;
+ start[91] = 15;
+ start[93] = 16;
+ start[124] = 50;
+ start[8660] = 19;
+ start[8658] = 21;
+ start[38] = 22;
+ start[8743] = 24;
+ start[8744] = 26;
+ start[33] = 51;
+ start[8800] = 32;
+ start[8804] = 33;
+ start[8805] = 34;
+ start[43] = 35;
+ start[45] = 36;
+ start[47] = 37;
+ start[37] = 38;
+ start[172] = 39;
+ start[35] = 40;
+ start[46] = 52;
+ start[8704] = 42;
+ start[8707] = 43;
+ start[8226] = 45;
+ start[Buffer.EOF] = -1;
+
}
- const int noSym = 100;
- static short[] start = new short[16385];
-
-
-
- static Token/*!*/ t; // current token
- static char ch; // current input character
- static int pos; // column number of current character
- static int line; // line number of current character
- static int lineStart; // start position of current line
- static Queue! oldEols; // EOLs that appeared in a comment;
- static BitArray/*!*/ ignore; // set of characters to be ignored by the scanner
- static string Filename;
-
- ///<summary>
- ///Initializes the scanner. Note: first fill the Buffer.
- ///</summary>
- ///<param name="filename">File name used for error reporting</param>
- public static void Init (string filename) {
- Filename = filename;
- pos = -1; line = 1; lineStart = 0;
- oldEols = new Queue();
- NextCh();
- ignore = new BitArray(16384);
- ignore[9] = true; ignore[10] = true; ignore[13] = true; ignore[32] = true;
-
- }
-
- private static void NextCh() {
- if (oldEols.Count > 0) {
- ch = (char) ((!)oldEols.Dequeue());
- } else {
- while (true) {
- ch = (char)BoogiePL.Buffer.Read(); pos++;
- if (ch == BoogiePL.Buffer.eof) {
- ch = EOF;
- } else if (ch == LF) {
- line++;
- lineStart = pos + 1;
-
- } else if (ch == '#' && pos == lineStart) {
- int prLine = line;
- int prColumn = pos - lineStart; // which is 0
-
- string hashLine = BoogiePL.Buffer.ReadToEOL(); pos += hashLine.Length;
- line++;
- lineStart = pos + 1;
-
- hashLine = hashLine.TrimEnd(null);
- if (hashLine.StartsWith("line ") || hashLine == "line") {
- // parse #line pragma: #line num [filename]
- string h = hashLine.Substring(4).TrimStart(null);
- int x = h.IndexOf(' ');
- if (x == -1) {
- x = h.Length; // this will be convenient below when we look for a filename
- }
- try {
- int li = int.Parse(h.Substring(0, x));
-
- h = h.Substring(x).Trim();
-
- // act on #line
- line = li;
- if (h.Length != 0) {
- // a filename was specified
- Filename = h;
- }
- continue; // successfully parsed and acted on the #line pragma
-
- } catch (System.FormatException) {
- // just fall down through to produce an error message
- }
- Errors.SemErr(Filename, prLine, prColumn, "Malformed (#line num [filename]) pragma: #" + hashLine);
- continue;
- }
-
- Errors.SemErr(Filename, prLine, prColumn, "Unrecognized pragma: #" + hashLine);
- continue;
- }
- return;
- }
- }
- }
-
-
- static bool Comment0() {
- int level = 1, line0 = line, lineStart0 = lineStart;
+
+ [NotDelayed]
+ public Scanner (string! fileName, Errors! errorHandler) {
+ this.errorHandler = errorHandler;
+ pt = tokens = new Token(); // first token is a dummy
+ t = new Token(); // dummy because t is a non-null field
+ try {
+ Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
+ buffer = new Buffer(stream, false);
+ Filename = fileName;
+ base();
+ Init();
+ } catch (IOException) {
+ throw new FatalError("Cannot open file " + fileName);
+ }
+ }
+
+ [NotDelayed]
+ public Scanner (Stream! s, Errors! errorHandler, string! fileName) {
+ pt = tokens = new Token(); // first token is a dummy
+ t = new Token(); // dummy because t is a non-null field
+ buffer = new Buffer(s, true);
+ this.errorHandler = errorHandler;
+ this.Filename = fileName;
+ base();
+ Init();
+ }
+
+ void Init() {
+ pos = -1; line = 1; col = 0;
+ oldEols = 0;
+ NextCh();
+ if (ch == 0xEF) { // check optional byte order mark for UTF-8
+ NextCh(); int ch1 = ch;
+ NextCh(); int ch2 = ch;
+ if (ch1 != 0xBB || ch2 != 0xBF) {
+ throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2));
+ }
+ buffer = new UTF8Buffer(buffer); col = 0;
+ NextCh();
+ }
+ pt = tokens = new Token(); // first token is a dummy
+ }
+
+ string! ReadToEOL(){
+ int p = buffer.Pos;
+ int ch = buffer.Read();
+ // replace isolated '\r' by '\n' in order to make
+ // eol handling uniform across Windows, Unix and Mac
+ if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+ while (ch != EOL && ch != Buffer.EOF){
+ ch = buffer.Read();
+ // replace isolated '\r' by '\n' in order to make
+ // eol handling uniform across Windows, Unix and Mac
+ if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+ }
+ string! s = buffer.GetString(p, buffer.Pos);
+ return s;
+ }
+
+ void NextCh() {
+ if (oldEols > 0) { ch = EOL; oldEols--; }
+ else {
+// pos = buffer.Pos;
+// ch = buffer.Read(); col++;
+// // replace isolated '\r' by '\n' in order to make
+// // eol handling uniform across Windows, Unix and Mac
+// if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+// if (ch == EOL) { line++; col = 0; }
+
+ while (true) {
+ pos = buffer.Pos;
+ ch = buffer.Read(); col++;
+ // replace isolated '\r' by '\n' in order to make
+ // eol handling uniform across Windows, Unix and Mac
+ if (ch == '\r' && buffer.Peek() != '\n') ch = EOL;
+ if (ch == EOL) {
+ line++; col = 0;
+ } else if (ch == '#' && col == 1) {
+ int prLine = line;
+ int prColumn = 0;
+
+ string! hashLine = ReadToEOL();
+ col = 0;
+ line++;
+
+ hashLine = hashLine.TrimEnd(null);
+ if (hashLine.StartsWith("line ") || hashLine == "line") {
+ // parse #line pragma: #line num [filename]
+ string h = hashLine.Substring(4).TrimStart(null);
+ int x = h.IndexOf(' ');
+ if (x == -1) {
+ x = h.Length; // this will be convenient below when we look for a filename
+ }
+ try {
+ int li = int.Parse(h.Substring(0, x));
+
+ h = h.Substring(x).Trim();
+
+ // act on #line
+ line = li;
+ if (h.Length != 0) {
+ // a filename was specified
+ Filename = h;
+ }
+ continue; // successfully parsed and acted on the #line pragma
+
+ } catch (FormatException) {
+ // just fall down through to produce an error message
+ }
+ this.errorHandler.SemErr(Filename, prLine, prColumn, "Malformed (#line num [filename]) pragma: #" + hashLine);
+ continue;
+ }
+
+ this.errorHandler.SemErr(Filename, prLine, prColumn, "Unrecognized pragma: #" + hashLine);
+ continue;
+ }
+ return;
+ }
+
+
+ }
+
+ }
+
+ void AddCh() {
+ if (tlen >= tval.Length) {
+ char[] newBuf = new char[2 * tval.Length];
+ Array.Copy(tval, 0, newBuf, 0, tval.Length);
+ tval = newBuf;
+ }
+ if (ch != Buffer.EOF) {
+ tval[tlen++] = (char) ch;
+ NextCh();
+ }
+ }
+
+
+
+ bool Comment0() {
+ int level = 1, pos0 = pos, line0 = line, col0 = col;
NextCh();
if (ch == '/') {
NextCh();
for(;;) {
if (ch == 10) {
level--;
- if (level == 0) {
- while(line0 < line) {oldEols.Enqueue('\r'); oldEols.Enqueue('\n'); line0++;}
- NextCh(); return true;
- }
+ if (level == 0) { oldEols = line - line0; NextCh(); return true; }
NextCh();
- } else if (ch == EOF) return false;
+ } else if (ch == Buffer.EOF) return false;
else NextCh();
}
} else {
- if (ch==CR) {line--; lineStart = lineStart0;}
- pos = pos - 2; Buffer.Pos = pos+1; NextCh();
+ buffer.Pos = pos0; NextCh(); line = line0; col = col0;
}
return false;
}
-
- static bool Comment1() {
- int level = 1, line0 = line, lineStart0 = lineStart;
+
+ bool Comment1() {
+ int level = 1, pos0 = pos, line0 = line, col0 = col;
NextCh();
if (ch == '*') {
NextCh();
@@ -251,10 +440,7 @@ public class Scanner {
NextCh();
if (ch == '/') {
level--;
- if (level == 0) {
- while(line0 < line) {oldEols.Enqueue('\r'); oldEols.Enqueue('\n'); line0++;}
- NextCh(); return true;
- }
+ if (level == 0) { oldEols = line - line0; NextCh(); return true; }
NextCh();
}
} else if (ch == '/') {
@@ -262,19 +448,18 @@ public class Scanner {
if (ch == '*') {
level++; NextCh();
}
- } else if (ch == EOF) return false;
+ } else if (ch == Buffer.EOF) return false;
else NextCh();
}
} else {
- if (ch==CR) {line--; lineStart = lineStart0;}
- pos = pos - 2; Buffer.Pos = pos+1; NextCh();
+ buffer.Pos = pos0; NextCh(); line = line0; col = col0;
}
return false;
}
-
- static void CheckLiteral() {
- switch (t.val) {
+
+ void CheckLiteral() {
+ switch (t.val) {
case "module": t.kind = 4; break;
case "imports": t.kind = 5; break;
case "class": t.kind = 8; break;
@@ -326,185 +511,212 @@ public class Scanner {
case "forall": t.kind = 94; break;
case "exists": t.kind = 96; break;
default: break;
+ }
+ }
- }
- }
-
- public static Token/*!*/ Scan() {
- while (ignore[ch]) { NextCh(); }
- if (ch == '/' && Comment0() || ch == '/' && Comment1() ) return Scan();
- t = new Token();
- t.pos = pos; t.col = pos - lineStart + 1; t.line = line; t.filename = Filename;
- int state = (/*^ (!) ^*/ start)[ch];
- StringBuilder buf = new StringBuilder(16);
- buf.Append(ch); NextCh();
-
- switch (state) {
- case 0: {t.kind = noSym; goto done;} // NextCh already done
+ Token! NextToken() {
+ while (ch == ' ' ||
+ ch >= 9 && ch <= 10 || ch == 13
+ ) NextCh();
+ if (ch == '/' && Comment0() ||ch == '/' && Comment1()) return NextToken();
+ int recKind = noSym;
+ int recEnd = pos;
+ t = new Token();
+ t.pos = pos; t.col = col; t.line = line;
+ t.filename = this.Filename;
+ int state;
+ if (start.ContainsKey(ch)) { state = (int) (!) start[ch]; }
+ else { state = 0; }
+ tlen = 0; AddCh();
+
+ switch (state) {
+ case -1: { t.kind = eofSym; break; } // NextCh already done
+ case 0: {
+ if (recKind != noSym) {
+ tlen = recEnd - t.pos;
+ SetScannerBehindT();
+ }
+ t.kind = recKind; break;
+ } // NextCh already done
case 1:
- if ((ch == 39 || ch >= '0' && ch <= '9' || ch == '?' || ch >= 'A' && ch <= 'Z' || ch == 92 || ch == '_' || ch >= 'a' && ch <= 'z')) {buf.Append(ch); NextCh(); goto case 1;}
- else {t.kind = 1; t.val = buf.ToString(); CheckLiteral(); return t;}
+ recEnd = pos; recKind = 1;
+ if (ch == 39 || ch >= '0' && ch <= '9' || ch == '?' || ch >= 'A' && ch <= 'Z' || ch == 92 || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;}
+ else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
case 2:
- if ((ch >= '0' && ch <= '9')) {buf.Append(ch); NextCh(); goto case 2;}
- else {t.kind = 2; goto done;}
+ recEnd = pos; recKind = 2;
+ if (ch >= '0' && ch <= '9') {AddCh(); goto case 2;}
+ else {t.kind = 2; break;}
case 3:
- if ((ch == '"')) {buf.Append(ch); NextCh(); goto case 4;}
- else if ((ch >= ' ' && ch <= '!' || ch >= '#' && ch <= '~')) {buf.Append(ch); NextCh(); goto case 3;}
- else {t.kind = noSym; goto done;}
+ if (ch == '"') {AddCh(); goto case 4;}
+ else if (ch >= ' ' && ch <= '!' || ch >= '#' && ch <= '~') {AddCh(); goto case 3;}
+ else {goto case 0;}
case 4:
- {t.kind = 3; goto done;}
+ {t.kind = 3; break;}
case 5:
- {t.kind = 6; goto done;}
+ {t.kind = 6; break;}
case 6:
- {t.kind = 7; goto done;}
+ {t.kind = 7; break;}
case 7:
- {t.kind = 13; goto done;}
+ {t.kind = 13; break;}
case 8:
- {t.kind = 15; goto done;}
+ {t.kind = 15; break;}
case 9:
- if (ch == '=') {buf.Append(ch); NextCh(); goto case 18;}
- else if (ch == ':') {buf.Append(ch); NextCh(); goto case 53;}
- else {t.kind = 16; goto done;}
+ {t.kind = 26; break;}
case 10:
- if (ch == '=') {buf.Append(ch); NextCh(); goto case 22;}
- else {t.kind = 17; goto done;}
+ {t.kind = 27; break;}
case 11:
- if (ch == '=') {buf.Append(ch); NextCh(); goto case 34;}
- else {t.kind = 18; goto done;}
+ {t.kind = 36; break;}
case 12:
- {t.kind = 26; goto done;}
+ {t.kind = 37; break;}
case 13:
- {t.kind = 27; goto done;}
+ {t.kind = 40; break;}
case 14:
- {t.kind = 36; goto done;}
+ {t.kind = 44; break;}
case 15:
- {t.kind = 37; goto done;}
+ {t.kind = 46; break;}
case 16:
- if (ch == '>') {buf.Append(ch); NextCh(); goto case 17;}
- else if (ch == '=') {buf.Append(ch); NextCh(); goto case 26;}
- else {t.kind = noSym; goto done;}
+ {t.kind = 47; break;}
case 17:
- {t.kind = 40; goto done;}
+ if (ch == '>') {AddCh(); goto case 18;}
+ else {goto case 0;}
case 18:
- {t.kind = 44; goto done;}
+ {t.kind = 62; break;}
case 19:
- {t.kind = 46; goto done;}
+ {t.kind = 63; break;}
case 20:
- {t.kind = 47; goto done;}
+ {t.kind = 64; break;}
case 21:
- if (ch == '|') {buf.Append(ch); NextCh(); goto case 32;}
- else {t.kind = 56; goto done;}
+ {t.kind = 65; break;}
case 22:
- if (ch == '=') {buf.Append(ch); NextCh(); goto case 23;}
- else {t.kind = 71; goto done;}
+ if (ch == '&') {AddCh(); goto case 23;}
+ else {goto case 0;}
case 23:
- if (ch == '>') {buf.Append(ch); NextCh(); goto case 24;}
- else {t.kind = noSym; goto done;}
+ {t.kind = 66; break;}
case 24:
- {t.kind = 62; goto done;}
+ {t.kind = 67; break;}
case 25:
- {t.kind = 63; goto done;}
+ {t.kind = 68; break;}
case 26:
- if (ch == '>') {buf.Append(ch); NextCh(); goto case 27;}
- else {t.kind = 70; goto done;}
+ {t.kind = 69; break;}
case 27:
- {t.kind = 64; goto done;}
+ {t.kind = 72; break;}
case 28:
- {t.kind = 65; goto done;}
+ {t.kind = 73; break;}
case 29:
- if (ch == '&') {buf.Append(ch); NextCh(); goto case 30;}
- else {t.kind = noSym; goto done;}
+ {t.kind = 74; break;}
case 30:
- {t.kind = 66; goto done;}
+ if (ch == 'n') {AddCh(); goto case 31;}
+ else {goto case 0;}
case 31:
- {t.kind = 67; goto done;}
+ {t.kind = 75; break;}
case 32:
- {t.kind = 68; goto done;}
+ {t.kind = 76; break;}
case 33:
- {t.kind = 69; goto done;}
+ {t.kind = 77; break;}
case 34:
- {t.kind = 72; goto done;}
+ {t.kind = 78; break;}
case 35:
- if (ch == '=') {buf.Append(ch); NextCh(); goto case 36;}
- else if (ch == '!') {buf.Append(ch); NextCh(); goto case 37;}
- else if (ch == 'i') {buf.Append(ch); NextCh(); goto case 38;}
- else {t.kind = 83; goto done;}
+ {t.kind = 79; break;}
case 36:
- {t.kind = 73; goto done;}
+ {t.kind = 80; break;}
case 37:
- {t.kind = 74; goto done;}
+ {t.kind = 81; break;}
case 38:
- if (ch == 'n') {buf.Append(ch); NextCh(); goto case 39;}
- else {t.kind = noSym; goto done;}
+ {t.kind = 82; break;}
case 39:
- {t.kind = 75; goto done;}
+ {t.kind = 84; break;}
case 40:
- {t.kind = 76; goto done;}
+ {t.kind = 88; break;}
case 41:
- {t.kind = 77; goto done;}
+ {t.kind = 91; break;}
case 42:
- {t.kind = 78; goto done;}
+ {t.kind = 95; break;}
case 43:
- {t.kind = 79; goto done;}
+ {t.kind = 97; break;}
case 44:
- {t.kind = 80; goto done;}
+ {t.kind = 98; break;}
case 45:
- {t.kind = 81; goto done;}
+ {t.kind = 99; break;}
case 46:
- {t.kind = 82; goto done;}
+ recEnd = pos; recKind = 16;
+ if (ch == '=') {AddCh(); goto case 14;}
+ else if (ch == ':') {AddCh(); goto case 44;}
+ else {t.kind = 16; break;}
case 47:
- {t.kind = 84; goto done;}
+ recEnd = pos; recKind = 17;
+ if (ch == '=') {AddCh(); goto case 53;}
+ else {t.kind = 17; break;}
case 48:
- {t.kind = 88; goto done;}
+ recEnd = pos; recKind = 18;
+ if (ch == '=') {AddCh(); goto case 27;}
+ else {t.kind = 18; break;}
case 49:
- if (ch == '.') {buf.Append(ch); NextCh(); goto case 50;}
- else {t.kind = 89; goto done;}
+ if (ch == '>') {AddCh(); goto case 13;}
+ else if (ch == '=') {AddCh(); goto case 54;}
+ else {goto case 0;}
case 50:
- {t.kind = 91; goto done;}
+ recEnd = pos; recKind = 56;
+ if (ch == '|') {AddCh(); goto case 25;}
+ else {t.kind = 56; break;}
case 51:
- {t.kind = 95; goto done;}
+ recEnd = pos; recKind = 83;
+ if (ch == '=') {AddCh(); goto case 28;}
+ else if (ch == '!') {AddCh(); goto case 29;}
+ else if (ch == 'i') {AddCh(); goto case 30;}
+ else {t.kind = 83; break;}
case 52:
- {t.kind = 97; goto done;}
+ recEnd = pos; recKind = 89;
+ if (ch == '.') {AddCh(); goto case 41;}
+ else {t.kind = 89; break;}
case 53:
- {t.kind = 98; goto done;}
+ recEnd = pos; recKind = 71;
+ if (ch == '=') {AddCh(); goto case 17;}
+ else {t.kind = 71; break;}
case 54:
- {t.kind = 99; goto done;}
- case 55: {t.kind = 0; goto done;}
- }
- done:
- t.val = buf.ToString();
- return t;
- }
+ recEnd = pos; recKind = 70;
+ if (ch == '>') {AddCh(); goto case 20;}
+ else {t.kind = 70; break;}
-} // end Scanner
+ }
+ t.val = new String(tval, 0, tlen);
+ return t;
+ }
+
+ private void SetScannerBehindT() {
+ buffer.Pos = t.pos;
+ NextCh();
+ line = t.line; col = t.col;
+ for (int i = 0; i < tlen; i++) NextCh();
+ }
+
+ // get the next token (possibly a token already seen during peeking)
+ public Token! Scan () {
+ if (tokens.next == null) {
+ return NextToken();
+ } else {
+ pt = tokens = tokens.next;
+ return tokens;
+ }
+ }
+ // peek for the next token, ignore pragmas
+ public Token! Peek () {
+ do {
+ if (pt.next == null) {
+ pt.next = NextToken();
+ }
+ pt = pt.next;
+ } while (pt.kind > maxT); // skip pragmas
+
+ return pt;
+ }
-public delegate void ErrorProc(int n, string filename, int line, int col);
+ // make sure that peeking starts at the current scan position
+ public void ResetPeek () { pt = tokens; }
-public class Errors {
- public static int count = 0; // number of errors detected
- public static ErrorProc/*!*/ SynErr; // syntactic errors
-
- public static void SemErr(string filename, int line, int col, string! msg) { // semantic errors
- System.ConsoleColor color = System.Console.ForegroundColor;
- System.Console.ForegroundColor = System.ConsoleColor.Red;
- System.Console.WriteLine("{0}({1},{2}): Error: {3}", filename, line, col, msg);
- System.Console.ForegroundColor = color;
- count++;
- }
-
- public static void SemErr(Bpl.IToken! tok, string! msg) { // semantic errors
- SemErr(tok.filename, tok.line, tok.col, msg);
- }
-
- public static void Exception (string s) {
- System.ConsoleColor color = System.Console.ForegroundColor;
- System.Console.ForegroundColor = System.ConsoleColor.Red;
- System.Console.WriteLine(s);
- System.Console.ForegroundColor = color;
- System.Environment.Exit(0);
- }
+} // end Scanner
+
+public delegate void ErrorProc(int n, string filename, int line, int col);
-} // Errors
-} // end namespace
+} \ No newline at end of file
diff --git a/Source/Dafny/Translator.ssc b/Source/Dafny/Translator.ssc
index 348fdd2b..4d9f3993 100644
--- a/Source/Dafny/Translator.ssc
+++ b/Source/Dafny/Translator.ssc
@@ -9,6 +9,7 @@ using System.Numerics;
using Microsoft.Contracts;
using Bpl = Microsoft.Boogie;
using System.Text;
+using Microsoft.Boogie;
namespace Microsoft.Dafny {
public class Translator {
@@ -31,9 +32,9 @@ namespace Microsoft.Dafny {
// Machinery for providing information to the Counterexample Visualizer
readonly Dictionary<string!,int>! cevFilenames = new Dictionary<string!,int>();
- readonly Dictionary<Token!,Bpl.Constant!>! cevLocations = new Dictionary<Token!,Bpl.Constant!>();
+ readonly Dictionary<IToken!,Bpl.Constant!>! cevLocations = new Dictionary<IToken!,Bpl.Constant!>();
readonly Dictionary<string!,Bpl.Constant!>! cevVariables = new Dictionary<string!,Bpl.Constant!>();
- Bpl.Expr! CevLocation(Token! tok)
+ Bpl.Expr! CevLocation(IToken! tok)
requires predef != null && sink != null;
{
Bpl.Constant c;
@@ -89,15 +90,15 @@ namespace Microsoft.Dafny {
public readonly Bpl.Type! CevVariableKind;
public readonly Bpl.Type! CevEventType;
private readonly Bpl.TypeSynonymDecl! setTypeCtor;
- public Bpl.Type! SetType(Token! tok, Bpl.Type! ty) {
+ public Bpl.Type! SetType(IToken! tok, Bpl.Type! ty) {
return new Bpl.TypeSynonymAnnotation(Token.NoToken, setTypeCtor, new Bpl.TypeSeq(ty));
}
private readonly Bpl.TypeCtorDecl! seqTypeCtor;
- public Bpl.Type! SeqType(Token! tok, Bpl.Type! ty) {
+ public Bpl.Type! SeqType(IToken! tok, Bpl.Type! ty) {
return new Bpl.CtorType(Token.NoToken, seqTypeCtor, new Bpl.TypeSeq(ty));
}
readonly Bpl.TypeCtorDecl! fieldName;
- public Bpl.Type! FieldName(Token! tok, Bpl.Type! ty) {
+ public Bpl.Type! FieldName(IToken! tok, Bpl.Type! ty) {
return new Bpl.CtorType(tok, fieldName, new Bpl.TypeSeq(ty));
}
public readonly Bpl.Type! HeapType;
@@ -109,7 +110,7 @@ namespace Microsoft.Dafny {
public readonly Bpl.Type! DtCtorId;
public readonly Bpl.Expr! Null;
private readonly Bpl.Constant! allocField;
- public Bpl.IdentifierExpr! Alloc(Token! tok) {
+ public Bpl.IdentifierExpr! Alloc(IToken! tok) {
return new Bpl.IdentifierExpr(tok, allocField);
}
@@ -247,11 +248,20 @@ namespace Microsoft.Dafny {
//using (System.IO.Stream stream = (!) System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("DafnyPrelude.bpl")) // Use this once Spec#/VSIP supports designating a non-.resx project item as an embedded resource
string! codebase = (!) System.IO.Path.GetDirectoryName((!)System.Reflection.Assembly.GetExecutingAssembly().Location);
string! preludePath = System.IO.Path.Combine(codebase, "DafnyPrelude.bpl");
+
+ Bpl.Program prelude;
+ int errorCount = Bpl.Parser.Parse(preludePath, out prelude);
+ if (prelude == null || errorCount > 0) {
+ return null;
+ } else {
+ return prelude;
+ }
+/*
List<string!> defines = new List<string!>();
using (System.IO.Stream stream = new System.IO.FileStream(preludePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
BoogiePL.Buffer.Fill(new System.IO.StreamReader(stream), defines);
- BoogiePL.Scanner.Init("<DafnyPrelude.bpl>");
+ //BoogiePL.Scanner.Init("<DafnyPrelude.bpl>");
Bpl.Program prelude;
int errorCount = BoogiePL.Parser.Parse(out prelude);
if (prelude == null || errorCount > 0) {
@@ -260,6 +270,7 @@ namespace Microsoft.Dafny {
return prelude;
}
}
+*/
}
public Bpl.Program! Translate(Program! program) {
@@ -660,7 +671,7 @@ namespace Microsoft.Dafny {
}
}
- Bpl.Expr! InSeqRange(Token! tok, Bpl.Expr! index, Bpl.Expr! seq, bool isSequence, Bpl.Expr lowerBound, bool includeUpperBound) {
+ Bpl.Expr! InSeqRange(IToken! tok, Bpl.Expr! index, Bpl.Expr! seq, bool isSequence, Bpl.Expr lowerBound, bool includeUpperBound) {
if (lowerBound == null) {
lowerBound = Bpl.Expr.Literal(0);
}
@@ -679,7 +690,7 @@ namespace Microsoft.Dafny {
int loopHeapVarCount = 0;
int otherTmpVarCount = 0;
Bpl.IdentifierExpr _phvie = null;
- Bpl.IdentifierExpr! GetPrevHeapVar_IdExpr(Token! tok, Bpl.VariableSeq! locals) // local variable that's shared between statements that need it
+ Bpl.IdentifierExpr! GetPrevHeapVar_IdExpr(IToken! tok, Bpl.VariableSeq! locals) // local variable that's shared between statements that need it
requires predef != null;
{
if (_phvie == null) {
@@ -691,7 +702,7 @@ namespace Microsoft.Dafny {
return _phvie;
}
Bpl.IdentifierExpr _nwie = null;
- Bpl.IdentifierExpr! GetNewVar_IdExpr(Token! tok, Bpl.VariableSeq! locals) // local variable that's shared between statements that need it
+ Bpl.IdentifierExpr! GetNewVar_IdExpr(IToken! tok, Bpl.VariableSeq! locals) // local variable that's shared between statements that need it
requires predef != null;
{
if (_nwie == null) {
@@ -795,7 +806,7 @@ namespace Microsoft.Dafny {
assert p != null;
builder.Add(new Bpl.CallCmd(p.tok, "CevVarIntro",
new Bpl.ExprSeq(
- CevLocation((Dafny.Token)p.tok),
+ CevLocation(p.tok),
new Bpl.IdentifierExpr(p.tok, "cev_parameter", predef.CevVariableKind),
CevVariable(p.tok, p.Name),
new Bpl.IdentifierExpr(p.tok, p.Name, p.TypedIdent.Type)), // it's important not to pass in just p, because that resolves to the proc's param, not the impl's param
@@ -805,7 +816,7 @@ namespace Microsoft.Dafny {
assert p != null;
builder.Add(new Bpl.CallCmd(p.tok, "CevVarIntro",
new Bpl.ExprSeq(
- CevLocation((Dafny.Token)p.tok),
+ CevLocation(p.tok),
new Bpl.IdentifierExpr(p.tok, "cev_local", predef.CevVariableKind), // treat out-parameters as locals
CevVariable(p.tok, p.Name),
new Bpl.IdentifierExpr(p.tok, p.Name, p.TypedIdent.Type)), // it's important not to pass in just p, because that resolves to the proc's param, not the impl's param
@@ -816,7 +827,7 @@ namespace Microsoft.Dafny {
DefineFrame(m.tok, m.Mod, builder, localVariables);
}
- void DefineFrame(Token! tok, List<FrameExpression!>! frameClause, Bpl.StmtListBuilder! builder, Bpl.VariableSeq! localVariables)
+ void DefineFrame(IToken! tok, List<FrameExpression!>! frameClause, Bpl.StmtListBuilder! builder, Bpl.VariableSeq! localVariables)
requires predef != null;
{
ExpressionTranslator etran = new ExpressionTranslator(this, predef, tok);
@@ -839,7 +850,7 @@ namespace Microsoft.Dafny {
builder.Add(Bpl.Cmd.SimpleAssign(tok, new Bpl.IdentifierExpr(tok, frame), lambda));
}
- void CheckFrameSubset(Token! tok, List<FrameExpression!>! calleeFrame,
+ void CheckFrameSubset(IToken! tok, List<FrameExpression!>! calleeFrame,
Expression receiverReplacement, Dictionary<IVariable,Expression!> substMap,
ExpressionTranslator! etran, Bpl.StmtListBuilder! builder, string! errorMessage)
requires predef != null;
@@ -959,7 +970,7 @@ namespace Microsoft.Dafny {
}
}
- Bpl.Expr! InRWClause(Token! tok, Bpl.Expr! o, Bpl.Expr! f, List<FrameExpression!>! rw, ExpressionTranslator! etran,
+ Bpl.Expr! InRWClause(IToken! tok, Bpl.Expr! o, Bpl.Expr! f, List<FrameExpression!>! rw, ExpressionTranslator! etran,
Expression receiverReplacement, Dictionary<IVariable,Expression!> substMap)
requires predef != null;
// requires o to denote an expression of type RefType
@@ -1225,7 +1236,7 @@ namespace Microsoft.Dafny {
}
}
- void CheckNonNull(Token! tok, Expression! e, Bpl.StmtListBuilder! builder, ExpressionTranslator! etran)
+ void CheckNonNull(IToken! tok, Expression! e, Bpl.StmtListBuilder! builder, ExpressionTranslator! etran)
requires predef != null;
{
if (e is ThisExpr) {
@@ -1490,7 +1501,7 @@ namespace Microsoft.Dafny {
return cc;
}
- Bpl.Expr GetTypeExpr(Token! tok, Type! type)
+ Bpl.Expr GetTypeExpr(IToken! tok, Type! type)
requires predef != null;
{
while (true) {
@@ -1706,13 +1717,13 @@ namespace Microsoft.Dafny {
}
class BoilerplateTriple { // a triple that is now a quintuple
- public readonly Token! tok;
+ public readonly IToken! tok;
public readonly bool IsFree;
public readonly Bpl.Expr! Expr;
public readonly string ErrorMessage;
invariant IsFree || ErrorMessage != null;
public readonly string Comment;
- public BoilerplateTriple(Token! tok, bool isFree, Bpl.Expr! expr, string errorMessage, string comment)
+ public BoilerplateTriple(IToken! tok, bool isFree, Bpl.Expr! expr, string errorMessage, string comment)
requires isFree || errorMessage != null;
{
this.tok = tok;
@@ -1730,7 +1741,7 @@ namespace Microsoft.Dafny {
/// S2. the post-state of the two-state interval
/// This method assumes that etranPre denotes S1, etran denotes S2, and that etran.Old denotes S0.
/// </summary>
- List<BoilerplateTriple!>! GetTwoStateBoilerplate(Token! tok, Method! method, ExpressionTranslator! etranPre, ExpressionTranslator! etran)
+ List<BoilerplateTriple!>! GetTwoStateBoilerplate(IToken! tok, Method! method, ExpressionTranslator! etranPre, ExpressionTranslator! etran)
{
List<BoilerplateTriple!> boilerplate = new List<BoilerplateTriple!>();
@@ -1751,7 +1762,7 @@ namespace Microsoft.Dafny {
/// S2. the post-state of the two-state interval
/// This method assumes that etranPre denotes S1, etran denotes S2, and that etran.Old denotes S0.
/// </summary>
- Bpl.Expr! FrameCondition(Token! tok, List<FrameExpression!>! modifiesClause, ExpressionTranslator! etranPre, ExpressionTranslator! etran)
+ Bpl.Expr! FrameCondition(IToken! tok, List<FrameExpression!>! modifiesClause, ExpressionTranslator! etranPre, ExpressionTranslator! etran)
requires predef != null;
{
// generate:
@@ -1838,7 +1849,7 @@ namespace Microsoft.Dafny {
return cmd;
}
- Bpl.Ensures! Ensures(Token! tok, bool free, Bpl.Expr! condition, string errorMessage, string comment)
+ Bpl.Ensures! Ensures(IToken! tok, bool free, Bpl.Expr! condition, string errorMessage, string comment)
{
Bpl.Ensures ens = new Bpl.Ensures(tok, free, condition, comment);
if (errorMessage != null) {
@@ -1847,7 +1858,7 @@ namespace Microsoft.Dafny {
return ens;
}
- Bpl.Requires! Requires(Token! tok, bool free, Bpl.Expr! condition, string errorMessage, string comment)
+ Bpl.Requires! Requires(IToken! tok, bool free, Bpl.Expr! condition, string errorMessage, string comment)
{
Bpl.Requires req = new Bpl.Requires(tok, free, condition, comment);
if (errorMessage != null) {
@@ -2266,7 +2277,7 @@ namespace Microsoft.Dafny {
// time for the actual loop body
TrStmt(s.Body, loopBodyBuilder, locals, etran);
// check definedness of decreases expressions
- List<Token!> toks = new List<Token!>();
+ List<IToken!> toks = new List<IToken!>();
List<Type!> types = new List<Type!>();
List<Bpl.Expr!> decrs = new List<Bpl.Expr!>();
foreach (Expression e in theDecreases) {
@@ -2457,7 +2468,7 @@ namespace Microsoft.Dafny {
}
}
- static Expression! CreateIntLiteral(Token! tok, int n)
+ static Expression! CreateIntLiteral(IToken! tok, int n)
{
if (0 <= n) {
Expression lit = new LiteralExpr(tok, n);
@@ -2468,7 +2479,7 @@ namespace Microsoft.Dafny {
}
}
- static Expression! CreateIntSub(Token! tok, Expression! e0, Expression! e1)
+ static Expression! CreateIntSub(IToken! tok, Expression! e0, Expression! e1)
requires e0.Type is IntType && e1.Type is IntType;
{
BinaryExpr s = new BinaryExpr(tok, BinaryExpr.Opcode.Sub, e0, e1);
@@ -2477,7 +2488,7 @@ namespace Microsoft.Dafny {
return s;
}
- static Expression! CreateIntITE(Token! tok, Expression! test, Expression! e0, Expression! e1)
+ static Expression! CreateIntITE(IToken! tok, Expression! test, Expression! e0, Expression! e1)
requires test.Type is BoolType && e0.Type is IntType && e1.Type is IntType;
{
ITEExpr ite = new ITEExpr(tok, test, e0, e1);
@@ -2504,12 +2515,12 @@ namespace Microsoft.Dafny {
yield return expr;
}
- void CheckCallTermination(Token! tok, List<Expression!>! contextDecreases, List<Expression!>! calleeDecreases,
+ void CheckCallTermination(IToken! tok, List<Expression!>! contextDecreases, List<Expression!>! calleeDecreases,
Expression receiverReplacement, Dictionary<IVariable,Expression!>! substMap,
ExpressionTranslator! etran, Bpl.StmtListBuilder! builder)
{
int N = min{contextDecreases.Count, calleeDecreases.Count};
- List<Token!> toks = new List<Token!>();
+ List<IToken!> toks = new List<IToken!>();
List<Type!> types = new List<Type!>();
List<Bpl.Expr!> callee = new List<Bpl.Expr!>();
List<Bpl.Expr!> caller = new List<Bpl.Expr!>();
@@ -2532,7 +2543,7 @@ namespace Microsoft.Dafny {
/// Returns the expression that says whether or not the decreases function has gone down. ee0 represents the new
/// values and ee1 represents old values.
/// </summary>
- Bpl.Expr! DecreasesCheck(List<Token!>! toks, List<Type!>! types, List<Bpl.Expr!>! ee0, List<Bpl.Expr!>! ee1,
+ Bpl.Expr! DecreasesCheck(List<IToken!>! toks, List<Type!>! types, List<Bpl.Expr!>! ee0, List<Bpl.Expr!>! ee1,
Bpl.StmtListBuilder! builder, ExpressionTranslator! etran, string! suffixMsg)
requires predef != null;
requires types.Count == ee0.Count && ee0.Count == ee1.Count;
@@ -2605,7 +2616,7 @@ namespace Microsoft.Dafny {
}
}
- void ComputeLessEq(Token! tok, Type! ty, Bpl.Expr! e0, Bpl.Expr! e1, out Bpl.Expr! less, out Bpl.Expr! eq, ExpressionTranslator! etran)
+ void ComputeLessEq(IToken! tok, Type! ty, Bpl.Expr! e0, Bpl.Expr! e1, out Bpl.Expr! less, out Bpl.Expr! eq, ExpressionTranslator! etran)
requires predef != null;
{
if (ty is BoolType) {
@@ -2641,7 +2652,7 @@ namespace Microsoft.Dafny {
builder.Add(new Bpl.CommentCmd(string.Format("----- {0} ----- {1}({2},{3})", comment, stmt.Tok.filename, stmt.Tok.line, stmt.Tok.col)));
}
- Bpl.Expr GetWhereClause(Token! tok, Bpl.Expr! x, Type! type, ExpressionTranslator! etran)
+ Bpl.Expr GetWhereClause(IToken! tok, Bpl.Expr! x, Type! type, ExpressionTranslator! etran)
requires predef != null;
{
if (type is TypeProxy) {
@@ -2703,7 +2714,7 @@ namespace Microsoft.Dafny {
}
}
- void TrAssignment(Token! tok, Expression! lhs, AssignmentRhs! rhs, Bpl.StmtListBuilder! builder, Bpl.VariableSeq! locals,
+ void TrAssignment(IToken! tok, Expression! lhs, AssignmentRhs! rhs, Bpl.StmtListBuilder! builder, Bpl.VariableSeq! locals,
ExpressionTranslator! etran)
requires predef != null;
{
@@ -2809,7 +2820,7 @@ namespace Microsoft.Dafny {
}
}
- Bpl.AssumeCmd! AssumeGoodHeap(Token! tok, ExpressionTranslator! etran) {
+ Bpl.AssumeCmd! AssumeGoodHeap(IToken! tok, ExpressionTranslator! etran) {
return new Bpl.AssumeCmd(tok, FunctionCall(tok, BuiltinFunction.IsGoodHeap, null, etran.HeapExpr));
}
@@ -2821,7 +2832,7 @@ namespace Microsoft.Dafny {
public readonly Translator! translator;
readonly Function applyLimited_CurrentFunction;
- public ExpressionTranslator(Translator! translator, PredefinedDecls! predef, Token! heapToken) {
+ public ExpressionTranslator(Translator! translator, PredefinedDecls! predef, IToken! heapToken) {
this.translator = translator;
this.predef = predef;
HeapExpr = new Bpl.IdentifierExpr(heapToken, predef.HeapVarName, predef.HeapType);
@@ -2854,7 +2865,7 @@ namespace Microsoft.Dafny {
return new ExpressionTranslator(translator, predef, HeapExpr, applyLimited_CurrentFunction);
}
- public Bpl.IdentifierExpr! TheFrame(Token! tok)
+ public Bpl.IdentifierExpr! TheFrame(IToken! tok)
ensures result.Type != null;
{
Bpl.TypeVariable alpha = new Bpl.TypeVariable(tok, "beta");
@@ -3211,12 +3222,12 @@ namespace Microsoft.Dafny {
}
}
- public Bpl.Expr! ProperSubset(Token! tok, Bpl.Expr! e0, Bpl.Expr! e1) {
+ public Bpl.Expr! ProperSubset(IToken! tok, Bpl.Expr! e0, Bpl.Expr! e1) {
return Bpl.Expr.And(
translator.FunctionCall(tok, BuiltinFunction.SetSubset, null, e0, e1),
Bpl.Expr.Not(translator.FunctionCall(tok, BuiltinFunction.SetSubset, null, e1, e0)));
}
- public Bpl.Expr! ProperPrefix(Token! tok, Bpl.Expr! e0, Bpl.Expr! e1) {
+ public Bpl.Expr! ProperPrefix(IToken! tok, Bpl.Expr! e0, Bpl.Expr! e1) {
Bpl.Expr len0 = translator.FunctionCall(tok, BuiltinFunction.SeqLength, null, e0);
Bpl.Expr len1 = translator.FunctionCall(tok, BuiltinFunction.SeqLength, null, e1);
return Bpl.Expr.And(
@@ -3246,7 +3257,7 @@ namespace Microsoft.Dafny {
return Bpl.Expr.Eq(f0, f1);
}
- public Bpl.Expr! CondApplyBox(Token! tok, Bpl.Expr! e, Type! fromType, Type! toType) {
+ public Bpl.Expr! CondApplyBox(IToken! tok, Bpl.Expr! e, Type! fromType, Type! toType) {
if (!ModeledAsBoxType(fromType) && ModeledAsBoxType(toType)) {
return translator.FunctionCall(tok, BuiltinFunction.Box, null, e);
} else {
@@ -3254,7 +3265,7 @@ namespace Microsoft.Dafny {
}
}
- public Bpl.Expr! BoxIfNecessary(Token! tok, Bpl.Expr! e, Type! fromType) {
+ public Bpl.Expr! BoxIfNecessary(IToken! tok, Bpl.Expr! e, Type! fromType) {
if (!ModeledAsBoxType(fromType)) {
return translator.FunctionCall(tok, BuiltinFunction.Box, null, e);
} else {
@@ -3262,7 +3273,7 @@ namespace Microsoft.Dafny {
}
}
- public Bpl.Expr! CondApplyUnbox(Token! tok, Bpl.Expr! e, Type! fromType, Type! toType) {
+ public Bpl.Expr! CondApplyUnbox(IToken! tok, Bpl.Expr! e, Type! fromType, Type! toType) {
if (ModeledAsBoxType(fromType) && !ModeledAsBoxType(toType)) {
return translator.FunctionCall(tok, BuiltinFunction.Unbox, translator.TrType(toType), e);
} else {
@@ -3285,7 +3296,7 @@ namespace Microsoft.Dafny {
return t.IsTypeParameter;
}
- public Bpl.IdentifierExpr! TrVar(Token! tok, IVariable! var) {
+ public Bpl.IdentifierExpr! TrVar(IToken! tok, IVariable! var) {
return new Bpl.IdentifierExpr(tok, var.UniqueName, translator.TrType(var.Type));
}
@@ -3293,7 +3304,7 @@ namespace Microsoft.Dafny {
/// Translate like s[Box(elmt)], but try to avoid as many set functions as possible in the
/// translation, because such functions can mess up triggering.
/// </summary>
- public Bpl.Expr! TrInSet(Token! tok, Bpl.Expr! elmt, Expression! s, Type! elmtType) {
+ public Bpl.Expr! TrInSet(IToken! tok, Bpl.Expr! elmt, Expression! s, Type! elmtType) {
if (s is BinaryExpr) {
BinaryExpr bin = (BinaryExpr)s;
switch (bin.ResolvedOp) {
@@ -3345,15 +3356,15 @@ namespace Microsoft.Dafny {
// --------------- help routines ---------------
- public Bpl.Expr! IsAlloced(Token! tok, Bpl.Expr! e) {
+ public Bpl.Expr! IsAlloced(IToken! tok, Bpl.Expr! e) {
return IsAlloced(tok, e, HeapExpr);
}
- Bpl.Expr! IsAlloced(Token! tok, Bpl.Expr! e, Bpl.Expr! heap) {
+ Bpl.Expr! IsAlloced(IToken! tok, Bpl.Expr! e, Bpl.Expr! heap) {
return Bpl.Expr.SelectTok(tok, heap, e, predef.Alloc(tok));
}
- public Bpl.Expr! GoodRef(Token! tok, Bpl.Expr! e, Type! type) {
+ public Bpl.Expr! GoodRef(IToken! tok, Bpl.Expr! e, Type! type) {
Bpl.Expr goodRef;
if (type is UserDefinedType && ((UserDefinedType)type).ResolvedClass != null) {
// Heap[e, alloc] && dtype(e) == T
@@ -3364,13 +3375,13 @@ namespace Microsoft.Dafny {
}
}
- public Bpl.Expr! GoodRef_Class(Token! tok, Bpl.Expr! e, UserDefinedType! type, bool isNew)
+ public Bpl.Expr! GoodRef_Class(IToken! tok, Bpl.Expr! e, UserDefinedType! type, bool isNew)
requires type.ResolvedClass is ClassDecl;
{
return GoodRef_Ref(tok, e, new Bpl.IdentifierExpr(tok, translator.GetClass(type.ResolvedClass)), type.TypeArgs, isNew);
}
- public Bpl.Expr! GoodRef_Ref(Token! tok, Bpl.Expr! e, Bpl.Expr! type, List<Type!>! typeArgs, bool isNew) {
+ public Bpl.Expr! GoodRef_Ref(IToken! tok, Bpl.Expr! e, Bpl.Expr! type, List<Type!>! typeArgs, bool isNew) {
// Heap[e, alloc]
Bpl.Expr r = IsAlloced(tok, e);
if (isNew) {
@@ -3396,7 +3407,7 @@ namespace Microsoft.Dafny {
return r;
}
- public Bpl.Expr TypeAlloced(Token! tok, Bpl.Expr! e, Type! type) {
+ public Bpl.Expr TypeAlloced(IToken! tok, Bpl.Expr! e, Type! type) {
while (true) {
TypeProxy proxy = type as TypeProxy;
if (proxy == null) {
@@ -3493,7 +3504,7 @@ namespace Microsoft.Dafny {
}
// The "typeInstantiation" argument is passed in to help construct the result type of the function.
- Bpl.NAryExpr! FunctionCall(Token! tok, BuiltinFunction f, Bpl.Type typeInstantiation, params Bpl.Expr[]! args)
+ Bpl.NAryExpr! FunctionCall(IToken! tok, BuiltinFunction f, Bpl.Type typeInstantiation, params Bpl.Expr[]! args)
requires predef != null;
{
switch (f) {
@@ -3667,12 +3678,12 @@ namespace Microsoft.Dafny {
}
}
- Bpl.NAryExpr! FunctionCall(Token! tok, string! function, Bpl.Type! returnType, params Bpl.Expr[]! args)
+ Bpl.NAryExpr! FunctionCall(IToken! tok, string! function, Bpl.Type! returnType, params Bpl.Expr[]! args)
{
return new Bpl.NAryExpr(tok, new Bpl.FunctionCall(new Bpl.IdentifierExpr(tok, function, returnType)), new Bpl.ExprSeq(args));
}
- Bpl.NAryExpr! FunctionCall(Token! tok, string! function, Bpl.Type! returnType, List<Bpl.Expr!>! args)
+ Bpl.NAryExpr! FunctionCall(IToken! tok, string! function, Bpl.Type! returnType, List<Bpl.Expr!>! args)
{
Bpl.ExprSeq aa = new Bpl.ExprSeq();
foreach (Bpl.Expr arg in args) {
diff --git a/Source/Dafny/parser.frame b/Source/Dafny/parser.frame
deleted file mode 100644
index de0ba1fb..00000000
--- a/Source/Dafny/parser.frame
+++ /dev/null
@@ -1,103 +0,0 @@
-
-using Microsoft.Contracts;
-
-namespace Microsoft.-->namespace {
-
-public class Parser {
--->constants
- const bool T = true;
- const bool x = false;
- const int minErrDist = 2;
-
- static Token/*!*/ token; // last recognized token
- static Token/*!*/ t; // lookahead token
- static int errDist = minErrDist;
-
- -->declarations
-
- static void Error(int n) {
- if (errDist >= minErrDist) Errors.SynErr(n, t.filename, t.line, t.col);
- errDist = 0;
- }
-
- public static void SemErr(string! msg) {
- if (errDist >= minErrDist) Errors.SemErr(token.filename, token.line, token.col, msg);
- errDist = 0;
- }
-
- public static void SemErr(Token! tok, string! msg) {
- if (errDist >= minErrDist) Errors.SemErr(tok.filename, tok.line, tok.col, msg);
- errDist = 0;
- }
-
- static void Get() {
- for (;;) {
- token = t;
- t = Scanner.Scan();
- if (t.kind<=maxT) {errDist++; return;}
--->pragmas
- t = token;
- }
- }
-
- static void Expect(int n) {
- if (t.kind==n) Get(); else Error(n);
- }
-
- static bool StartOf(int s) {
- return set[s, t.kind];
- }
-
- static void ExpectWeak(int n, int follow) {
- if (t.kind == n) Get();
- else {
- Error(n);
- while (!StartOf(follow)) Get();
- }
- }
-
- static bool WeakSeparator(int n, int syFol, int repFol) {
- bool[] s = new bool[maxT+1];
- if (t.kind == n) {Get(); return true;}
- else if (StartOf(repFol)) return false;
- else {
- for (int i=0; i <= maxT; i++) {
- s[i] = set[syFol, i] || set[repFol, i] || set[0, i];
- }
- Error(n);
- while (!s[t.kind]) Get();
- return StartOf(syFol);
- }
- }
-
--->productions
-
- public static void Parse() {
- Errors.SynErr = new ErrorProc(SynErr);
- t = new Token();
- Get();
--->parseRoot
- }
-
- [Microsoft.Contracts.Verify(false)]
- static void SynErr(int n, string filename, int line, int col) {
- Errors.count++;
- System.Console.Write("{0}({1},{2}): syntax error: ", filename, line, col);
- string s;
- switch (n) {
--->errors
- default: s = "error " + n; break;
- }
- System.Console.WriteLine(s);
- }
-
- static bool[,]! set = {
--->initialization
- };
-
- [Microsoft.Contracts.Verify(false)]
- static Parser() {}
-} // end Parser
-
-} // end namespace
-$$$ \ No newline at end of file
diff --git a/Source/Dafny/scanner.frame b/Source/Dafny/scanner.frame
deleted file mode 100644
index a526c7f2..00000000
--- a/Source/Dafny/scanner.frame
+++ /dev/null
@@ -1,170 +0,0 @@
-using System.IO;
-using System.Collections;
-using System.Collections.Generic;
-using System.Text;
-using Microsoft.Contracts;
-using Bpl = Microsoft.Boogie;
-using BoogiePL;
-
-
-namespace Microsoft.Dafny {
-
- [Immutable]
- public class Token : Bpl.Token {
- public Token();
- public Token(int linenum, int colnum) {
- base(linenum, colnum);
- }
- public new static Token! NoToken = new Token();
- }
-
-}
-
-namespace Microsoft.-->namespace {
-
-
-public class Scanner {
- const char EOF = '\0';
- const char CR = '\r';
- const char LF = '\n';
-
- [Microsoft.Contracts.Verify(false)]
--->declarations
-
-
- static Token/*!*/ t; // current token
- static char ch; // current input character
- static int pos; // column number of current character
- static int line; // line number of current character
- static int lineStart; // start position of current line
- static Queue! oldEols; // EOLs that appeared in a comment;
- static BitArray/*!*/ ignore; // set of characters to be ignored by the scanner
- static string Filename;
-
- ///<summary>
- ///Initializes the scanner. Note: first fill the Buffer.
- ///</summary>
- ///<param name="filename">File name used for error reporting</param>
- public static void Init (string filename) {
- Filename = filename;
- pos = -1; line = 1; lineStart = 0;
- oldEols = new Queue();
- NextCh();
--->initialization
- }
-
- private static void NextCh() {
- if (oldEols.Count > 0) {
- ch = (char) ((!)oldEols.Dequeue());
- } else {
- while (true) {
- ch = (char)BoogiePL.Buffer.Read(); pos++;
- if (ch == BoogiePL.Buffer.eof) {
- ch = EOF;
- } else if (ch == LF) {
- line++;
- lineStart = pos + 1;
-
- } else if (ch == '#' && pos == lineStart) {
- int prLine = line;
- int prColumn = pos - lineStart; // which is 0
-
- string hashLine = BoogiePL.Buffer.ReadToEOL(); pos += hashLine.Length;
- line++;
- lineStart = pos + 1;
-
- hashLine = hashLine.TrimEnd(null);
- if (hashLine.StartsWith("line ") || hashLine == "line") {
- // parse #line pragma: #line num [filename]
- string h = hashLine.Substring(4).TrimStart(null);
- int x = h.IndexOf(' ');
- if (x == -1) {
- x = h.Length; // this will be convenient below when we look for a filename
- }
- try {
- int li = int.Parse(h.Substring(0, x));
-
- h = h.Substring(x).Trim();
-
- // act on #line
- line = li;
- if (h.Length != 0) {
- // a filename was specified
- Filename = h;
- }
- continue; // successfully parsed and acted on the #line pragma
-
- } catch (System.FormatException) {
- // just fall down through to produce an error message
- }
- Errors.SemErr(Filename, prLine, prColumn, "Malformed (#line num [filename]) pragma: #" + hashLine);
- continue;
- }
-
- Errors.SemErr(Filename, prLine, prColumn, "Unrecognized pragma: #" + hashLine);
- continue;
- }
- return;
- }
- }
- }
-
--->comment
-
- static void CheckLiteral() {
- switch (t.val) {
--->literals
- }
- }
-
- public static Token/*!*/ Scan() {
- while (ignore[ch]) { NextCh(); }
--->scan1
- t = new Token();
- t.pos = pos; t.col = pos - lineStart + 1; t.line = line; t.filename = Filename;
- int state = (/*^ (!) ^*/ start)[ch];
- StringBuilder buf = new StringBuilder(16);
- buf.Append(ch); NextCh();
-
- switch (state) {
- case 0: {t.kind = noSym; goto done;} // NextCh already done
--->scan2
- }
- done:
- t.val = buf.ToString();
- return t;
- }
-
-} // end Scanner
-
-
-public delegate void ErrorProc(int n, string filename, int line, int col);
-
-public class Errors {
- public static int count = 0; // number of errors detected
- public static ErrorProc/*!*/ SynErr; // syntactic errors
-
- public static void SemErr(string filename, int line, int col, string! msg) { // semantic errors
- System.ConsoleColor color = System.Console.ForegroundColor;
- System.Console.ForegroundColor = System.ConsoleColor.Red;
- System.Console.WriteLine("{0}({1},{2}): Error: {3}", filename, line, col, msg);
- System.Console.ForegroundColor = color;
- count++;
- }
-
- public static void SemErr(Bpl.IToken! tok, string! msg) { // semantic errors
- SemErr(tok.filename, tok.line, tok.col, msg);
- }
-
- public static void Exception (string s) {
- System.ConsoleColor color = System.Console.ForegroundColor;
- System.Console.ForegroundColor = System.ConsoleColor.Red;
- System.Console.WriteLine(s);
- System.Console.ForegroundColor = color;
- System.Environment.Exit(0);
- }
-
-} // Errors
-
-} // end namespace
-$$$
diff --git a/Source/DafnyDriver/DafnyDriver.ssc b/Source/DafnyDriver/DafnyDriver.ssc
index 8920db94..d9d9a6be 100644
--- a/Source/DafnyDriver/DafnyDriver.ssc
+++ b/Source/DafnyDriver/DafnyDriver.ssc
@@ -350,7 +350,7 @@ namespace Microsoft.Boogie
/// </summary>
static Program ParseBoogieProgram(List<string!>! fileNames, bool suppressTraceOutput)
{
- BoogiePL.Errors.count = 0;
+ //BoogiePL.Errors.count = 0;
Program program = null;
bool okay = true;
foreach (string bplFileName in fileNames) {
@@ -366,9 +366,9 @@ namespace Microsoft.Boogie
Program programSnippet;
int errorCount;
try {
- errorCount = BoogiePL.Parser.Parse(bplFileName, out programSnippet);
+ errorCount = Microsoft.Boogie.Parser.Parse(bplFileName, out programSnippet);
if (programSnippet == null || errorCount != 0) {
- Console.WriteLine("{0} parse errors detected in {1}", BoogiePL.Errors.count, bplFileName);
+ Console.WriteLine("{0} parse errors detected in {1}", errorCount, bplFileName);
okay = false;
continue;
}
diff --git a/Test/test0/Answer b/Test/test0/Answer
index 90721188..8d9ba2c3 100644
--- a/Test/test0/Answer
+++ b/Test/test0/Answer
@@ -99,9 +99,9 @@ WhereParsing.bpl(15,33): Error: where clause not allowed here
WhereParsing0.bpl(17,38): Error: where clause not allowed here
WhereParsing0.bpl(18,38): Error: where clause not allowed here
2 parse errors detected in WhereParsing0.bpl
-WhereParsing1.bpl(14,27): syntax error: ) expected
+WhereParsing1.bpl(14,27): syntax error: ")" expected
1 parse errors detected in WhereParsing1.bpl
-WhereParsing2.bpl(1,14): syntax error: ; expected
+WhereParsing2.bpl(1,14): syntax error: ";" expected
1 parse errors detected in WhereParsing2.bpl
WhereResolution.bpl(28,38): Error: undeclared identifier: alpha
WhereResolution.bpl(32,30): Error: old expressions allowed only in two-state contexts