From 554fb3a6780c412b81dc935835c2760e4cbe0b4d Mon Sep 17 00:00:00 2001 From: rustanleino Date: Tue, 10 Aug 2010 02:16:29 +0000 Subject: Boogie: Added boolean code expressions (sans well-formedness checks on the input). --- Source/Core/BoogiePL.atg | 190 ++++++++++++++++++----------------------------- 1 file changed, 71 insertions(+), 119 deletions(-) (limited to 'Source/Core/BoogiePL.atg') diff --git a/Source/Core/BoogiePL.atg b/Source/Core/BoogiePL.atg index 42f9f735..fe302acb 100644 --- a/Source/Core/BoogiePL.atg +++ b/Source/Core/BoogiePL.atg @@ -38,7 +38,6 @@ public static int Parse (string! filename, /*maybe null*/ List defines, FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); -// Scanner scanner = new Scanner(stream); if (defines == null) { defines = new List(); @@ -49,9 +48,6 @@ public static int Parse (string! filename, /*maybe null*/ List defines, 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 parser.Parse(); @@ -65,48 +61,7 @@ public static int Parse (string! filename, /*maybe null*/ List defines, program = null; return parser.errors.count; } -/* - using (System.IO.StreamReader reader = new System.IO.StreamReader(filename)) { - Buffer.Fill(reader); - Scanner.Init(filename); - return Parse(out program); - } -*/ -} - -/// -///Returns the number of parsing errors encountered. If 0, "program" returns as -///the parsed program. -///Note: first initialize the Scanner. -/// -//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); - 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 @@ -639,60 +594,13 @@ SpecPrePost = (. Expr! e; VariableSeq! locals; BlockSeq! blocks; Token tok = null; QKeyValue kv = null; .) ( "requires" (. tok = t; .) { Attribute } - (Proposition ";" (. pre.Add(new Requires(tok, free, e, null, kv)); .) - | - SpecBody ";" - (. pre.Add(new Requires(tok, free, new BlockExpr(locals, blocks), null, kv)); .) - ) + Proposition ";" (. pre.Add(new Requires(tok, free, e, null, kv)); .) | "ensures" (. tok = t; .) { Attribute } - (Proposition ";" (. post.Add(new Ensures(tok, free, e, null, kv)); .) - | - SpecBody ";" - (. post.Add(new Ensures(tok, free, new BlockExpr(locals, blocks), null, kv)); .) - ) + Proposition ";" (. post.Add(new Ensures(tok, free, e, null, kv)); .) ) . -SpecBody -= (. locals = new VariableSeq(); Block! b; .) - "{{" - { LocalVars } - SpecBlock (. blocks = new BlockSeq(b); .) - { SpecBlock (. blocks.Add(b); .) - } - "}}" - . - -SpecBlock -= (. IToken! x; IToken! y; - Cmd c; IToken label; - CmdSeq cs = new CmdSeq(); - TokenSeq! xs; - StringSeq ss = new StringSeq(); - b = dummyBlock; - Expr! e; - .) - Ident ":" - { LabelOrCmd - (. if (c != null) { - assert label == null; - cs.Add(c); - } else { - assert label != null; - this.SemErr("SpecBlock's can only have one label"); - } - .) - } - ( "goto" (. y = t; .) - Idents (. foreach (IToken! s in xs) { ss.Add(s.val); } - b = new Block(x,x.val,cs,new GotoCmd(y,ss)); - .) - | "return" Expression - (. b = new Block(x,x.val,cs,new ReturnExprCmd(t,e)); .) - ) ";" - . - /*------------------------------------------------------------------------*/ ImplBody @@ -891,21 +799,29 @@ LabelOrCmd LabelOrAssign /* ensures (c == null) != (label != null) */ -= (. IToken! id; IToken! x; Expr! e, e0; += (. IToken! id; IToken! x, y; Expr! e, e0; c = dummyCmd; label = null; AssignLhs! lhs; List! lhss; List! rhss; + List! indexes; .) Ident (. x = t; .) ( ":" (. c = null; label = x; .) - | - MapAssignIndexes (. lhss = new List (); - lhss.Add(lhs); .) + + | (. lhss = new List(); .) + (. lhs = new SimpleAssignLhs(id, new IdentifierExpr(id, id.val)); .) + + { MapAssignIndex (. lhs = new MapAssignLhs(y, lhs, indexes); .) } + (. lhss.Add(lhs); .) + { "," Ident - MapAssignIndexes (. lhss.Add(lhs); .) + (. lhs = new SimpleAssignLhs(id, new IdentifierExpr(id, id.val)); .) + { MapAssignIndex (. lhs = new MapAssignLhs(y, lhs, indexes); .) } + (. lhss.Add(lhs); .) } + ":=" (. x = t; /* use location of := */ .) Expression (. rhss = new List (); rhss.Add(e0); .) @@ -916,27 +832,18 @@ LabelOrAssign ) . -MapAssignIndexes -= (. IToken! x; - AssignLhs! runningLhs = - new SimpleAssignLhs(assignedVariable, - new IdentifierExpr(assignedVariable, assignedVariable.val)); - List! indexes; - Expr! e0; +MapAssignIndex<.out IToken! x, out List! indexes.> += (. indexes = new List (); + Expr! e; .) - { - "[" (. x = t; - indexes = new List (); .) - [ - Expression (. indexes.Add(e0); .) - { "," - Expression (. indexes.Add(e0); .) - } - ] - "]" (. runningLhs = - new MapAssignLhs (x, runningLhs, indexes); .) - } - (. lhs = runningLhs; .) + "[" (. x = t; .) + [ + Expression (. indexes.Add(e); .) + { "," + Expression (. indexes.Add(e); .) + } + ] + "]" . /*------------------------------------------------------------------------*/ @@ -1296,6 +1203,8 @@ AtomExpression Bpl.Type! ty; QKeyValue kv; e = dummyExpr; + VariableSeq! locals; + List! blocks; .) ( "false" (. e = new LiteralExpr(t, false); .) | "true" (. e = new LiteralExpr(t, true); .) @@ -1335,9 +1244,52 @@ AtomExpression ) ")" | IfThenElseExpression + | CodeExpression (. e = new CodeExpr(locals, blocks); .) ) . +CodeExpression<.out VariableSeq! locals, out List! blocks.> += (. locals = new VariableSeq(); Block! b; + blocks = new List(); + .) + "|{" + { LocalVars } + SpecBlock (. blocks.Add(b); .) + { SpecBlock (. blocks.Add(b); .) + } + "}|" + . + +SpecBlock += (. IToken! x; IToken! y; + Cmd c; IToken label; + CmdSeq cs = new CmdSeq(); + TokenSeq! xs; + StringSeq ss = new StringSeq(); + b = dummyBlock; + Expr! e; + .) + Ident ":" + { LabelOrCmd + (. if (c != null) { + assert label == null; + cs.Add(c); + } else { + assert label != null; + SemErr("SpecBlock's can only have one label"); + } + .) + } + ( "goto" (. y = t; .) + Idents (. foreach (IToken! s in xs) { ss.Add(s.val); } + b = new Block(x,x.val,cs,new GotoCmd(y,ss)); + .) + | "return" Expression + (. b = new Block(x,x.val,cs,new ReturnExprCmd(t,e)); .) + ) + ";" + . + Attribute = (. Trigger trig = null; .) AttributeOrTrigger (. if (trig != null) this.SemErr("only attributes, not triggers, allowed here"); .) -- cgit v1.2.3