5 True. Bool ::= "true" ;
6 False. Bool ::= "false" ;
9 TBool. Type ::= "bool" ;
11 Program. Program ::= [FuncStm] ;
14 SExp. Stm ::= Exp ";" ;
15 SBlock. Stm ::= "{" [Stm] "}" ;
16 SDecl. Stm ::= Type Ident "=" Exp ";" ;
17 SDeclD. Stm ::= Type Ident ";" ;
20 SWhile. Stm ::= "while" "(" Exp ")" Stm ;
21 SIf. Stm ::= "if" "(" Exp ")" Stm "else" Stm ;
22 if. Stm ::= "if" "(" Exp ")" Stm ;
23 define if e s = SIf e s SNoop ;
25 -- SFor. Stm ::= "for" "(" Stm Exp ";" Exp ")" Stm ;
26 SPrint. Stm ::= "print" Exp ";" ;
28 SReturn. Stm ::= "return" Exp ";" ;
32 EAss. Exp ::= Ident "=" Exp;
34 compExp. Exp ::= Exp1 Op0 Exp1 ;
35 define compExp e1 o e2 = BiOpExp e1 o e2 ;
37 op1. Exp1 ::= Exp1 Op1 Exp2 ;
38 define op1 e1 o e2 = BiOpExp e1 o e2 ;
40 op2. Exp2 ::= Exp2 Op2 Exp3 ;
41 define op2 e1 o e2 = BiOpExp e1 o e2 ;
43 postIncr. Exp3 ::= Ident "++" ;
44 define postIncr i = EPost i Plus ;
46 postDecr. Exp3 ::= Ident "--" ;
47 define postDecr i = EPost i Minus ;
49 EVar. Exp3 ::= Ident ;
50 EInt. Exp3 ::= Integer ;
51 EBool. Exp3 ::= Bool ;
53 ENeg. Exp3 ::= "-" Exp3 ;
54 ENot. Exp3 ::= "!" Exp3 ;
56 EReadI. Exp3 ::= "readInt" ;
57 EReadB. Exp3 ::= "readBool" ;
59 EFunc. Exp3 ::= Ident "(" [Exp] ")" ;
66 -- _. Stm ::= Stm ";" ;
73 Decl. Decl ::= Type Ident ;
77 Func. Func ::= Type Ident "(" [Decl] ")" "{" [Stm] "}" ;
84 separator FuncStm "" ;
87 -- E2. Exps ::= Exp "," Exps ;
108 -- internal ExpT. Exp ::= Type Exp ;
109 -- internal EDefault. Exp ::= ;
110 internal BiOpExp. Exp ::= Exp Op Exp ;
111 -- internal NoType. Type ::= ;
112 internal EPost. Exp ::= Ident Op1 ;
114 internal SNoop. Stm ::= ;