[MLton] cvs commit: bugfix: grammar for programs

Stephen Weeks sweeks@mlton.org
Wed, 2 Feb 2005 10:59:05 -0800


sweeks      05/02/02 10:59:04

  Modified:    mlton/front-end ml.grm
  Log:
  MAIL bugfix: grammar for programs
  
  Fixed a bug in the grammar for programs that prevented sequences of
  expressions (separated by semicolons) after a topdec had already been
  processed.  For example, the following program was incorrectly
  rejected.
  
     val x = 0;
     ignore x;
     ignore x;
  
  Thanks to Andreas Rossberg for reporting the bug.
  
  The fix lead to much cleaner productions for programs than what we had
  before.  Here are (essentially) the new productions.
  
    program ::= exp ; program
              | topdecs
    topdecs ::=
              | topdec topdecs
              | ; program
  
  (exp and topdec had the same productions as before)

Revision  Changes    Path
1.43      +11 -15    mlton/mlton/front-end/ml.grm

Index: ml.grm
===================================================================
RCS file: /cvsroot/mlton/mlton/mlton/front-end/ml.grm,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- ml.grm	12 Jan 2005 21:56:02 -0000	1.42
+++ ml.grm	2 Feb 2005 18:59:04 -0000	1.43
@@ -285,6 +285,7 @@
        | exp_list of Exp.t list
        | exp_ps of Exp.t list
        | expnode of Exp.node
+       | expsAndTopdecs of Topdec.t list list
        | fctarg of FctArg.node
        | fctid of Fctid.t
        | field of Field.t
@@ -299,7 +300,6 @@
        | idEqual of Symbol.t * Region.t
        | idNoAsterisk of Symbol.t * Region.t
        | int of IntInf.t
-       | leadExps of Topdec.t list list
        | longcon of Longcon.t
        | longid of Symbol.t list * Region.t
        | longidEqual of Symbol.t list * Region.t
@@ -453,20 +453,16 @@
 
 %%
 
-program : topdecs                   (Program.T topdecs)
-        | leadExps                  (Program.T leadExps)
-        |                           (Program.T [])
-	 
-leadExps: exp SEMICOLON leadExps   ([Topdec.fromExp exp] :: leadExps)
-        | exp SEMICOLON topdecs    ([Topdec.fromExp exp] :: topdecs)
-	| exp SEMICOLON            ([[Topdec.fromExp exp]])
-	  
-topdecs : topdec                    ([[topdec]])
-        | SEMICOLON                 ([])
-        | SEMICOLON topdecs         ([] :: topdecs)
-        | topdec topdecs            (consTopdec (topdec, topdecs))
-        | SEMICOLON exp SEMICOLON topdecs  ([Topdec.fromExp exp] :: topdecs)
-        | SEMICOLON exp SEMICOLON   ([[Topdec.fromExp exp]])
+program: expsAndTopdecs (Program.T expsAndTopdecs)
+
+expsAndTopdecs:
+    exp SEMICOLON expsAndTopdecs ([Topdec.fromExp exp] :: expsAndTopdecs)
+  | topdecs (topdecs)
+    
+topdecs:
+      ([])
+  | topdec topdecs (consTopdec (topdec, topdecs))
+  | SEMICOLON expsAndTopdecs ([] :: expsAndTopdecs)
 
 topdec : topdecnode (Topdec.makeRegion' (topdecnode,
 					 topdecnodeleft,