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

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