5 True. Bool ::= "true" ;
6 False. Bool ::= "false" ;
9 TBool. Type ::= "bool" ;
11 Program. Stms ::= [Stm] ;
14 SExp. Stm ::= Exp ";" ;
15 SBlock. Stm ::= "{" [Stm] "}" ;
16 declIntE. Stm ::= "int" Ident "=" Exp ";" ;
17 declBoolE. Stm ::= "bool" Ident "=" Exp ";" ;
18 define declIntE x e = SDecl TInt x e;
19 define declBoolE x e = SDecl TBool x e;
20 declInt. Stm ::= "int" Ident ";" ;
21 declBool. Stm ::= "bool" Ident ";" ;
22 define declInt x = SDecl TInt x (EInt 0);
23 define declBool x = SDecl TBool x (EBool False);
26 SWhile. Stm ::= "while" "(" Exp ")" Stm ;
27 SIf. Stm ::= "if" "(" Exp ")" Stm "else" Stm ;
28 if. Stm ::= "if" "(" Exp ")" Stm ;
29 define if e s = SIf e s SNoop ;
31 -- SFor. Stm ::= "for" "(" Stm Exp ";" Exp ")" Stm ;
32 SPrint. Stm ::= "print" Exp ";" ;
36 EAss. Exp ::= Ident "=" Exp;
38 compExp. Exp ::= Exp1 Op0 Exp1 ;
39 define compExp e1 o e2 = BiOpExp e1 o e2 ;
41 op1. Exp1 ::= Exp1 Op1 Exp2 ;
42 define op1 e1 o e2 = BiOpExp e1 o e2 ;
44 op2. Exp2 ::= Exp2 Op2 Exp3 ;
45 define op2 e1 o e2 = BiOpExp e1 o e2 ;
47 postIncr. Exp3 ::= Ident "++" ;
48 define postIncr i = EPost i Plus ;
50 postDecr. Exp3 ::= Ident "--" ;
51 define postDecr i = EPost i Minus ;
53 EVar. Exp3 ::= Ident ;
54 EInt. Exp3 ::= Integer ;
55 EBool. Exp3 ::= Bool ;
57 ENeg. Exp3 ::= "-" Exp3 ;
58 ENot. Exp3 ::= "!" Exp3 ;
60 EReadI. Exp3 ::= "readInt" ;
61 EReadB. Exp3 ::= "readBool" ;
67 -- _. Stm ::= Stm ";" ;
92 -- internal ExpT. Exp ::= Type Exp ;
93 -- internal EDefault. Exp ::= ;
94 internal BiOpExp. Exp ::= Exp Op Exp ;
95 -- internal NoType. Type ::= ;
96 internal EPost. Exp ::= Ident Op1 ;
98 internal SNoop. Stm ::= ;
99 internal SDecl. Stm ::= Type Ident "=" Exp ";" ;
104 entrypoints Stms, Exp ;