Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/ml-yacc/src/look.sml
ViewVC logotype

Diff of /sml/trunk/src/ml-yacc/src/look.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 514, Thu Dec 16 08:32:57 1999 UTC revision 515, Sun Jan 9 09:59:14 2000 UTC
# Line 1  Line 1 
1  (* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi  (* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi
2   *   *
3   * $Log$   * $Log$
4     * Revision 1.2  2000/01/09 09:59:14  blume
5     * pickler bug fixes; some cosmetic changes
6     *
7   * Revision 1.1.1.10  1999/04/17 18:56:12  monnier   * Revision 1.1.1.10  1999/04/17 18:56:12  monnier
8   * version 110.16   * version 110.16
9   *   *
# Line 74  Line 77 
77             We have found all the possible nullable rules.             We have found all the possible nullable rules.
78        *)        *)
79    
80          val nullable =          val nullable = let
81            let fun ok_rhs nil = true              fun add_rule (RULE { lhs, rhs, ... }, r) = let
82                  | ok_rhs ((TERM _)::_) = false                  fun addNT (TERM _, _) = NONE
83                  | ok_rhs ((NONTERM i)::r) = ok_rhs r                    | addNT (_, NONE) = NONE
84                fun add_rule (RULE {lhs,rhs,...},r) =                    | addNT (NONTERM (NT i), SOME ntlist) = SOME (i :: ntlist)
85                   if ok_rhs rhs then (lhs,map (fn (NONTERM (NT i)) => i) rhs)::r              in
86                   else r                  case foldr addNT (SOME []) rhs of
87                        NONE => r
88                      | SOME ntlist => (lhs, ntlist) :: r
89                end
90                val items = List.foldr add_rule [] rules                val items = List.foldr add_rule [] rules
91                val nullable = array(nonterms,false)                val nullable = array(nonterms,false)
92                val f = fn ((NT i,nil),(l,_)) => (update(nullable,i,true);              fun f ((NT i,nil),(l,_)) = (update(nullable,i,true);
93                                                 (l,true))                                                 (l,true))
94                         | (a as (lhs,(h::t)),(l,change)) =>                | f (a as (lhs,(h::t)),(l,change)) =
95                                  case (nullable sub h)                  (case (nullable sub h) of
96                                    of false => (a::l,change)                       false => (a::l,change)
97                                     | true => ((lhs,t)::l,true)                     | true => ((lhs,t)::l,true))
98                fun prove(l,true) = prove(List.foldr f (nil,false) l)                fun prove(l,true) = prove(List.foldr f (nil,false) l)
99                  | prove(_,false) = ()                  | prove(_,false) = ()
100          in (prove(items,true); fn (NT i) => nullable sub i)          in (prove(items,true); fn (NT i) => nullable sub i)

Legend:
Removed from v.514  
changed lines
  Added in v.515

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0