]> ruin.nu Git - proglang.git/commitdiff
removed most shift/reduce conflicts by moving EAss from Exp3 to Exp and thus disallow...
authorMichael Andreen <harv@ruin.nu>
Sun, 26 Feb 2006 20:50:51 +0000 (20:50 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 26 Feb 2006 20:50:51 +0000 (20:50 +0000)
Docsyntax.tex
Parsyntax.y
Printsyntax.hs
syntax.cf

index b22e5448befef0133379770c9d9808a2e2ed5178..a4040dc8da604ba2614e495033c45b9c03029ef7 100644 (file)
@@ -80,11 +80,11 @@ All other symbols are terminals.\\
  & {\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}  &{\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}}  \\
 \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}\\
 
  & {\delimit}  &{\nonterminal{Exp1}}  \\
 \end{tabular}\\
 
@@ -102,13 +102,16 @@ All other symbols are terminals.\\
 {\nonterminal{Exp3}} & {\arrow}  &{\nonterminal{Ident}} {\terminal{{$+$}{$+$}}}  \\
  & {\delimit}  &{\nonterminal{Ident}} {\terminal{{$-$}{$-$}}}  \\
  & {\delimit}  &{\nonterminal{Ident}}  \\
 {\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}  &{\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}
 \end{tabular}\\
 
 \begin{tabular}{lll}
index 6fef6bad9bb89672f5902fd0fdc9a14d732c349a..8bf7c6812d4ca3074be5f2e493c57b5359353263 100644 (file)
@@ -67,11 +67,11 @@ Stm : Type Ident '=' Exp ';' { SDecl $1 $2 $4 }
   | 'if' '(' Exp ')' Stm 'else' Stm { SIf $3 $5 $7 }
   | 'while' '(' Exp ')' Stm { SWhile $3 $5 }
   | 'print' Exp ';' { SPrint $2 }
   | '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 } 
 
 
 Exp :: { Exp }
 Exp : Exp1 BOp Exp1 { BExp $1 $2 $3 } 
+  | Ident '=' Exp { EAss $1 $3 }
   | Exp1 { $1 }
 
 
   | Exp1 { $1 }
 
 
@@ -89,13 +89,16 @@ Exp3 :: { Exp }
 Exp3 : Ident '++' { postIncr_ $1 } 
   | Ident '--' { postDecr_ $1 }
   | Ident { EVar $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 }
   | Integer { EInt $1 }
   | '-' Exp3 { ENeg $2 }
   | Bool { EBool $1 }
   | 'readInt' { EReadI }
   | 'readBool' { EReadB }
-  | '(' Exp ')' { $2 }
+  | Exp4 { $1 }
+
+
+Exp4 :: { Exp }
+Exp4 : '(' Exp ')' { $2 } 
 
 
 ListStm :: { [Stm] }
 
 
 ListStm :: { [Stm] }
index aeb32584f78b7bd2a380d9ed2361ab0e57b33fed..1d1068749e5bc7d85c4411c7eb9efdf905125d07 100644 (file)
@@ -105,7 +105,7 @@ instance Print Exp where
   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])
   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])
    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])
index fae1234c287f73180e784eb039d7a68169a81bb8..dc7e65960cacd24d1430ed90c02bf9ba07c69c8a 100644 (file)
--- a/syntax.cf
+++ b/syntax.cf
@@ -16,6 +16,7 @@ SWhile.   Stm      ::= "while" "(" Exp ")" Stm ;
 -- SFor.     Stm      ::= "for" "(" Stm Exp ";" Exp ")" Stm ;
 SPrint.   Stm      ::= "print" Exp ";" ;
 
 -- 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 ;
 BExp.     Exp     ::= Exp1 BOp Exp1 ;
 op1.      Exp1    ::= Exp1 Op1 Exp2 ;
 define op1 e1 o e2 = OpExp e1 o e2 ;
@@ -26,7 +27,6 @@ define postIncr i = EPost i Plus ;
 postDecr.    Exp3    ::= Ident "--" ;
 define postDecr i = EPost i Minus ;
 EVar.     Exp3    ::= Ident ;
 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 ;
 EInt.     Exp3    ::= Integer ;
 ENeg.     Exp3    ::= "-" Exp3 ;
 EBool.    Exp3    ::= Bool ;
@@ -36,7 +36,7 @@ EReadB.   Exp3    ::= "readBool" ;
 coercions Exp 3 ;
 
 
 coercions Exp 3 ;
 
 
-_.        Stm     ::= Stm ";" ;
+-- _.        Stm     ::= Stm ";" ;
 
 
 terminator Stm "" ;
 
 
 terminator Stm "" ;