From a537984b725aaf2b8250fa8000662d32334e10f1 Mon Sep 17 00:00:00 2001 From: wuestholz Date: Tue, 6 Dec 2011 23:20:12 +0100 Subject: Dafny: Made some minor changes to the grammar. --- Source/Dafny/Dafny.atg | 57 +++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 22 deletions(-) (limited to 'Source/Dafny/Dafny.atg') diff --git a/Source/Dafny/Dafny.atg b/Source/Dafny/Dafny.atg index 2eaaca7f..7019a22b 100644 --- a/Source/Dafny/Dafny.atg +++ b/Source/Dafny/Dafny.atg @@ -191,6 +191,7 @@ ClassDecl List members = new List(); IToken bodyStart; .) + SYNC "class" { Attribute } Ident @@ -234,6 +235,7 @@ DatatypeDecl List ctors = new List(); IToken bodyStart = Token.NoToken; // dummy assignment .) + SYNC "datatype" { Attribute } Ident @@ -241,7 +243,7 @@ DatatypeDecl "=" (. bodyStart = t; .) DatatypeMemberDecl { "|" DatatypeMemberDecl } - ";" + SYNC ";" (. dt = new DatatypeDecl(id, id.val, module, typeArgs, ctors, attrs); dt.BodyStartTok = bodyStart; dt.BodyEndTok = t; @@ -263,6 +265,7 @@ FieldDecl<.MemberModifiers mmod, List/*!*/ mm.> Attributes attrs = null; IToken/*!*/ id; Type/*!*/ ty; .) + SYNC "var" (. if (mmod.IsUnlimited) { SemErr(t, "fields cannot be declared 'unlimited'"); } if (mmod.IsStatic) { SemErr(t, "fields cannot be declared 'static'"); } @@ -271,7 +274,7 @@ FieldDecl<.MemberModifiers mmod, List/*!*/ mm.> IdentType (. mm.Add(new Field(id, id.val, mmod.IsGhost, ty, attrs)); .) { "," IdentType (. mm.Add(new Field(id, id.val, mmod.IsGhost, ty, attrs)); .) } - ";" + SYNC ";" . CouplingInvDecl<.MemberModifiers mmod, List/*!*/ mm.> = (. Contract.Requires(cce.NonNullElements(mm)); @@ -379,6 +382,7 @@ MethodDecl IToken bodyStart = Token.NoToken; IToken bodyEnd = Token.NoToken; .) + SYNC ( "method" | "constructor" (. if (allowConstructor) { isConstructor = true; @@ -423,16 +427,17 @@ MethodSpec<.List/*!*/ req, List/ = (. Contract.Requires(cce.NonNullElements(req)); Contract.Requires(cce.NonNullElements(mod)); Contract.Requires(cce.NonNullElements(ens)); Contract.Requires(cce.NonNullElements(decreases)); Expression/*!*/ e; FrameExpression/*!*/ fe; bool isFree = false; .) + SYNC ( "modifies" [ FrameExpression (. mod.Add(fe); .) { "," FrameExpression (. mod.Add(fe); .) } - ] ";" + ] SYNC ";" | [ "free" (. isFree = true; .) ] - ( "requires" Expression ";" (. req.Add(new MaybeFreeExpression(e, isFree)); .) - | "ensures" Expression ";" (. ens.Add(new MaybeFreeExpression(e, isFree)); .) + ( "requires" Expression SYNC ";" (. req.Add(new MaybeFreeExpression(e, isFree)); .) + | "ensures" Expression SYNC ";" (. ens.Add(new MaybeFreeExpression(e, isFree)); .) ) - | "decreases" DecreasesList ";" + | "decreases" DecreasesList SYNC ";" ) . Formals<.bool incoming, bool allowGhostKeyword, List/*!*/ formals.> @@ -555,13 +560,15 @@ FunctionDecl FunctionSpec<.List/*!*/ reqs, List/*!*/ reads, List/*!*/ ens, List/*!*/ decreases.> = (. Contract.Requires(cce.NonNullElements(reqs)); Contract.Requires(cce.NonNullElements(reads)); Contract.Requires(cce.NonNullElements(decreases)); Expression/*!*/ e; FrameExpression/*!*/ fe; .) - ( "requires" Expression ";" (. reqs.Add(e); .) + ( + SYNC + "requires" Expression SYNC ";" (. reqs.Add(e); .) | "reads" [ PossiblyWildFrameExpression (. reads.Add(fe); .) { "," PossiblyWildFrameExpression (. reads.Add(fe); .) } - ] ";" - | "ensures" Expression ";" (. ens.Add(e); .) - | "decreases" DecreasesList ";" + ] SYNC ";" + | "ensures" Expression SYNC ";" (. ens.Add(e); .) + | "decreases" DecreasesList SYNC ";" ) . PossiblyWildExpression @@ -622,6 +629,7 @@ OneStmt int breakCount; .) /* This list does not contain BlockStmt, see comment above in Stmt production. */ + SYNC ( BlockStmt | AssertStmt | AssumeStmt @@ -640,6 +648,7 @@ OneStmt | { "break" (. breakCount++; .) } ) + SYNC ";" (. s = label != null ? new BreakStmt(x, label) : new BreakStmt(x, breakCount); .) | ReturnStmt ) @@ -814,25 +823,29 @@ WhileStmt ) . LoopSpec<.out List invariants, out List decreases, out List mod.> -= (. bool isFree; Expression/*!*/ e; FrameExpression/*!*/ fe; += (. FrameExpression/*!*/ fe; invariants = new List(); + MaybeFreeExpression invariant = null; decreases = new List(); mod = null; .) - { (. isFree = false; .) - [ "free" (. isFree = true; .) - ] - "invariant" - Expression (. invariants.Add(new MaybeFreeExpression(e, isFree)); .) - ";" - | "decreases" DecreasesList ";" - | "modifies" (. mod = mod ?? new List(); .) + { + Invariant SYNC ";" (. invariants.Add(invariant); .) + | SYNC "decreases" DecreasesList SYNC ";" + | SYNC "modifies" (. mod = mod ?? new List(); .) [ FrameExpression (. mod.Add(fe); .) { "," FrameExpression (. mod.Add(fe); .) } - ] ";" + ] SYNC ";" } . +Invariant += (. bool isFree = false; Expression/*!*/ e; invariant = null; .) + SYNC + ["free" (. isFree = true; .) + ] + "invariant" Expression (. invariant = new MaybeFreeExpression(e, isFree); .) + . DecreasesList<.List decreases, bool allowWildcard.> = (. Expression/*!*/ e; .) PossiblyWildExpression (. if (!allowWildcard && e is WildcardExpr) { @@ -1310,8 +1323,8 @@ Suffix } ) | ".." (. anyDots = true; .) - [ Expression (. e1 = ee; .) - ] + [ Expression (. e1 = ee; .) + ] ) (. if (multipleIndices != null) { e = new MultiSelectExpr(x, e, multipleIndices); -- cgit v1.2.3