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/src/ml-yacc/lib/lrtable.sml
ViewVC logotype

Annotation of /sml/trunk/src/ml-yacc/lib/lrtable.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 93 - (view) (download)
Original Path: sml/branches/SMLNJ/src/ml-yacc/lib/lrtable.sml

1 : monnier 2 (* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi
2 :     *
3 :     * $Log$
4 : monnier 93 * Revision 1.1.1.3 1998/05/12 21:56:20 monnier
5 : monnier 8 * *** empty log message ***
6 : monnier 2 *
7 : monnier 93 * Revision 1.1.1.1 1998/04/08 18:40:16 george
8 :     * Version 110.5
9 :     *
10 : monnier 8 * Revision 1.1.1.1 1997/01/14 01:38:04 george
11 :     * Version 109.24
12 :     *
13 : monnier 2 * Revision 1.1.1.1 1996/01/31 16:01:42 george
14 :     * Version 109
15 :     *
16 :     *)
17 :    
18 :     structure LrTable : LR_TABLE =
19 :     struct
20 :     open Array List
21 :     infix 9 sub
22 :     datatype ('a,'b) pairlist = EMPTY
23 :     | PAIR of 'a * 'b * ('a,'b) pairlist
24 :     datatype term = T of int
25 :     datatype nonterm = NT of int
26 :     datatype state = STATE of int
27 :     datatype action = SHIFT of state
28 :     | REDUCE of int (* rulenum from grammar *)
29 :     | ACCEPT
30 :     | ERROR
31 :     exception Goto of state * nonterm
32 :     type table = {states: int, rules : int,initialState: state,
33 :     action: ((term,action) pairlist * action) array,
34 :     goto : (nonterm,state) pairlist array}
35 :     val numStates = fn ({states,...} : table) => states
36 :     val numRules = fn ({rules,...} : table) => rules
37 :     val describeActions =
38 :     fn ({action,...} : table) =>
39 :     fn (STATE s) => action sub s
40 :     val describeGoto =
41 :     fn ({goto,...} : table) =>
42 :     fn (STATE s) => goto sub s
43 :     fun findTerm (T term,row,default) =
44 :     let fun find (PAIR (T key,data,r)) =
45 :     if key < term then find r
46 :     else if key=term then data
47 :     else default
48 :     | find EMPTY = default
49 :     in find row
50 :     end
51 :     fun findNonterm (NT nt,row) =
52 :     let fun find (PAIR (NT key,data,r)) =
53 :     if key < nt then find r
54 :     else if key=nt then SOME data
55 :     else NONE
56 :     | find EMPTY = NONE
57 :     in find row
58 :     end
59 :     val action = fn ({action,...} : table) =>
60 :     fn (STATE state,term) =>
61 :     let val (row,default) = action sub state
62 :     in findTerm(term,row,default)
63 :     end
64 :     val goto = fn ({goto,...} : table) =>
65 :     fn (a as (STATE state,nonterm)) =>
66 :     case findNonterm(nonterm,goto sub state)
67 :     of SOME state => state
68 :     | NONE => raise (Goto a)
69 :     val initialState = fn ({initialState,...} : table) => initialState
70 :     val mkLrTable = fn {actions,gotos,initialState,numStates,numRules} =>
71 :     ({action=actions,goto=gotos,
72 :     states=numStates,
73 :     rules=numRules,
74 :     initialState=initialState} : table)
75 :     end;

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