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

SCM Repository

[smlnj] Annotation of /sml/trunk/benchmarks/programs/mlyacc/core.sml
ViewVC logotype

Annotation of /sml/trunk/benchmarks/programs/mlyacc/core.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 193 - (view) (download)

1 : monnier 193 (* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi
2 :     *
3 :     * $Log$
4 :     * Revision 1.2 1996/02/26 15:02:31 george
5 :     * print no longer overloaded.
6 :     * use of makestring has been removed and replaced with Int.toString ..
7 :     * use of IO replaced with TextIO
8 :     *
9 :     * Revision 1.1.1.1 1996/01/31 16:01:44 george
10 :     * Version 109
11 :     *
12 :     *)
13 :    
14 :     functor mkCore(structure IntGrammar : INTGRAMMAR) : CORE =
15 :     struct
16 :     open IntGrammar
17 :     open Grammar
18 :     structure IntGrammar = IntGrammar
19 :     structure Grammar = Grammar
20 :    
21 :     datatype item = ITEM of
22 :     { rule : rule,
23 :     dot : int,
24 :     rhsAfter : symbol list
25 :     }
26 :    
27 :     val eqItem = fn (ITEM{rule=RULE{num=n,...},dot=d,...},
28 :     ITEM{rule=RULE{num=m,...},dot=e,...}) =>
29 :     n=m andalso d=e
30 :    
31 :     val gtItem = fn (ITEM{rule=RULE{num=n,...},dot=d,...},
32 :     ITEM{rule=RULE{num=m,...},dot=e,...}) =>
33 :     n>m orelse (n=m andalso d>e)
34 :    
35 :     structure ItemList = ListOrdSet
36 :     (struct
37 :     type elem = item
38 :     val eq = eqItem
39 :     val gt = gtItem
40 :     end)
41 :    
42 :     open ItemList
43 :     datatype core = CORE of item list * int
44 :    
45 :     val gtCore = fn (CORE (a,_),CORE (b,_)) => ItemList.set_gt(a,b)
46 :     val eqCore = fn (CORE (a,_),CORE (b,_)) => ItemList.set_eq(a,b)
47 :    
48 :     (* functions for printing and debugging *)
49 :    
50 :     val prItem = fn (symbolToString,nontermToString,print) =>
51 :     let val printInt = print o (Int.toString : int -> string)
52 :     val prSymbol = print o symbolToString
53 :     val prNonterm = print o nontermToString
54 :     fun showRest nil = ()
55 :     | showRest (h::t) = (prSymbol h; print " "; showRest t)
56 :     fun showRhs (l,0) = (print ". "; showRest l)
57 :     | showRhs (nil,_) = ()
58 :     | showRhs (h::t,n) = (prSymbol h;
59 :     print " ";
60 :     showRhs(t,n-1))
61 :     in fn (ITEM {rule=RULE {lhs,rhs,rulenum,num,...},
62 :     dot,rhsAfter,...}) =>
63 :     (prNonterm lhs; print " : "; showRhs(rhs,dot);
64 :     case rhsAfter
65 :     of nil => (print " (reduce by rule ";
66 :     printInt rulenum;
67 :     print ")")
68 :     | _ => ();
69 :     if DEBUG then
70 :     (print " (num "; printInt num; print ")")
71 :     else ())
72 :     end
73 :    
74 :     val prCore = fn a as (_,_,print) =>
75 :     let val prItem = prItem a
76 :     in fn (CORE (items,state)) =>
77 :     (print "state ";
78 :     print (Int.toString state);
79 :     print ":\n\n";
80 :     app (fn i => (print "\t";
81 :     prItem i; print "\n")) items;
82 :     print "\n")
83 :     end
84 :     end;

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