Răsfoiți Sursa

Fixed shift/reduce conflicts by making vardecs list right-recursive

Taddeus Kroes 12 ani în urmă
părinte
comite
d7b07541bb
2 a modificat fișierele cu 9 adăugiri și 3 ștergeri
  1. 1 1
      Makefile
  2. 8 2
      parser.mly

+ 1 - 1
Makefile

@@ -10,7 +10,7 @@ LIBS := str unix
 OCAMLFLAGS := -g
 
 OCAMLYACC := menhir
-YFLAGS := --infer
+YFLAGS := --infer --explain
 
 CIVAS := ../bin32/civas
 CIVVM := ../bin32/civvm

+ 8 - 2
parser.mly

@@ -53,6 +53,12 @@
 
 %%
 
+(* Right-recursive list (less efficient then left-recursive list(x), only use
+ * when followed by left-recursive list to resolve conflicts) *)
+rlist(x):
+    |            { [] }
+    | rlist(x) x { $1 @ [$2] }
+
 basic_type:
     | FLOAT { Float }
     | INT   { Int }
@@ -116,7 +122,7 @@ param:
       Param (ArrayDims (ctype, make_dims dimloc dims), name, loc) }
 
 fun_body:
-    | var_dec* local_fun_dec* statement* loption(return_statement)
+    | rlist(var_dec); local_fun_dec*; statement*; loption(return_statement)
     { VarDecs $1 :: (LocalFuns $2) :: $3 @ $4 }
 
 return_statement:
@@ -126,7 +132,7 @@ return_statement:
 
 (* function: use location of function name *)
 local_fun_dec:
-    hdr=fun_header; LBRACE; body=fun_body; RBRACE
+    | hdr=fun_header; LBRACE; body=fun_body; RBRACE
     { let (t, n, p, nameloc) = hdr in
       FunDef (false, t, n, p, Block body, nameloc) }