[MLton-commit] r7065

Matthew Fluet fluet at mlton.org
Wed Apr 8 05:32:58 PDT 2009


Minimize diff with SML/NJ upstream version of ml-yacc tool.

Since we now use the default int and word type provided by the host
compiler, there is no need for the extra 'type int = Int.int' and
':int' in the sources of ml-yacc.  Minimizing the diff with SML/NJ
upstream means that it is easier to apply changes.
----------------------------------------------------------------------

U   mlton/trunk/lib/mlyacc/base.sig
U   mlton/trunk/lib/mlyacc/join.sml
U   mlton/trunk/lib/mlyacc/lrtable.sml
A   mlton/trunk/lib/mlyacc/ml-yacc-lib.cm
U   mlton/trunk/lib/mlyacc/parser1.sml
U   mlton/trunk/lib/mlyacc/parser2.sml
D   mlton/trunk/lib/mlyacc/sources.cm
U   mlton/trunk/lib/mlyacc/stream.sml
A   mlton/trunk/mlton/front-end/ml-yacc-lib-proxy.cm
U   mlton/trunk/mlton/front-end/sources.cm
U   mlton/trunk/mlton/mlton.cm
D   mlton/trunk/mlyacc/INSTALL
U   mlton/trunk/mlyacc/Makefile
U   mlton/trunk/mlyacc/README.MLton
U   mlton/trunk/mlyacc/doc/mlyacc.tex
U   mlton/trunk/mlyacc/doc/tech.doc
U   mlton/trunk/mlyacc/examples/calc/README
U   mlton/trunk/mlyacc/examples/calc/calc.lex
U   mlton/trunk/mlyacc/examples/calc/calc.sml
U   mlton/trunk/mlyacc/examples/fol/README
U   mlton/trunk/mlyacc/examples/fol/fol.grm
U   mlton/trunk/mlyacc/examples/fol/parse.sml
U   mlton/trunk/mlyacc/examples/pascal/README
U   mlton/trunk/mlyacc/examples/pascal/parser.sml
U   mlton/trunk/mlyacc/examples/pascal/pascal.grm
U   mlton/trunk/mlyacc/examples/pascal/pascal.lex
U   mlton/trunk/mlyacc/examples/pascal/test/c1.p
U   mlton/trunk/mlyacc/examples/pascal/test/t1.p
D   mlton/trunk/mlyacc/mlyacc.cm
U   mlton/trunk/mlyacc/mlyacc.mlb
D   mlton/trunk/mlyacc/sources.cm
D   mlton/trunk/mlyacc/sources.mlb
U   mlton/trunk/mlyacc/src/absyn.sig
U   mlton/trunk/mlyacc/src/absyn.sml
U   mlton/trunk/mlyacc/src/core.sml
U   mlton/trunk/mlyacc/src/coreutils.sml
D   mlton/trunk/mlyacc/src/export-yacc.sml
U   mlton/trunk/mlyacc/src/grammar.sml
U   mlton/trunk/mlyacc/src/graph.sml
U   mlton/trunk/mlyacc/src/hdr.sml
U   mlton/trunk/mlyacc/src/lalr.sml
U   mlton/trunk/mlyacc/src/link.sml
U   mlton/trunk/mlyacc/src/look.sml
U   mlton/trunk/mlyacc/src/mklrtable.sml
U   mlton/trunk/mlyacc/src/mkprstruct.sml
U   mlton/trunk/mlyacc/src/parse.sml
U   mlton/trunk/mlyacc/src/shrink.sml
U   mlton/trunk/mlyacc/src/sigs.sml
D   mlton/trunk/mlyacc/src/sources.cm
D   mlton/trunk/mlyacc/src/sources.mlb
U   mlton/trunk/mlyacc/src/utils.sig
U   mlton/trunk/mlyacc/src/utils.sml
U   mlton/trunk/mlyacc/src/verbose.sml
U   mlton/trunk/mlyacc/src/yacc.grm
U   mlton/trunk/mlyacc/src/yacc.lex
U   mlton/trunk/mlyacc/src/yacc.sml

----------------------------------------------------------------------

Modified: mlton/trunk/lib/mlyacc/base.sig
===================================================================
--- mlton/trunk/lib/mlyacc/base.sig	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/lib/mlyacc/base.sig	2009-04-08 12:32:52 UTC (rev 7065)
@@ -1,9 +1,3 @@
-(* Modified by mfluet at acm.org on 2005-8-01.
- * Update with SML/NJ 110.55+.
- *)
-(* Modified by sweeks at acm.org on 2000-8-24.
- * Ported to MLton.
- *)
 (* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi *)
 
 (* base.sig: Base signature file for SML-Yacc.  This file contains signatures
@@ -37,7 +31,7 @@
                         | ACCEPT
                         | ERROR
         type table
-        
+
         val numStates : table -> int
         val numRules : table -> int
         val describeActions : table -> state ->
@@ -69,7 +63,7 @@
    constructor function for a integer token might be
 
           INT: int * 'a * 'a -> 'a token.
- 
+
    This is not possible because we need to have tokens with the representation
    given below for the polymorphic parser.
 
@@ -106,7 +100,7 @@
                      arg: 'arg,
                      saction : int *
                                '_c *
-                                (LrTable.state * ('_b * '_c * '_c)) list * 
+                                (LrTable.state * ('_b * '_c * '_c)) list *
                                 'arg ->
                                      LrTable.nonterm *
                                      ('_b * '_c * '_c) *
@@ -145,7 +139,7 @@
                 type pos
                 type svalue
            end
-        val makeLexer : (int -> string) -> unit -> 
+        val makeLexer : (int -> string) -> unit ->
          (UserDeclarations.svalue,UserDeclarations.pos) UserDeclarations.token
    end
 
@@ -162,12 +156,12 @@
                 type svalue
                 type arg
            end
-        val makeLexer : (int -> string) -> UserDeclarations.arg -> unit -> 
+        val makeLexer : (int -> string) -> UserDeclarations.arg -> unit ->
          (UserDeclarations.svalue,UserDeclarations.pos) UserDeclarations.token
    end
 
 (* PARSER_DATA: the signature of ParserData structures in {parser name}LrValsFun
-   produced by  SML-Yacc.  All such structures match this signature.  
+   produced by  SML-Yacc.  All such structures match this signature.
 
    The {parser name}LrValsFun produces a structure which contains all the values
    except for the lexer needed to call the polymorphic parser mentioned
@@ -187,7 +181,7 @@
 
          (* the type of the user-supplied argument to the parser *)
         type arg
- 
+
         (* the intended type of the result of the parser.  This value is
            produced by applying extract from the structure Actions to the
            final semantic value resultiing from a parse.
@@ -204,7 +198,7 @@
            a default value for the semantic stack.
          *)
 
-        structure Actions : 
+        structure Actions :
           sig
               val actions : int * pos *
                    (LrTable.state * (svalue * pos * pos)) list * arg->
@@ -232,7 +226,7 @@
         val table : LrTable.table
     end
 
-(* signature PARSER is the signature that most user parsers created by 
+(* signature PARSER is the signature that most user parsers created by
    SML-Yacc will match.
 *)
 
@@ -252,7 +246,7 @@
 
          (* the type of the user-supplied argument to the parser *)
         type arg
-        
+
         (* type svalue is the type of semantic values for the semantic value
            stack
          *)
@@ -281,7 +275,7 @@
     lexer takes an additional argument.
 *)
 
-signature ARG_PARSER = 
+signature ARG_PARSER =
     sig
         structure Token : TOKEN
         structure Stream : STREAM
@@ -302,4 +296,3 @@
         val sameToken : (svalue,pos) Token.token * (svalue,pos) Token.token ->
                                 bool
      end
-

Modified: mlton/trunk/lib/mlyacc/join.sml
===================================================================
--- mlton/trunk/lib/mlyacc/join.sml	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/lib/mlyacc/join.sml	2009-04-08 12:32:52 UTC (rev 7065)
@@ -19,7 +19,7 @@
 struct
     structure Token = ParserData.Token
     structure Stream = LrParser.Stream
- 
+
     exception ParseError = LrParser.ParseError
 
     type arg = ParserData.arg
@@ -46,7 +46,7 @@
      val sameToken = Token.sameToken
 end
 
-(* functor JoinWithArg creates a variant of the parser structure produced 
+(* functor JoinWithArg creates a variant of the parser structure produced
    above.  In this case, the makeLexer take an additional argument before
    yielding a value of type unit -> (svalue,pos) token
  *)

Modified: mlton/trunk/lib/mlyacc/lrtable.sml
===================================================================
--- mlton/trunk/lib/mlyacc/lrtable.sml	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/lib/mlyacc/lrtable.sml	2009-04-08 12:32:52 UTC (rev 7065)
@@ -1,11 +1,5 @@
-(* Modified by mfluet at acm.org on 2005-8-01.
- * Update with SML/NJ 110.55+.
- *)
-(* Modified by sweeks at acm.org on 2000-8-24.
- * Ported to MLton.
- *)
 (* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi *)
-structure LrTable : LR_TABLE = 
+structure LrTable : LR_TABLE =
     struct
         open Array List
         infix 9 sub
@@ -25,7 +19,7 @@
         val numStates = fn ({states,...} : table) => states
         val numRules = fn ({rules,...} : table) => rules
         val describeActions =
-           fn ({action,...} : table) => 
+           fn ({action,...} : table) =>
                    fn (STATE s) => action sub s
         val describeGoto =
            fn ({goto,...} : table) =>

Copied: mlton/trunk/lib/mlyacc/ml-yacc-lib.cm (from rev 7064, mlton/trunk/lib/mlyacc/sources.cm)
===================================================================
--- mlton/trunk/lib/mlyacc/sources.cm	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/lib/mlyacc/ml-yacc-lib.cm	2009-04-08 12:32:52 UTC (rev 7065)
@@ -0,0 +1,30 @@
+(* sources file for ML-Yacc library *)
+
+Library
+
+signature STREAM
+signature LR_TABLE
+signature TOKEN
+signature LR_PARSER
+signature LEXER
+signature ARG_LEXER
+signature PARSER_DATA
+signature PARSER
+signature ARG_PARSER
+functor Join
+functor JoinWithArg
+structure LrTable
+structure Stream
+structure LrParser
+
+is
+
+#if defined(NEW_CM)
+  $/basis.cm
+#endif
+
+base.sig
+join.sml
+lrtable.sml
+stream.sml
+parser2.sml     (* error correcting version *)

Modified: mlton/trunk/lib/mlyacc/parser1.sml
===================================================================
--- mlton/trunk/lib/mlyacc/parser1.sml	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/lib/mlyacc/parser1.sml	2009-04-08 12:32:52 UTC (rev 7065)
@@ -2,7 +2,7 @@
 
 (* drt (12/15/89) -- the functor should be used during development work,
    but it is wastes space in the release version.
-   
+
 functor ParserGen(structure LrTable : LR_TABLE
                   structure Stream : STREAM) : LR_PARSER =
 *)
@@ -19,9 +19,9 @@
             datatype ('a,'b) token = TOKEN of LrTable.term * ('a * 'b * 'b)
             val sameToken = fn (TOKEN (t,_),TOKEN(t',_)) => t=t'
         end
-     
 
-     open LrTable 
+
+     open LrTable
      open Token
 
      val DEBUG = false
@@ -51,12 +51,12 @@
                             errtermvalue,showTerminal,
                             error,terms,noShift},
                       lookahead} =>
- let fun prAction(stack as (state, _) :: _, 
+ let fun prAction(stack as (state, _) :: _,
                   next as (TOKEN (term,_),_), action) =
              (println "Parse: state stack:";
               printStack(stack, 0);
               print("       state="
-                         ^ showState state      
+                         ^ showState state
                          ^ " next="
                          ^ showTerminal term
                          ^ " action="
@@ -95,4 +95,3 @@
    in parseStep(next,[(initialState table,(void,leftPos,leftPos))])
    end
 end;
-

Modified: mlton/trunk/lib/mlyacc/parser2.sml
===================================================================
--- mlton/trunk/lib/mlyacc/parser2.sml	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/lib/mlyacc/parser2.sml	2009-04-08 12:32:52 UTC (rev 7065)
@@ -1,9 +1,3 @@
-(* Modified by mfluet at acm.org on 2005-8-01.
- * Update with SML/NJ 110.55+.
- *)
-(* Modified by sweeks at acm.org on 2000-8-24.
- * Ported to MLton.
- *)
 (* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi *)
 
 (* parser.sml:  This is a parser driver for LR tables with an error-recovery
@@ -17,7 +11,7 @@
 
     This program is an implementation is the partial, deferred method discussed
     in the article.  The algorithm and data structures used in the program
-    are described below.  
+    are described below.
 
     This program assumes that all semantic actions are delayed.  A semantic
     action should produce a function from unit -> value instead of producing the
@@ -29,7 +23,7 @@
 
     Data Structures:
     ----------------
-        
+
         * The parser:
 
            The state stack has the type
@@ -37,7 +31,7 @@
                  (state * (semantic value * line # * line #)) list
 
            The parser keeps a queue of (state stack * lexer pair).  A lexer pair
-         consists of a terminal * value pair and a lexer.  This allows the 
+         consists of a terminal * value pair and a lexer.  This allows the
          parser to reconstruct the states for terminals to the left of a
          syntax error, and attempt to make error corrections there.
 
@@ -49,7 +43,7 @@
     Algorithm:
     ----------
 
-        * The steady-state parser:  
+        * The steady-state parser:
 
             This parser keeps the length of the queue of state stacks at
         a steady state by always removing an element from the front when
@@ -85,7 +79,7 @@
         tokens left unparsed, a queue, and an action option.
 *)
 
-signature FIFO = 
+signature FIFO =
   sig type 'a queue
       val empty : 'a queue
       exception Empty
@@ -139,11 +133,11 @@
       type ('a,'b) lexpair = ('a,'b) lexv * (('a,'b) lexv Stream.stream)
       type ('a,'b) distanceParse =
                  ('a,'b) lexpair *
-                 ('a,'b) stack * 
+                 ('a,'b) stack *
                  (('a,'b) stack * ('a,'b) lexpair) Fifo.queue *
                  int ->
                    ('a,'b) lexpair *
-                   ('a,'b) stack * 
+                   ('a,'b) stack *
                    (('a,'b) stack * ('a,'b) lexpair) Fifo.queue *
                    int *
                    action option
@@ -157,7 +151,7 @@
           showTerminal : term -> string,
           noShift : term -> bool}
 
-      local 
+      local
          val print = fn s => TextIO.output(TextIO.stdOut,s)
          val println = fn s => (print s; print "\n")
          val showState = fn (STATE s) => "STATE " ^ (Int.toString s)
@@ -169,13 +163,13 @@
                   println(showState state);
                   printStack(rest, n+1))
             | nil => ()
-                
+
         fun prAction showTerminal
                  (stack as (state,_) :: _, next as (TOKEN (term,_),_), action) =
              (println "Parse: state stack:";
               printStack(stack, 0);
               print("       state="
-                         ^ showState state      
+                         ^ showState state
                          ^ " next="
                          ^ showTerminal term
                          ^ " action="
@@ -195,7 +189,7 @@
         fixError is called with the arguments of parseStep (lexv,stack,and
         queue).  It returns the lexv, and a new stack and queue adjusted so
         that the lexv can be parsed *)
-        
+
     val ssParse =
       fn (table,showTerminal,saction,fixError,arg) =>
         let val prAction = prAction showTerminal
@@ -225,7 +219,7 @@
                                     queue)
                        | _ => raise (ParseImpossible 197))
                  | ERROR => parseStep(fixError args)
-                 | ACCEPT => 
+                 | ACCEPT =>
                         (case stack
                          of (_,(topvalue,_,_)) :: _ =>
                                 let val (token,restLexer) = lexPair
@@ -276,7 +270,7 @@
                  | ACCEPT => (lexPair,stack,queue,distance,SOME nextAction)
               end
            | parseStep _ = raise (ParseImpossible 242)
-        in parseStep : ('_a,'_b) distanceParse 
+        in parseStep : ('_a,'_b) distanceParse
         end
 
 (* mkFixError: function to create fixError function which adjusts parser state
@@ -286,7 +280,7 @@
               preferred_change,noShift,
               showTerminal,error,...} : ('_a,'_b) ecRecord,
              distanceParse : ('_a,'_b) distanceParse,
-             minAdvance,maxAdvance) 
+             minAdvance,maxAdvance)
 
             (lexv as (TOKEN (term,value as (_,leftPos,_)),_),stack,queue) =
     let val _ = if DEBUG2 then
@@ -300,7 +294,7 @@
 
         (* pull all the state * lexv elements from the queue *)
 
-        val stateList = 
+        val stateList =
            let fun f q = let val (elem,newQueue) = Fifo.get q
                          in elem :: (f newQueue)
                          end handle Fifo.Empty => nil
@@ -348,9 +342,9 @@
 
         fun parse (lexPair,stack,queuePos : int) =
             case distanceParse(lexPair,stack,Fifo.empty,queuePos+maxAdvance+1)
-             of (_,_,_,distance,SOME ACCEPT) => 
-                        if maxAdvance-distance-1 >= 0 
-                            then maxAdvance 
+             of (_,_,_,distance,SOME ACCEPT) =>
+                        if maxAdvance-distance-1 >= 0
+                            then maxAdvance
                             else maxAdvance-distance-1
               | (_,_,_,distance,_) => maxAdvance - distance - 1
 
@@ -361,12 +355,12 @@
         fun keywordsDelta new = if List.exists (fn(TOKEN(t,_))=>is_keyword t) new
                        then minDelta else 0
 
-        fun tryChange{lex,stack,pos:int,leftPos,rightPos,orig,new} =
+        fun tryChange{lex,stack,pos,leftPos,rightPos,orig,new} =
              let val lex' = List.foldr (fn (t',p)=>(t',Stream.cons p)) lex new
-                 val distance = parse(lex',stack,pos+List.length new-List.length orig)
-              in if distance >= minAdvance + keywordsDelta new 
+                 val distance = parse(lex',stack,pos+length new-length orig)
+              in if distance >= minAdvance + keywordsDelta new
                    then [CHANGE{pos=pos,leftPos=leftPos,rightPos=rightPos,
-                                distance=distance,orig=orig,new=new}] 
+                                distance=distance,orig=orig,new=new}]
                    else []
              end
 
@@ -395,7 +389,7 @@
                  tryChange{lex=lexPair,stack=stack,
                            pos=queuePos,orig=[],new=[tokAt(t,l)],
                            leftPos=l,rightPos=l})
-                              
+
 (* trySubst: try to substitute tokens for the current terminal;
        return a list of the successes  *)
 
@@ -412,8 +406,8 @@
      (* do_delete(toks,lexPair) tries to delete tokens "toks" from "lexPair".
          If it succeeds, returns SOME(toks',l,r,lp), where
              toks' is the actual tokens (with positions and values) deleted,
-             (l,r) are the (leftmost,rightmost) position of toks', 
-             lp is what remains of the stream after deletion 
+             (l,r) are the (leftmost,rightmost) position of toks',
+             lp is what remains of the stream after deletion
      *)
         fun do_delete(nil,lp as (TOKEN(_,(_,l,_)),_)) = SOME(nil,l,l,lp)
           | do_delete([t],(tok as TOKEN(t',(_,l,r)),lp')) =
@@ -427,13 +421,13 @@
                                SOME(tok::deleted,l,r',lp'')
                           | NONE => NONE
                    else NONE
-                             
+
         fun tryPreferred((stack,lexPair),queuePos) =
             catList preferred_change (fn (delete,insert) =>
                if List.exists noShift delete then [] (* should give warning at
                                                  parser-generation time *)
                else case do_delete(delete,lexPair)
-                     of SOME(deleted,l,r,lp) => 
+                     of SOME(deleted,l,r,lp) =>
                             tryChange{lex=lp,stack=stack,pos=queuePos,
                                       leftPos=l,rightPos=r,orig=deleted,
                                       new=map (fn t=>(tokAt(t,r))) insert}
@@ -446,7 +440,7 @@
                               catList numStateList (tryDelete 2) @
                                 catList numStateList (tryDelete 3)
 
-        val findMaxDist = fn l => 
+        val findMaxDist = fn l =>
           foldr (fn (CHANGE {distance,...},high) => Int.max(distance,high)) 0 l
 
 (* maxDist: max distance past error taken that we could parse *)
@@ -455,14 +449,14 @@
 
 (* remove changes which did not parse maxDist tokens past the error token *)
 
-        val changes = catList changes 
-              (fn(c as CHANGE{distance,...}) => 
+        val changes = catList changes
+              (fn(c as CHANGE{distance,...}) =>
                   if distance=maxDist then [c] else [])
 
-      in case changes 
+      in case changes
           of (l as change :: _) =>
               let fun print_msg (CHANGE {new,orig,leftPos,rightPos,...}) =
-                  let val s = 
+                  let val s =
                       case (orig,new)
                           of (_::_,[]) => "deleting " ^ (showTerms orig)
                            | ([],_::_) => "inserting " ^ (showTerms new)
@@ -470,8 +464,8 @@
                                  " with " ^ (showTerms new)
                   in error ("syntax error: " ^ s,leftPos,rightPos)
                   end
-                   
-                  val _ = 
+
+                  val _ =
                       (if length l > 1 andalso DEBUG2 then
                            (print "multiple fixes possible; could fix it by:\n";
                             app print_msg l;
@@ -499,7 +493,7 @@
                                           end
                       in f (rev stateList,n)
                       end
-                
+
                   val CHANGE {pos,orig,new,...} = change
                   val (last,queueFront) = findNth pos
                   val (stack,lexPair) = last
@@ -507,7 +501,7 @@
                   val lp1 = foldl(fn (_,(_,r)) => Stream.get r) lexPair orig
                   val lp2 = foldr(fn(t,r)=>(t,Stream.cons r)) lp1 new
 
-                  val restQueue = 
+                  val restQueue =
                       Fifo.put((stack,lp2),
                                foldl Fifo.put Fifo.empty queueFront)
 
@@ -545,4 +539,3 @@
         in loop (distanceParse(lexPair,startStack,startQueue,distance))
         end
  end;
-

Deleted: mlton/trunk/lib/mlyacc/sources.cm
===================================================================
--- mlton/trunk/lib/mlyacc/sources.cm	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/lib/mlyacc/sources.cm	2009-04-08 12:32:52 UTC (rev 7065)
@@ -1,33 +0,0 @@
-(* Modified by sweeks at acm.org on 2000-8-22.
- * Commented out Stream and STREAM exports.
- *)
-(* sources file for ML-Yacc library *)
-
-Library
-
-(* signature STREAM *)
-signature LR_TABLE
-signature TOKEN
-signature LR_PARSER
-signature LEXER
-signature ARG_LEXER
-signature PARSER_DATA
-signature PARSER
-signature ARG_PARSER
-functor Join
-functor JoinWithArg
-structure LrTable
-(* structure Stream *)
-structure LrParser
-
-is
-
-#if (defined (SMLNJ_VERSION))
-../basis-stubs-for-smlnj/sources.cm
-#endif
-
-base.sig
-join.sml
-lrtable.sml
-stream.sml
-parser2.sml     (* error correcting version *)

Modified: mlton/trunk/lib/mlyacc/stream.sml
===================================================================
--- mlton/trunk/lib/mlyacc/stream.sml	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/lib/mlyacc/stream.sml	2009-04-08 12:32:52 UTC (rev 7065)
@@ -10,7 +10,7 @@
    type 'a stream = 'a str ref
 
    fun get(ref(EVAL t)) = t
-     | get(s as ref(UNEVAL f)) = 
+     | get(s as ref(UNEVAL f)) =
             let val t = (f(), ref(UNEVAL f)) in s := EVAL t; t end
 
    fun streamify f = ref(UNEVAL f)

Added: mlton/trunk/mlton/front-end/ml-yacc-lib-proxy.cm
===================================================================
--- mlton/trunk/mlton/front-end/ml-yacc-lib-proxy.cm	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlton/front-end/ml-yacc-lib-proxy.cm	2009-04-08 12:32:52 UTC (rev 7065)
@@ -0,0 +1,16 @@
+(* Copyright (C) 2009 Matthew Fluet.
+ *
+ * MLton is released under a BSD-style license.
+ * See the file MLton-LICENSE for details.
+ *)
+
+Library
+
+library($/ml-yacc-lib.cm) - (
+  signature STREAM
+  structure Stream
+)
+
+is
+
+$/ml-yacc-lib.cm

Modified: mlton/trunk/mlton/front-end/sources.cm
===================================================================
--- mlton/trunk/mlton/front-end/sources.cm	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlton/front-end/sources.cm	2009-04-08 12:32:52 UTC (rev 7065)
@@ -15,7 +15,11 @@
 is
 
 ../../lib/mlton/sources.cm
-../../lib/mlyacc/sources.cm
+#if (defined (SMLNJ_VERSION))
+ml-yacc-lib-proxy.cm
+#else
+../../lib/mlyacc/ml-yacc-lib.cm
+#endif
 ../ast/sources.cm
 ../control/sources.cm
 

Modified: mlton/trunk/mlton/mlton.cm
===================================================================
--- mlton/trunk/mlton/mlton.cm	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlton/mlton.cm	2009-04-08 12:32:52 UTC (rev 7065)
@@ -10,6 +10,6 @@
 
 upgrade-basis.sml
 (* Need to elaborate ML-Yacc library in Basis Library, not MLton library. *)
-../lib/mlyacc/sources.cm
+../lib/mlyacc/ml-yacc-lib.cm
 sources.cm
 call-main.sml

Deleted: mlton/trunk/mlyacc/INSTALL
===================================================================
--- mlton/trunk/mlyacc/INSTALL	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/INSTALL	2009-04-08 12:32:52 UTC (rev 7065)
@@ -1,26 +0,0 @@
-Installation instructions for ML-Yacc
--------------------------------------
-
-ML-Yacc will normally be automatically
-installed as part of the SML/NJ system
-by the SML/NJ installer.
-
-To install by hand (e.g., if you make
-your own modifications), run the
-
-    ./build
-
-script in this directory and then move
-the file
-
-    src/ml-yacc.$ARCH-$OS
-
-to the heap-file directory.
-
-Running ./build requires a properly
-functioning installation of SML/NJ.
-If you make modifications to lexer or
-parser, be sure to also have properly
-functioning instances of ml-lex and
-ml-yacc installed before you run
-./build.

Modified: mlton/trunk/mlyacc/Makefile
===================================================================
--- mlton/trunk/mlyacc/Makefile	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/Makefile	2009-04-08 12:32:52 UTC (rev 7065)
@@ -1,4 +1,5 @@
-## Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+## Copyright (C) 2009 Matthew Fluet.
+ # Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
  #    Jagannathan, and Stephen Weeks.
  # Copyright (C) 1997-2000 NEC Research Institute.
  #
@@ -22,9 +23,6 @@
 	@echo 'Compiling $(NAME)'
 	"$(MLTON)" $(FLAGS) $(NAME).mlb
 
-$(NAME).sml: $(NAME).cm $(shell "$(MLTON)" -stop f $(NAME).cm)
-	mlton -stop sml $(NAME).cm
-
 src/yacc.lex.sml: src/yacc.lex
 	rm -f src/yacc.lex.sml && \
 		mllex src/yacc.lex && \

Modified: mlton/trunk/mlyacc/README.MLton
===================================================================
--- mlton/trunk/mlyacc/README.MLton	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/README.MLton	2009-04-08 12:32:52 UTC (rev 7065)
@@ -1,11 +1,56 @@
-This is a modified version of the ml-yacc directory that comes with SML/NJ
-110.55.  I made a few changes so that the sources are compilable with MLton.
+This is a modified version of the ml-lex directory that comes with SML/NJ.
 
-mfluet at acm.org  2005-7-21
+Files from SML/NJ:
+  COPYRIGHT
+  INSTALL -- deleted
+  build -- deleted
+  build.bat -- deleted
+  doc/
+  examples/
+  lib/base.sig -- moved to <src>/lib/mlyacc
+  lib/join.sml -- moved to <src>/lib/mlyacc
+  lib/lrtable.sml -- moved to <src>/lib/mlyacc
+  lib/ml-yacc-lib.cm
+  lib/parser1.sml -- moved to <src>/lib/mlyacc
+  lib/parser2.sml -- moved to <src>/lib/mlyacc
+  lib/sources.cm -- deleted
+  lib/stream.sml -- moved to <src>/lib/mlyacc
+  src/FILES
+  src/README
+  src/absyn.sig -- modifed
+  src/absyn.sml -- modifed
+  src/core.sml
+  src/coreutils.sml
+  src/export-yacc.sml -- deleted
+  src/grammar.sml
+  src/graph.sml
+  src/hdr.sml -- modifed
+  src/lalr.sml
+  src/link.sml
+  src/look.sml
+  src/mklrtable.sml
+  src/mkprstruct.sml
+  src/ml-yacc.cm -- deleted
+  src/parse.sml -- modifed
+  src/shrink.sml
+  src/sigs.sml -- modifed
+  src/utils.sig
+  src/utils.sml
+  src/verbose.sml
+  src/yacc.grm -- modifed
+  src/yacc.grm.sig -- deleted (generated by Makefile)
+  src/yacc.grm.sml -- deleted (generated by Makefile)
+  src/yacc.lex -- modifed
+  src/yacc.lex.sml -- deleted (generated by Makefile)
+  src/yacc.sml -- modifed
+  tool/* -- deleted
 
-*****
-
-This is a modified version of the ml-yacc directory that comes with SML/NJ
-110.9.1.  I made a few changes so that the sources are compilable with MLton.
-
-sweeks at acm.org  2000-8-23
+Files added:
+  Makefile
+  README.MLton
+  call-main.sml
+  doc/Makefile
+  doc/macros.hva
+  lib/mlyacc-lib.mlb -- moved to <src>/lib/mlyacc
+  main.sml
+  mlyacc.mlb

Modified: mlton/trunk/mlyacc/doc/mlyacc.tex
===================================================================
--- mlton/trunk/mlyacc/doc/mlyacc.tex	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/doc/mlyacc.tex	2009-04-08 12:32:52 UTC (rev 7065)
@@ -4,12 +4,12 @@
       }
 \author{                David R. Tarditi$^1$\\
                         Andrew W. Appel$^2$\\
-\\              
+\\
 $^1$Microsoft Research \\
 \\
 $^2$Department of Computer Science \\
     Princeton University \\
-    Princeton, NJ 08544 
+    Princeton, NJ 08544
 }
 \date{April 24, 2000}
 
@@ -38,8 +38,8 @@
 \subsection{General}
 ML-Yacc is a parser generator for Standard ML modeled after the
 Yacc parser generator.  It generates parsers for LALR languages, like Yacc,
-and has a similar syntax.  The generated parsers use a different algorithm 
-for recovering from syntax errors than parsers generated by Yacc.  
+and has a similar syntax.  The generated parsers use a different algorithm
+for recovering from syntax errors than parsers generated by Yacc.
 The algorithm is a partial implementation of an algorithm described in \cite{bf}.
 A parser tries to recover from a syntax error
 by making a single token insertion, deletion, or
@@ -59,7 +59,7 @@
 grammars and LR parsing.  We briefly review some terminology here.  A
 context-free grammar is defined by a set of terminals $T$, a set of
 nonterminals $NT$, a set of productions $P$, and a start
-nonterminal $S$.  
+nonterminal $S$.
 Terminals are interchangeably referred to as tokens.  The terminal
 and nonterminal sets are assumed to be disjoint.  The set of symbols is the
 union of the nonterminal and terminal sets.  We use lower case
@@ -70,9 +70,9 @@
 write as $A \rightarrow \alpha$.  We define a relation between strings of
 symbols $\alpha$ and $\beta$, written $\alpha \vdash \beta$ and read
 as $\alpha$ derives $\beta$, if and only if $\alpha = \delta A \gamma$,
-$\beta = \delta \phi \gamma$ and 
+$\beta = \delta \phi \gamma$ and
 there exists some production $A \rightarrow \phi$.  We write the
-transitive closure of this relation as 
+transitive closure of this relation as
 $\vdash_*$. We say that a string of terminals $\alpha$ is a valid sentence
 of the language, {\em i.e.} it is derivable, if the start symbol
 $S \vdash_* \alpha$.   The sequence of derivations is often
@@ -81,7 +81,7 @@
 ML-Yacc uses an attribute grammar scheme with synthesized attributes.
 Each symbol in the grammar may have a value (i.e. attribute) associated
 with it.  Each production has a semantic action associated with it.
-A production with a semantic action is called a rule. 
+A production with a semantic action is called a rule.
 Parsers perform bottom-up, left-to-right evaluations of parse trees using semantic
 actions to compute values as they do so.  Given a production
 $P = A \rightarrow \alpha$, the corresponding semantic action is
@@ -214,8 +214,8 @@
 the rule has the higher precedence, the reduction is chosen.  If both
 the terminal and the rule have the same precedence, then the associativity
 of the terminal is used to resolve the conflict.  If the terminal is
-left associative, the reduction is chosen.  If the terminal is 
-right associative, the shift is chosen.   Terminals may be declared to 
+left associative, the reduction is chosen.  If the terminal is
+right associative, the shift is chosen.   Terminals may be declared to
 be nonassociative, also, in which case an error message is produced
 if the associativity is need to resolve the parsing conflict.
 
@@ -230,7 +230,7 @@
 Text surrounded by brackets denotes meta-notation.  If you see
 something like \{parser name\}, you should substitute the actual
 name of your parser for the meta-notation.  Text in a bold-face
-typewriter font ({\tt like this}) denotes text in a specification 
+typewriter font ({\tt like this}) denotes text in a specification
 or ML code.
 
 \section{ML-Yacc specifications}
@@ -262,7 +262,7 @@
 You may optionally declare precedences for terminals,
 make declarations that will
 improve error-recovery, and suppress the generation of
-default reductions in the parser.  You may 
+default reductions in the parser.  You may
 declare whether the parser generator should create
 a verbose description of the parser in a ``.desc'' file.  This is useful
 for finding the causes of shift/reduce errors and other parsing conflicts.
@@ -307,7 +307,7 @@
 \verb'of for = { } , * -> : | ( )'
 
 \end{quote}
-        
+
 The following classes of ML symbols are used:
 \begin{quote}
 \begin{description}
@@ -389,14 +389,14 @@
               &  | &  \mbox{clause-list {\tt |} symbol-list rule-prec code} \\
 \mbox{rule} & ::= & \mbox{symbol {\tt :} clause-list} \\
 \mbox{rule-list} & ::= & \mbox{rule-list rule} \\
-            &  |  & \mbox{rule} 
+            &  |  & \mbox{rule}
 \end{eqnarray*}
 \subsection{Required ML-Yacc Declarations}
 \begin{description}
 \item[{\tt \%name}]
 You must specify the name of the parser with {\tt \%name} \{name\}.
 \item[{\tt \%nonterm} and {\tt \%term}]
-You must define the terminal and nonterminal sets using the 
+You must define the terminal and nonterminal sets using the
 {\tt \%term} and {\tt \%nonterm}
 declarations, respectively.  These declarations are like an ML datatype
 definition.
@@ -404,7 +404,7 @@
 that the symbol is defined.  Each declarations consists of the keyword
 ({\tt \%term} or {\tt \%nonterm})
 followed by a list of symbol entries separated by a bar (``{\tt |}'').
-Each symbol entry is a symbol name followed by an optional 
+Each symbol entry is a symbol name followed by an optional
 ``of \/ $<$ML-type$>$''. The types cannot be polymorphic.
 Those symbol entries without a type carry no value.
 Nonterminal and terminal names must be disjoint and no name may be declared
@@ -412,13 +412,13 @@
 
 The symbol names and types are used to construct a datatype union for the
 values on the semantic stack in the LR parser and to name the values
-associated with subcomponents of a rule.  The names and types of 
+associated with subcomponents of a rule.  The names and types of
 terminals are also used to construct a signature for a structure that
 may be passed to the lexer functor.
 
 Because the types and names are used in these manners, do
 not use ML keywords as symbol names.   The programs produced by ML-Yacc
-will not compile if ML keywords are used as symbol names.  
+will not compile if ML keywords are used as symbol names.
 Make sure that the types specified in the {\tt \%term} declaration are
 fully qualified types or are available in the background
 environment when the signatures produced by ML-Yacc are loaded.  Do
@@ -471,9 +471,9 @@
 actions until a parse is successful).
 
 ML-Yacc has no concept of an end-of-file.  You must
-define an end-of-file terminal (EOF, perhaps) in the 
+define an end-of-file terminal (EOF, perhaps) in the
 {\tt \%term} declaration.
-You must declare terminals which cannot be shifted, such as 
+You must declare terminals which cannot be shifted, such as
 end-of-file, in the {\tt \%noshift} declaration.  The
 {\tt \%noshift} keyword should be followed by the list of non-shiftable
 terminals. An error message will be printed if a non-shiftable terminal
@@ -496,7 +496,7 @@
 \begin{verbatim}
 %header (functor {parser name}LrValsFun(
                                 structure Token : TOKEN
-                                       ...) 
+                                       ...)
         )
 \end{verbatim}
 \end{quote}
@@ -587,7 +587,7 @@
         The error-correction algorithm may also insert terminals with values.
      You must supply a value for such a terminal. The keyword
      should be followed by a terminal and a piece of
-     code (enclosed in parentheses) that when evaluated supplies the value. 
+     code (enclosed in parentheses) that when evaluated supplies the value.
      There must be a separate {\tt \%value} declaration for each terminal with
      a value that you wish may be inserted or substituted in an error correction.
      The code for the value is not evaluated until the parse is
@@ -602,23 +602,23 @@
 
 All rules are declared in the final section, after the last {\tt \%\%}
 delimiter.  A rule consists of a left hand side nonterminal, followed by
-a colon, followed by a list of right hand side clauses. 
+a colon, followed by a list of right hand side clauses.
 
 The right hand side clauses should be separated by bars (``{\tt |}'').  Each
 clause consists of a list of nonterminal and terminal symbols, followed
 by an optional {\tt \%prec} declaration, and then followed by the code to be
 evaluated when the rule is reduced.
 
-The optional {\tt \%prec} consists of the keyword {\tt \%prec} followed by a 
+The optional {\tt \%prec} consists of the keyword {\tt \%prec} followed by a
 terminal whose precedence should be used as the precedence of the
 rule.
 
-The values of those symbols on the right hand side which have values are 
+The values of those symbols on the right hand side which have values are
 available inside the code.  Positions for all the symbols are also
 available.
-Each value has the general form \{symbol name\}\{n+1\}, where \{n\} is the 
+Each value has the general form \{symbol name\}\{n+1\}, where \{n\} is the
 number of occurrences of the symbol to the left of the symbol.  If
-the symbol occurs only once in the rule, \{symbol name\} may also 
+the symbol occurs only once in the rule, \{symbol name\} may also
 be used.
 The positions are given by \{symbol~name\}\{n+1\}left and
 \{symbol~name\}\{n+1\}right.  where \{n\} is defined as before.
@@ -689,7 +689,7 @@
 {\tt \%header} allows the user to define the header for a structure body.
 
 If the name of the parser in the specification were Calc, you
-would add this declaration to the specification for the lexical 
+would add this declaration to the specification for the lexical
 analyzer:
 \begin{quote}
 \tt
@@ -726,7 +726,7 @@
 You may use a lexer constructed using ML-Lex with the {\tt \%arg}
 declaration, but you must follow special instructions for tying the parser
 and lexer together.
- 
+
 \section{Creating the parser}
 \label{create-parser}
 Let the name of the grammar specification file be denoted by
@@ -745,7 +745,7 @@
 ml-yacc-lib.cm
 {lexer}
 {grammar}
-\end{verbatim}  
+\end{verbatim}
 \end{quote}
 This will cause ML-Yacc to be run on \{grammar\}, producing source files
 \{grammar\}.sig and \{grammar\}.sml, and ML-Lex to be run on
@@ -757,7 +757,7 @@
 \begin{verbatim}
 structure {n}LrVals =
   {n}LrValsFun(structure Token = LrParser.Token)
-structure {n}Lex = 
+structure {n}Lex =
   {n}LexFun(structure Tokens = {n}LrVals.Tokens)
 structure {n}Parser=
   Join(structure ParserData = {n}LrVals.ParserData
@@ -793,7 +793,7 @@
 
 (* printed out in .sig file created by parser generator: *)
 
-signature {n}_TOKENS = 
+signature {n}_TOKENS =
 sig
   structure Token : TOKEN
   type svalue
@@ -844,17 +844,17 @@
     structure Token = ParserData.Token
     type svalue = ...
     fun PLUS(p1,p2) = ...
-    fun INTLIT(i,p1,p2) = ... 
+    fun INTLIT(i,p1,p2) = ...
   end
 
 end
 
 (* to be done by the user: *)
- 
+
 structure {n}LrVals =
   {n}LrValsFun(structure Token = LrParser.Token)
 
-structure {n}Lex = 
+structure {n}Lex =
   {n}LexFun(structure Tokens = {n}LrVals.Tokens)
 
 structure {n}Parser =
@@ -1039,7 +1039,7 @@
       | EXP SUB EXP     (EXP1-EXP2)
       | EXP CARAT EXP   (let fun e (m,0) = 1
                                 | e (m,l) = m*e(m,l-1)
-                         in e (EXP1,EXP2)       
+                         in e (EXP1,EXP2)
                          end)
 \end{verbatim}
 \end{tt}
@@ -1104,7 +1104,7 @@
        structure Lex = CalcLex)
 \end{verbatim}
 \end{quote}
- 
+
 Now we need a function which given a lexer invokes the parser.  The
 function {\tt invoke} does this.
 
@@ -1121,12 +1121,12 @@
 
 Finally, we need a function which can read one or more expressions from
 the standard input.  The function {\tt parse}, shown below, does this.
-It runs the calculator on the standard input and terminates 
+It runs the calculator on the standard input and terminates
 when an end-of-file is encountered.
 
 \begin{quote}
 \begin{verbatim}
-fun parse () = 
+fun parse () =
     let val lexer = CalcParser.makeLexer
                       (fn _ => TextIO.inputLine TextIO.stdIn)
         val dummyEOF = CalcLrVals.Tokens.EOF(0,0)
@@ -1182,7 +1182,7 @@
                   | ACCEPT
                   | ERROR
   type table
-        
+
   val numStates : table -> int
   val numRules : table -> int
   val describeActions : table -> state ->
@@ -1229,7 +1229,7 @@
         arg: 'arg,
         saction : int *
                  'c *
-                 (LrTable.state * ('b * 'c * 'c)) list * 
+                 (LrTable.state * ('b * 'c * 'c)) list *
                  'arg ->
                   LrTable.nonterm *
                   ('b * 'c * 'c) *
@@ -1265,7 +1265,7 @@
       type pos
       type svalue
     end
-  val makeLexer : (int -> string) -> unit -> 
+  val makeLexer : (int -> string) -> unit ->
        (UserDeclarations.svalue, UserDeclarations.pos)
        UserDeclarations.token
 end
@@ -1287,7 +1287,7 @@
   val makeLexer :
       (int -> string) ->
       UserDeclarations.arg ->
-      unit -> 
+      unit ->
        (UserDeclarations.svalue, UserDeclarations.pos)
        UserDeclarations.token
 end
@@ -1316,7 +1316,7 @@
   structure Token : TOKEN
   sharing Token.LrTable = LrTable
 
-  structure Actions : 
+  structure Actions :
     sig
       val actions : int * pos *
        (LrTable.state * (svalue * pos * pos)) list * arg ->
@@ -1352,7 +1352,7 @@
 \begin{verbatim}
 (* printed out in .sig file created by parser generator: *)
 
-signature {n}_TOKENS = 
+signature {n}_TOKENS =
 sig
   type ('a,'b) token
   type svalue
@@ -1401,7 +1401,7 @@
 signature:
 \begin{quote}
 \begin{verbatim}
-signature ARG_PARSER = 
+signature ARG_PARSER =
 sig
   structure Token : TOKEN
   structure Stream : STREAM
@@ -1476,7 +1476,7 @@
            Lex.UserDeclarations.token
 
 sharing {n}LrVals.LrTable = LrParser.LrTable
-        
+
 \end{verbatim}
 \end{quote}
 
@@ -1572,7 +1572,7 @@
 functor.
 \begin{quote}
 \begin{verbatim}
-signature INTERFACE = 
+signature INTERFACE =
 sig
    type pos
    val line : pos ref

Modified: mlton/trunk/mlyacc/doc/tech.doc
===================================================================
--- mlton/trunk/mlyacc/doc/tech.doc	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/doc/tech.doc	2009-04-08 12:32:52 UTC (rev 7065)
@@ -7,7 +7,7 @@
 
 Look at the file sigs.sml to see how the modules are layed out.
 The file graph.sml contains the Graph functor, which produces a structure
-containing a function mkGraph.  mkGraph takes a grammar and returns a 
+containing a function mkGraph.  mkGraph takes a grammar and returns a
 some useful values and functions, including the LR(0) graph.  It renumbers
 the rules to an internal form to make the LR(0) graph generation more
 efficient.  The LR(0) graph includes only core items in its set of items.
@@ -23,7 +23,7 @@
 added and all other items without dots at the end (i.e. non-reduction items)
 are removed.
 
-The functor MkTable produces a function with takes the LR(0) graph 
+The functor MkTable produces a function with takes the LR(0) graph
 produced by the function in mkGraph and the LR(0) graph with lookaheads
 produced by Lalr and creates an LALR(1) table from these graphs.
 
@@ -56,7 +56,7 @@
 or goto to the graph.  We continue doing this until there are no more cores
 to adds to the graph.
 
-We have to take the closure of a core to include those items which are 
+We have to take the closure of a core to include those items which are
 derived from nonterminals with a dot before them.  If item A -> 'a .B 'c
 is in a core, the all productions derived by B must also be in the core.
 
@@ -112,17 +112,17 @@
 
             In (a), lookahead(items derived from B) includes first('c)
             and lookahead(A -> 'a .B 'c)
-        
+
             In (b), lookahead(items derived from B) includes only first('c).
 
-            This is an example of back propagation. 
-        
+            This is an example of back propagation.
+
         Note that an item is either the result of a closure or the
         result of a shift/goto.  It is never the result of both (that
         would be a contradiction).
 
         The following representation will be used:
-        
+
           goto/shift items:
                 an ordered list of item * lookahead ref *
                                           lookahead ref for the resulting
@@ -143,7 +143,7 @@
 was the result of a shift or goto from some item j, then lookahead(i) includes
 lookahead(j).  If item i is a production of some nonterminal B, and there
 exists some item j of the form A -> x .B y, then item i will be added through
-closure(j).  This implies that lookahead(i) includes first(y).  If y => 
+closure(j).  This implies that lookahead(i) includes first(y).  If y =>
 epsilon, then lookahead(i) includes lookahead(j).
 
 Lookahead must be recorded for completion items, which are items of the
@@ -196,7 +196,7 @@
         (1) nonterminals  such that c =c+=> .C y and y =*=> epsilon
 
         Let s = the set of nonterminals added through closure = B
-        
+
         repeat
                 for all B which are elements of s,
                         if B -> .C z and z =*=> epsilon then
@@ -220,9 +220,9 @@
         for each nonterminal in this set.
 
 These algorithms can be restated as either breadth-first or depth-first search
-algorithms.   The loop invariant of the algorithms is that whenever a 
+algorithms.   The loop invariant of the algorithms is that whenever a
 nonterminal is added to the set being calculated, all the productions
-for the nonterminal are checked.  
+for the nonterminal are checked.
 
 This algorithm computes the lookahead for each item:
 
@@ -240,7 +240,7 @@
                           all items of A -> x. or A -> x .B y, where
                           y =*=> epsilon, and x is not epsilon
 
-                      add the lookahead we have computed for X to the 
+                      add the lookahead we have computed for X to the
                       elements of l
 
                       if B =c+=> X z, where z is nullable, add first(y) to

Modified: mlton/trunk/mlyacc/examples/calc/README
===================================================================
--- mlton/trunk/mlyacc/examples/calc/README	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/examples/calc/README	2009-04-08 12:32:52 UTC (rev 7065)
@@ -22,7 +22,7 @@
 and the calc.sml file containing the driver code.
 
 The end result of loading these files is a structure Calc containing a
-top-level driver function named parse.  
+top-level driver function named parse.
 
   Calc.parse : unit -> unit
 

Modified: mlton/trunk/mlyacc/examples/calc/calc.lex
===================================================================
--- mlton/trunk/mlyacc/examples/calc/calc.lex	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/examples/calc/calc.lex	2009-04-08 12:32:52 UTC (rev 7065)
@@ -33,5 +33,3 @@
 "/"      => (Tokens.DIV(!pos,!pos));
 "."      => (error ("ignoring bad character "^yytext,!pos,!pos);
              lex());
-
-

Modified: mlton/trunk/mlyacc/examples/calc/calc.sml
===================================================================
--- mlton/trunk/mlyacc/examples/calc/calc.sml	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/examples/calc/calc.sml	2009-04-08 12:32:52 UTC (rev 7065)
@@ -6,10 +6,10 @@
 
 structure Calc : sig
                    val parse : unit -> unit
-                 end = 
+                 end =
 struct
 
-(* 
+(*
  * We apply the functors generated from calc.lex and calc.grm to produce
  * the CalcParser structure.
  *)
@@ -25,7 +25,7 @@
          structure ParserData = CalcLrVals.ParserData
          structure Lex = CalcLex)
 
-(* 
+(*
  * We need a function which given a lexer invokes the parser. The
  * function invoke does this.
  *)
@@ -37,14 +37,14 @@
        in CalcParser.parse(0,lexstream,print_error,())
       end
 
-(* 
+(*
  * Finally, we need a driver function that reads one or more expressions
  * from the standard input. The function parse, shown below, does
  * this. It runs the calculator on the standard input and terminates when
  * an end-of-file is encountered.
  *)
 
-  fun parse () = 
+  fun parse () =
       let val lexer = CalcParser.makeLexer (fn _ => TextIO.inputLine TextIO.stdIn)
           val dummyEOF = CalcLrVals.Tokens.EOF(0,0)
           val dummySEMI = CalcLrVals.Tokens.SEMI(0,0)

Modified: mlton/trunk/mlyacc/examples/fol/README
===================================================================
--- mlton/trunk/mlyacc/examples/fol/README	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/examples/fol/README	2009-04-08 12:32:52 UTC (rev 7065)
@@ -30,7 +30,7 @@
 The end result of loading these files is a structure Parse containing
 the following top-level driver functions:
 
-  val prog_parse : string -> Absyn.absyn 
+  val prog_parse : string -> Absyn.absyn
    (* parse a program from a string *)
 
   val query_parse : string -> Absyn.absyn

Modified: mlton/trunk/mlyacc/examples/fol/fol.grm
===================================================================
--- mlton/trunk/mlyacc/examples/fol/fol.grm	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/examples/fol/fol.grm	2009-04-08 12:32:52 UTC (rev 7065)
@@ -14,7 +14,7 @@
 (* gform: goal formula
    dform: definite clause *)
 
-%nonterm 
+%nonterm
     start of Absyn.absyn
   | clause | query | gform | dform
   | atom | termlist | term  | varbd | id
@@ -55,7 +55,7 @@
       | FORALL varbd gform      ()      (* universal quantification *)
       | EXISTS varbd gform      ()      (* existential quantification *)
       | atom                    ()      (* atomic formula *)
-      | LPAREN gform RPAREN     ()      
+      | LPAREN gform RPAREN     ()
 
 dform : TRUE                    ()
       | dform COMMA dform       ()      (* and *)
@@ -79,4 +79,3 @@
 
 id : LCID               ()
    | UCID               ()
-

Modified: mlton/trunk/mlyacc/examples/fol/parse.sml
===================================================================
--- mlton/trunk/mlyacc/examples/fol/parse.sml	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/examples/fol/parse.sml	2009-04-08 12:32:52 UTC (rev 7065)
@@ -1,4 +1,4 @@
-(* Uses the generated lexer and parser to export parsing functions 
+(* Uses the generated lexer and parser to export parsing functions
  *)
 
 signature PARSE =
@@ -8,7 +8,7 @@
 
 (* parse a program from a string *)
 
-  val prog_parse : string -> Absyn.absyn 
+  val prog_parse : string -> Absyn.absyn
 
 (* parse a query from a string *)
 
@@ -17,7 +17,7 @@
 (* parse a program in a file *)
 
   val file_parse : string -> Absyn.absyn
- 
+
 (* parse a query from the standard input *)
 
   val top_parse : unit -> Absyn.absyn
@@ -44,7 +44,7 @@
         val empty = !Interface.line
         val dummyEOF = Tokens.EOF(empty,empty)
         val dummyTOKEN = dummyToken(empty,empty)
-        fun invoke lexer = 
+        fun invoke lexer =
            let val newLexer = Parser.Stream.cons(dummyTOKEN,lexer)
            in Parser.parse(lookahead,newLexer,Interface.error,
                                 Interface.nothing)
@@ -62,7 +62,7 @@
     let val next = ref s
      in fn _ => !next before next := ""
     end
-    
+
 fun prog_parse s = parse (Tokens.PARSEPROG,15,string_reader s)
 
 fun query_parse s = parse (Tokens.PARSEQUERY,15,string_reader s)
@@ -73,7 +73,7 @@
         before TextIO.closeIn dev
     end
 
-fun top_parse () = 
+fun top_parse () =
     parse (Tokens.PARSEQUERY,0,(fn i => TextIO.inputLine TextIO.stdIn))
 
 end  (* functor Parse *)

Modified: mlton/trunk/mlyacc/examples/pascal/README
===================================================================
--- mlton/trunk/mlyacc/examples/pascal/README	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/examples/pascal/README	2009-04-08 12:32:52 UTC (rev 7065)
@@ -6,27 +6,26 @@
   CM.make "sources.cm";
 
 This will apply ML-Yacc to the file "pascal.grm" to create
-the files "pascal.grm.sig" and "pascal.grm.sml", then 
+the files "pascal.grm.sig" and "pascal.grm.sml", then
 ML_Lex will be applied to pascal.lex to produce pascal.lex.sml.
 
 Then these generated files will be compiled together with necessary
 components from the ML-Yacc library supplied by the ml-yacc-lib.cm
-file. 
+file.
 
 The end result is a structure Parser with two functions.  The
-function 
+function
 
   parse: string ->
          PascalParser.result *
-         (Parser.PascalParser.svalue,PascalParser.pos) LrParser.Token.token 
+         (Parser.PascalParser.svalue,PascalParser.pos) LrParser.Token.token
             LrParser.stream
 
 parses input from a file, while
 
   keybd: unit ->
          Parser.PascalParser.result *
-         (Parser.PascalParser.svalue,Parser.PascalParser.pos) 
+         (Parser.PascalParser.svalue,Parser.PascalParser.pos)
            LrParser.Token.token LrParser.stream
 
 parses from the standard input.
-

Modified: mlton/trunk/mlyacc/examples/pascal/parser.sml
===================================================================
--- mlton/trunk/mlyacc/examples/pascal/parser.sml	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/examples/pascal/parser.sml	2009-04-08 12:32:52 UTC (rev 7065)
@@ -24,7 +24,7 @@
     end
 
 fun keybd () =
-    let val stream = 
+    let val stream =
             PascalParser.makeLexer (fn i => TextIO.inputLine TextIO.stdIn)
         fun error (e,i:int,_) =
             TextIO.output(TextIO.stdOut,

Modified: mlton/trunk/mlyacc/examples/pascal/pascal.grm
===================================================================
--- mlton/trunk/mlyacc/examples/pascal/pascal.grm	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/examples/pascal/pascal.grm	2009-04-08 12:32:52 UTC (rev 7065)
@@ -14,11 +14,11 @@
         YTYPE   |       YUNTIL  |       YVAR    |       YWHILE |
         YWITH   |       YBINT   |       YOCT    |       YHEX |
         YCASELAB |      YILLCH  |       YEXTERN  |
- YDOT | YLPAR  | YRPAR | YSEMI  | YCOMMA  | YCOLON |  YCARET |  YLBRA | 
+ YDOT | YLPAR  | YRPAR | YSEMI  | YCOMMA  | YCOLON |  YCARET |  YLBRA |
  YRBRA | YTILDE |
- YLESS | YEQUAL | YGREATER 
+ YLESS | YEQUAL | YGREATER
 | YPLUS | YMINUS | YBAR
-| UNARYSIGN 
+| UNARYSIGN
 | YSTAR | YSLASH | YAMP
 |  EOF
 
@@ -33,30 +33,30 @@
 %left   YSTAR   YSLASH  YDIV    YMOD    YAND    YAMP
 %left   YNOT
 
-%nonterm goal | prog_hedr | block | decls | decl | labels | label_decl | 
-const_decl | type_decl | var_decl | proc_decl | pheadres | phead | 
-porf | params | param | ftype | param_list | const | number | const_list | 
-type' | simple_type | struct_type | simple_type_list | field_list | 
-fixed_part | field | variant_part | variant_list | variant | stat_list | 
-stat_lsth | cstat_list | cstat | stat | assign | expr | element_list | 
-element | variable | qual_var | wexpr | octhex | expr_list | wexpr_list | 
-relop | addop | divop | negop | var_list | id_list | const_id | type_id | 
+%nonterm goal | prog_hedr | block | decls | decl | labels | label_decl |
+const_decl | type_decl | var_decl | proc_decl | pheadres | phead |
+porf | params | param | ftype | param_list | const | number | const_list |
+type' | simple_type | struct_type | simple_type_list | field_list |
+fixed_part | field | variant_part | variant_list | variant | stat_list |
+stat_lsth | cstat_list | cstat | stat | assign | expr | element_list |
+element | variable | qual_var | wexpr | octhex | expr_list | wexpr_list |
+relop | addop | divop | negop | var_list | id_list | const_id | type_id |
 var_id | array_id | ptr_id | record_id | field_id | func_id
 | begin
 
 %keyword
-        YAND            YARRAY          YBEGIN          YCASE 
-        YCONST          YDIV            YDO             
-        YTO             YELSE           YEND            YFILE 
-        YFOR            YFORWARD        YPROCEDURE      YGOTO 
-        YIF             YIN             
-        YLABEL          YMOD            YNOT            
-        YOF             YOR             YPACKED         YNIL 
+        YAND            YARRAY          YBEGIN          YCASE
+        YCONST          YDIV            YDO
+        YTO             YELSE           YEND            YFILE
+        YFOR            YFORWARD        YPROCEDURE      YGOTO
+        YIF             YIN
+        YLABEL          YMOD            YNOT
+        YOF             YOR             YPACKED         YNIL
         YFUNCTION       YPROG           YRECORD         YREPEAT
-        YSET            YSTRING         YTHEN           YDOWNTO 
-        YTYPE           YUNTIL          YVAR            YWHILE 
-        YWITH           YOCT            YHEX 
-        YEXTERN         YAMP 
+        YSET            YSTRING         YTHEN           YDOWNTO
+        YTYPE           YUNTIL          YVAR            YWHILE
+        YWITH           YOCT            YHEX
+        YEXTERN         YAMP
 
 %prefer YID YSEMI YCOMMA  YLBRA
 

Modified: mlton/trunk/mlyacc/examples/pascal/pascal.lex
===================================================================
--- mlton/trunk/mlyacc/examples/pascal/pascal.lex	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/examples/pascal/pascal.lex	2009-04-08 12:32:52 UTC (rev 7065)
@@ -38,8 +38,8 @@
                 | f nil = NONE
           in  f (Array.sub(HashTable, i))
           end
- 
-        val _ = 
+
+        val _ =
             (List.app add
         [("and",YAND),
          ("array",YARRAY),

Modified: mlton/trunk/mlyacc/examples/pascal/test/c1.p
===================================================================
--- mlton/trunk/mlyacc/examples/pascal/test/c1.p	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/examples/pascal/test/c1.p	2009-04-08 12:32:52 UTC (rev 7065)
@@ -1,4 +1,4 @@
-program simplex(input, output); 
+program simplex(input, output);
 
 { two-phase simplex algorithm: version Feb. 24, 1988 }
 
@@ -24,12 +24,12 @@
     pivotel: real;                      { pivot element }
     cbar: real;         { price when searching for entering column }
     carry: array[-1..mmax, -1..mmax] of real;   { inverse-basis matrix of the
-						  revised simplex method }
+                                                  revised simplex method }
     phase: 1..2;        { phase }
     price: array[0..mmax] of real;      { shadow prices = row -1 of carry =
-					  -dual variables }
+                                          -dual variables }
     basis: array[0..mmax] of integer;  { basis columns, negative integers
-					  artificial }
+                                          artificial }
     ncol: 1..ncolmax;                   { number of columns }
     tab: array[0..mmax, 1..ncolmax] of real;    { tableau }
     lhs: array[0..mmax] of real;        { left-hand-side }
@@ -54,13 +54,13 @@
     pivotcol:= 0;
     for col:= 1 to ncol do
       begin
-	tempcost:= d[col];
-	for i:= 0 to m do tempcost:= tempcost - price[i]*tab[i, col];
-	if( cbar > tempcost ) then
-	  begin
-	   cbar:= tempcost;
-	   pivotcol:= col
-	  end
+        tempcost:= d[col];
+        for i:= 0 to m do tempcost:= tempcost - price[i]*tab[i, col];
+        if( cbar > tempcost ) then
+          begin
+           cbar:= tempcost;
+           pivotcol:= col
+          end
       end;  { for col }
     if ( cbar > -eps ) then optimal:= true
   end;   { columnsearch }
@@ -77,9 +77,9 @@
   begin  { rowsearch }
     for i:= 0 to m do           { generate column }
       begin
-	curcol[i]:= 0.0;        { current column = B inverse * original col. }
-	for  j:= 0 to m do curcol[i]:=
-			   curcol[i] + carry[i, j]*tab[j, pivotcol]
+        curcol[i]:= 0.0;        { current column = B inverse * original col. }
+        for  j:= 0 to m do curcol[i]:=
+                           curcol[i] + carry[i, j]*tab[j, pivotcol]
       end;
   curcol[-1]:= cbar;            { first element in current column }
   pivotrow:= -1;
@@ -87,24 +87,24 @@
   for i:= 0 to m do                             { ratio test }
     begin
       if( curcol[i] > eps ) then
-	begin
-	  ratio:= carry[i, -1]/curcol[i];
-	    if( minratio > ratio ) then         { favorable row }
-	      begin
-		minratio:= ratio;
-		pivotrow:= i;
-		pivotel:= curcol[i]
-	      end
-	    else { break tie with max pivot }
-	      if ( (minratio = ratio) and (pivotel < curcol[i]) ) then
-		  begin
-		    pivotrow:= i;
-		    pivotel:= curcol[i]
-		  end
-	end  { curcol > eps }
+        begin
+          ratio:= carry[i, -1]/curcol[i];
+            if( minratio > ratio ) then         { favorable row }
+              begin
+                minratio:= ratio;
+                pivotrow:= i;
+                pivotel:= curcol[i]
+              end
+            else { break tie with max pivot }
+              if ( (minratio = ratio) and (pivotel < curcol[i]) ) then
+                  begin
+                    pivotrow:= i;
+                    pivotel:= curcol[i]
+                  end
+        end  { curcol > eps }
       end;  { for i }
     if ( pivotrow = -1 ) then  unbounded:= true         { nothing found }
-			 else  unbounded:= false
+                         else  unbounded:= false
   end;  { rowsearch }
 
 
@@ -119,8 +119,8 @@
     for j:= -1 to m do carry[pivotrow, j]:= carry[pivotrow, j]/pivotel;
     for i:= -1 to m do
       if( i<> pivotrow ) then
-	for j:= -1 to m do
-	  carry[i, j]:= carry[i, j] - carry[pivotrow, j]*curcol[i];
+        for j:= -1 to m do
+          carry[i, j]:= carry[i, j] - carry[pivotrow, j]*curcol[i];
     curcost:= -carry[-1, -1]
   end;  { pivot }
 
@@ -135,17 +135,17 @@
     phase:= 2;
     for i:= 0 to m do if( basis[i] <= 0 ) then
       writeln( '...artificial basis element ', basis[i]:5,
-	       ' remains in basis after phase 1');
+               ' remains in basis after phase 1');
     for j:= 1 to ncol do d[j]:= c[j];   { switch to original cost vector }
     for j:= -1 to m do
       begin
-	carry[-1, j]:= 0.0;
-	for i:= 0 to m do
-	  begin
-	    b:= basis[i];       { ignore artificial basis elements that are }
-	    if( b >= 1 ) then   { still in basis }
-	      carry[-1, j]:= carry[-1, j] - c[b]*carry[i,j]
-	  end  { for i }
+        carry[-1, j]:= 0.0;
+        for i:= 0 to m do
+          begin
+            b:= basis[i];       { ignore artificial basis elements that are }
+            if( b >= 1 ) then   { still in basis }
+              carry[-1, j]:= carry[-1, j] - c[b]*carry[i,j]
+          end  { for i }
       end;  { for j }
     curcost:= -carry[-1, -1]
   end;   { changephase }
@@ -185,8 +185,8 @@
   if( ncol <= ncolmax ) then               { check number of columns }
     for col:= 1 to ncol do      { initialize cost vector for phase 1 }
       begin
-	d[col]:= 0.0;
-	for row:= 0 to m do d[col]:= d[col] - tab[row, col]
+        d[col]:= 0.0;
+        for row:= 0 to m do d[col]:= d[col] - tab[row, col]
       end
   else
     begin
@@ -201,56 +201,56 @@
 begin  { simplex }
   setup;
   while( (numpivots < maxpivots) and (not done) and
-	 ( (curcost > lowlim) or (phase = 1) ) ) do
+         ( (curcost > lowlim) or (phase = 1) ) ) do
     begin
       columnsearch;
       if( not optimal ) then
-	begin                         { not optimal }
-	  rowsearch;
-	    if( unbounded ) then
-	      begin
-		done:= true;
-		result:= unbound;
-		writeln('problem is unbounded')
-	      end
-	    else
-	      begin
-		pivot;
-		numpivots:= numpivots + 1;
-		if ( (numpivots = 1 ) or ( numpivots mod 10 = 0 ) ) then
-		      writeln('pivot ', numpivots:4, ' cost= ', curcost:12)
-	      end
-	end  { not optimal }
+        begin                         { not optimal }
+          rowsearch;
+            if( unbounded ) then
+              begin
+                done:= true;
+                result:= unbound;
+                writeln('problem is unbounded')
+              end
+            else
+              begin
+                pivot;
+                numpivots:= numpivots + 1;
+                if ( (numpivots = 1 ) or ( numpivots mod 10 = 0 ) ) then
+                      writeln('pivot ', numpivots:4, ' cost= ', curcost:12)
+              end
+        end  { not optimal }
       else                            { optimal }
-	  if( phase = 1 ) then
-	    begin
-	      if( curcost > eps ) then
-		begin
-		  done:= true;
-		  result:= infeas;
-		  writeln('problem is infeasible')
-		end
-	      else
-		begin
-		  if ( (numpivots <> 1 ) and ( numpivots mod 10 <> 0 ) ) then
-		    writeln('pivot ', numpivots:4, ' cost= ', curcost:12);
-		  writeln('phase 1 successfully completed');
-		  changephase
-		end
-	    end  { if phase = 1 }
-	  else
-	    begin
-	      if ( (numpivots <> 1 ) and ( numpivots mod 10 <> 0 ) ) then
-		writeln('pivot ', numpivots:4, ' cost= ', curcost:12);
-	      writeln('phase 2 successfully completed');
-	      done:= true;
-	      result:= opt
-	    end
+          if( phase = 1 ) then
+            begin
+              if( curcost > eps ) then
+                begin
+                  done:= true;
+                  result:= infeas;
+                  writeln('problem is infeasible')
+                end
+              else
+                begin
+                  if ( (numpivots <> 1 ) and ( numpivots mod 10 <> 0 ) ) then
+                    writeln('pivot ', numpivots:4, ' cost= ', curcost:12);
+                  writeln('phase 1 successfully completed');
+                  changephase
+                end
+            end  { if phase = 1 }
+          else
+            begin
+              if ( (numpivots <> 1 ) and ( numpivots mod 10 <> 0 ) ) then
+                writeln('pivot ', numpivots:4, ' cost= ', curcost:12);
+              writeln('phase 2 successfully completed');
+              done:= true;
+              result:= opt
+            end
     end;  { while }
   if( (curcost <= lowlim) and (phase = 2) ) then
     begin
       if ( (numpivots <> 1 ) and ( numpivots mod 10 <> 0 ) ) then
-	writeln('pivot ', numpivots:4, ' cost= ', curcost:12);
+        writeln('pivot ', numpivots:4, ' cost= ', curcost:12);
       result:= unbound;
       writeln('problem is unbounded')
     end;
@@ -265,8 +265,7 @@
       writeln('optimal solution reached');
       writeln('cost    =', -carry[-1,-1]:10:6);
       for i:= 0 to m do
-	writeln('x(', basis[i]:4, ')= ', carry[i,-1]:10:6)
+        writeln('x(', basis[i]:4, ')= ', carry[i,-1]:10:6)
     end
 
 end.
-

Modified: mlton/trunk/mlyacc/examples/pascal/test/t1.p
===================================================================
--- mlton/trunk/mlyacc/examples/pascal/test/t1.p	2009-04-08 12:32:46 UTC (rev 7064)
+++ mlton/trunk/mlyacc/examples/pascal/test/t1.p	2009-04-08 12:32:52 UTC (rev 7065)
@@ -1,4 +1,4 @@
-junk simplex(input, output); 
+junk simplex(input, output);
 
 { two-phase simplex algorithm: version Feb. 24, 1988 }
 
@@ -24,12 +24,12 @@
     pivotel: real;                      { pivot element }
     cbar: real;         { price when searching for entering column }
     carry: array[-1..mmax, -1..mmax] of real;   { inverse-basis matrix of the
-						  revised simplex method }
+                                                  revised simplex method }
     phase: 1..2;        { phase }
     price: array[0..mmax] of real;      { shadow prices = row -1 of carry =
-					  -dual variables }
+                                          -dual variables }
     basis: array[0..mmax] of integer;  { basis columns, negative integers
-					  artificial }
+                                          artificial }
     ncol: 1..ncolmax;                   { number of columns }
     tab: ar



More information about the MLton-commit mailing list