& {\delimit} &{\terminal{if}} {\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} {\nonterminal{Stm}} {\terminal{else}} {\nonterminal{Stm}} \\
& {\delimit} &{\terminal{while}} {\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} {\nonterminal{Stm}} \\
& {\delimit} &{\terminal{print}} {\nonterminal{Exp}} {\terminal{;}} \\
- & {\delimit} &{\nonterminal{Stm}} {\terminal{;}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp}} & {\arrow} &{\nonterminal{Exp1}} {\nonterminal{BOp}} {\nonterminal{Exp1}} \\
+ & {\delimit} &{\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Exp}} \\
& {\delimit} &{\nonterminal{Exp1}} \\
\end{tabular}\\
{\nonterminal{Exp3}} & {\arrow} &{\nonterminal{Ident}} {\terminal{{$+$}{$+$}}} \\
& {\delimit} &{\nonterminal{Ident}} {\terminal{{$-$}{$-$}}} \\
& {\delimit} &{\nonterminal{Ident}} \\
- & {\delimit} &{\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Exp}} \\
& {\delimit} &{\nonterminal{Integer}} \\
& {\delimit} &{\terminal{{$-$}}} {\nonterminal{Exp3}} \\
& {\delimit} &{\nonterminal{Bool}} \\
& {\delimit} &{\terminal{readInt}} \\
& {\delimit} &{\terminal{readBool}} \\
- & {\delimit} &{\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} \\
+ & {\delimit} &{\nonterminal{Exp4}} \\
+\end{tabular}\\
+
+\begin{tabular}{lll}
+{\nonterminal{Exp4}} & {\arrow} &{\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
| 'if' '(' Exp ')' Stm 'else' Stm { SIf $3 $5 $7 }
| 'while' '(' Exp ')' Stm { SWhile $3 $5 }
| 'print' Exp ';' { SPrint $2 }
- | Stm ';' { $1 }
Exp :: { Exp }
Exp : Exp1 BOp Exp1 { BExp $1 $2 $3 }
+ | Ident '=' Exp { EAss $1 $3 }
| Exp1 { $1 }
Exp3 : Ident '++' { postIncr_ $1 }
| Ident '--' { postDecr_ $1 }
| Ident { EVar $1 }
- | Ident '=' Exp { EAss $1 $3 }
| Integer { EInt $1 }
| '-' Exp3 { ENeg $2 }
| Bool { EBool $1 }
| 'readInt' { EReadI }
| 'readBool' { EReadB }
- | '(' Exp ')' { $2 }
+ | Exp4 { $1 }
+
+
+Exp4 :: { Exp }
+Exp4 : '(' Exp ')' { $2 }
ListStm :: { [Stm] }
prt i e = case e of
BExp exp0 bop exp -> prPrec i 0 (concatD [prt 1 exp0 , prt 0 bop , prt 1 exp])
EVar id -> prPrec i 3 (concatD [prt 0 id])
- EAss id exp -> prPrec i 3 (concatD [prt 0 id , doc (showString "=") , prt 0 exp])
+ EAss id exp -> prPrec i 0 (concatD [prt 0 id , doc (showString "=") , prt 0 exp])
EInt n -> prPrec i 3 (concatD [prt 0 n])
ENeg exp -> prPrec i 3 (concatD [doc (showString "-") , prt 3 exp])
EBool bool -> prPrec i 3 (concatD [prt 0 bool])
-- SFor. Stm ::= "for" "(" Stm Exp ";" Exp ")" Stm ;
SPrint. Stm ::= "print" Exp ";" ;
+EAss. Exp ::= Ident "=" Exp;
BExp. Exp ::= Exp1 BOp Exp1 ;
op1. Exp1 ::= Exp1 Op1 Exp2 ;
define op1 e1 o e2 = OpExp e1 o e2 ;
postDecr. Exp3 ::= Ident "--" ;
define postDecr i = EPost i Minus ;
EVar. Exp3 ::= Ident ;
-EAss. Exp3 ::= Ident "=" Exp;
EInt. Exp3 ::= Integer ;
ENeg. Exp3 ::= "-" Exp3 ;
EBool. Exp3 ::= Bool ;
coercions Exp 3 ;
-_. Stm ::= Stm ";" ;
+-- _. Stm ::= Stm ";" ;
terminator Stm "" ;