Skip to content

Commit

Permalink
Fix parsing of true/false in Pancake
Browse files Browse the repository at this point in the history
These aren't in the concrete syntax, so map them to 1 and 0 C-style

Addresses (the easy part of) issue #939
  • Loading branch information
IlmariReissumies committed May 25, 2023
1 parent 5e0612a commit 6291302
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pancake/parser/panConcreteExamplesScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ val ex2 = ‘if b & (a ^ c) & d {
goo(4, 5, 6);
}’;

val treeEx2 = parse_pancake ex2;
val treeEx2 = check_success $ parse_pancake ex2;

(** We also have a selection of boolean operators and
a ‘return’ statement. *)
(** FIXME: Add ‘true’ and ‘false’ to EBaseNT *)
val ex3 = ‘if b & (a ^ c) & d { return true; } else { return false; }’;

val treeEx3 = (* check_success $ *) parse_pancake ex3;
val treeEx3 = check_success $ parse_pancake ex3;

(** Loops: standard looping construct. *)

Expand Down
8 changes: 4 additions & 4 deletions pancake/parser/panLexerScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ val _ = new_theory "panLexer";
Datatype:
keyword = SkipK | StoreK | StoreBK | IfK | ElseK | WhileK
| BrK | ContK | RaiseK | RetK | TicK | VarK | WithK | HandleK
| LdsK | LdbK | BaseK | InK
| LdsK | LdbK | BaseK | InK | TrueK | FalseK
End

Datatype:
token = AndT | OrT | XorT | NotT
| EqT | NeqT | LessT | GreaterT | GeqT | LeqT
| PlusT | MinusT | HashT | DotT | StarT
| LslT | LsrT | AsrT | RorT
| TrueT | FalseT | IntT int | IdentT string
| IntT int | IdentT string
| LParT | RParT | CommaT | SemiT | ColonT | DArrowT | AddrT
| LBrakT | RBrakT | LCurT | RCurT
| AssignT
Expand Down Expand Up @@ -110,8 +110,8 @@ Definition get_keyword_def:
if s = "lds" then (KeywordT LdsK) else
if s = "ldb" then (KeywordT LdbK) else
if s = "@base" then (KeywordT BaseK) else
if s = "true" then TrueT else
if s = "false" then FalseT else
if s = "true" then (KeywordT TrueK) else
if s = "false" then (KeywordT FalseK) else
if isPREFIX "@" s ∨ s = "" then LexErrorT else
IdentT s
End
Expand Down
4 changes: 3 additions & 1 deletion pancake/parser/panPEGScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ Definition pancake_peg_def[nocompute]:
(INL EBaseNT, seql [choicel [seql [consume_tok LParT;
mknt ExpNT;
consume_tok RParT] I;
keep_kw TrueK; keep_kw FalseK;
keep_int; keep_ident; mknt LabelNT;
mknt StructNT; mknt LoadNT;
mknt LoadByteNT; keep_kw BaseK];
mknt LoadByteNT; keep_kw BaseK;
];
rpt (seql [consume_tok DotT; keep_nat] I)
FLAT]
(mksubtree EBaseNT));
Expand Down
2 changes: 2 additions & 0 deletions pancake/parser/panPtreeConversionScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ Definition conv_Exp_def:
| (e::es) => conv_binaryExps es ' (conv_Exp e)
else NONE) ∧
(conv_Exp leaf = if tokcheck leaf (kw BaseK) then SOME BaseAddr
else if tokcheck leaf (kw TrueK) then SOME $ Const 1w
else if tokcheck leaf (kw FalseK) then SOME $ Const 0w
else NONE) ∧
conv_binaryExps [] e = SOME e ∧
(conv_binaryExps (t1::t2::ts) res =
Expand Down

0 comments on commit 6291302

Please sign in to comment.