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/parser2.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : monnier 2 (* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi
2 :     *
3 :     * $Log$
4 : monnier 8 * Revision 1.1.1.2 1998/01/18 01:00:08 monnier
5 :     * *** empty log message ***
6 : monnier 2 *
7 : monnier 8 * Revision 1.2 1997/08/26 19:18:54 jhr
8 :     * Replaced used of "abstraction" with ":>".
9 :     *
10 : monnier 2 # Revision 1.1.1.1 1997/01/14 01:38:04 george
11 :     # Version 109.24
12 :     #
13 :     * Revision 1.3 1996/10/03 03:36:58 jhr
14 :     * Qualified identifiers that are no-longer top-level (quot, rem, min, max).
15 :     *
16 :     * Revision 1.2 1996/02/26 15:02:29 george
17 :     * print no longer overloaded.
18 :     * use of makestring has been removed and replaced with Int.toString ..
19 :     * use of IO replaced with TextIO
20 :     *
21 :     * Revision 1.1.1.1 1996/01/31 16:01:42 george
22 :     * Version 109
23 :     *
24 :     *)
25 :    
26 :     (* parser.sml: This is a parser driver for LR tables with an error-recovery
27 :     routine added to it. The routine used is described in detail in this
28 :     article:
29 :    
30 :     'A Practical Method for LR and LL Syntactic Error Diagnosis and
31 :     Recovery', by M. Burke and G. Fisher, ACM Transactions on
32 :     Programming Langauges and Systems, Vol. 9, No. 2, April 1987,
33 :     pp. 164-197.
34 :    
35 :     This program is an implementation is the partial, deferred method discussed
36 :     in the article. The algorithm and data structures used in the program
37 :     are described below.
38 :    
39 :     This program assumes that all semantic actions are delayed. A semantic
40 :     action should produce a function from unit -> value instead of producing the
41 :     normal value. The parser returns the semantic value on the top of the
42 :     stack when accept is encountered. The user can deconstruct this value
43 :     and apply the unit -> value function in it to get the answer.
44 :    
45 :     It also assumes that the lexer is a lazy stream.
46 :    
47 :     Data Structures:
48 :     ----------------
49 :    
50 :     * The parser:
51 :    
52 :     The state stack has the type
53 :    
54 :     (state * (semantic value * line # * line #)) list
55 :    
56 :     The parser keeps a queue of (state stack * lexer pair). A lexer pair
57 :     consists of a terminal * value pair and a lexer. This allows the
58 :     parser to reconstruct the states for terminals to the left of a
59 :     syntax error, and attempt to make error corrections there.
60 :    
61 :     The queue consists of a pair of lists (x,y). New additions to
62 :     the queue are cons'ed onto y. The first element of x is the top
63 :     of the queue. If x is nil, then y is reversed and used
64 :     in place of x.
65 :    
66 :     Algorithm:
67 :     ----------
68 :    
69 :     * The steady-state parser:
70 :    
71 :     This parser keeps the length of the queue of state stacks at
72 :     a steady state by always removing an element from the front when
73 :     another element is placed on the end.
74 :    
75 :     It has these arguments:
76 :    
77 :     stack: current stack
78 :     queue: value of the queue
79 :     lexPair ((terminal,value),lex stream)
80 :    
81 :     When SHIFT is encountered, the state to shift to and the value are
82 :     are pushed onto the state stack. The state stack and lexPair are
83 :     placed on the queue. The front element of the queue is removed.
84 :    
85 :     When REDUCTION is encountered, the rule is applied to the current
86 :     stack to yield a triple (nonterm,value,new stack). A new
87 :     stack is formed by adding (goto(top state of stack,nonterm),value)
88 :     to the stack.
89 :    
90 :     When ACCEPT is encountered, the top value from the stack and the
91 :     lexer are returned.
92 :    
93 :     When an ERROR is encountered, fixError is called. FixError
94 :     takes the arguments to the parser, fixes the error if possible and
95 :     returns a new set of arguments.
96 :    
97 :     * The distance-parser:
98 :    
99 :     This parser includes an additional argument distance. It pushes
100 :     elements on the queue until it has parsed distance tokens, or an
101 :     ACCEPT or ERROR occurs. It returns a stack, lexer, the number of
102 :     tokens left unparsed, a queue, and an action option.
103 :     *)
104 :    
105 :     signature FIFO =
106 :     sig type 'a queue
107 :     val empty : 'a queue
108 :     exception Empty
109 :     val get : 'a queue -> 'a * 'a queue
110 :     val put : 'a * 'a queue -> 'a queue
111 :     end
112 :    
113 :     (* drt (12/15/89) -- the functor should be used in development work, but
114 :     it wastes space in the release version.
115 :    
116 :     functor ParserGen(structure LrTable : LR_TABLE
117 :     structure Stream : STREAM) : LR_PARSER =
118 :     *)
119 :    
120 :     structure LrParser :> LR_PARSER =
121 :     struct
122 :     structure LrTable = LrTable
123 :     structure Stream = Stream
124 :    
125 :     structure Token : TOKEN =
126 :     struct
127 :     structure LrTable = LrTable
128 :     datatype ('a,'b) token = TOKEN of LrTable.term * ('a * 'b * 'b)
129 :     val sameToken = fn (TOKEN(t,_),TOKEN(t',_)) => t=t'
130 :     end
131 :    
132 :     open LrTable
133 :     open Token
134 :    
135 :     val DEBUG1 = false
136 :     val DEBUG2 = false
137 :     exception ParseError
138 :     exception ParseImpossible of int
139 :    
140 :     structure Fifo :> FIFO =
141 :     struct
142 :     type 'a queue = ('a list * 'a list)
143 :     val empty = (nil,nil)
144 :     exception Empty
145 :     fun get(a::x, y) = (a, (x,y))
146 :     | get(nil, nil) = raise Empty
147 :     | get(nil, y) = get(rev y, nil)
148 :     fun put(a,(x,y)) = (x,a::y)
149 :     end
150 :    
151 :     type ('a,'b) elem = (state * ('a * 'b * 'b))
152 :     type ('a,'b) stack = ('a,'b) elem list
153 :     type ('a,'b) lexv = ('a,'b) token
154 :     type ('a,'b) lexpair = ('a,'b) lexv * (('a,'b) lexv Stream.stream)
155 :     type ('a,'b) distanceParse =
156 :     ('a,'b) lexpair *
157 :     ('a,'b) stack *
158 :     (('a,'b) stack * ('a,'b) lexpair) Fifo.queue *
159 :     int ->
160 :     ('a,'b) lexpair *
161 :     ('a,'b) stack *
162 :     (('a,'b) stack * ('a,'b) lexpair) Fifo.queue *
163 :     int *
164 :     action option
165 :    
166 :     type ('a,'b) ecRecord =
167 :     {is_keyword : term -> bool,
168 :     preferred_change : (term list * term list) list,
169 :     error : string * 'b * 'b -> unit,
170 :     errtermvalue : term -> 'a,
171 :     terms : term list,
172 :     showTerminal : term -> string,
173 :     noShift : term -> bool}
174 :    
175 :     local
176 :     val print = fn s => TextIO.output(TextIO.stdOut,s)
177 :     val println = fn s => (print s; print "\n")
178 :     val showState = fn (STATE s) => "STATE " ^ (Int.toString s)
179 :     in
180 :     fun printStack(stack: ('a,'b) stack, n: int) =
181 :     case stack
182 :     of (state,_) :: rest =>
183 :     (print("\t" ^ Int.toString n ^ ": ");
184 :     println(showState state);
185 :     printStack(rest, n+1))
186 :     | nil => ()
187 :    
188 :     fun prAction showTerminal
189 :     (stack as (state,_) :: _, next as (TOKEN (term,_),_), action) =
190 :     (println "Parse: state stack:";
191 :     printStack(stack, 0);
192 :     print(" state="
193 :     ^ showState state
194 :     ^ " next="
195 :     ^ showTerminal term
196 :     ^ " action="
197 :     );
198 :     case action
199 :     of SHIFT state => println ("SHIFT " ^ (showState state))
200 :     | REDUCE i => println ("REDUCE " ^ (Int.toString i))
201 :     | ERROR => println "ERROR"
202 :     | ACCEPT => println "ACCEPT")
203 :     | prAction _ (_,_,action) = ()
204 :     end
205 :    
206 :     (* ssParse: parser which maintains the queue of (state * lexvalues) in a
207 :     steady-state. It takes a table, showTerminal function, saction
208 :     function, and fixError function. It parses until an ACCEPT is
209 :     encountered, or an exception is raised. When an error is encountered,
210 :     fixError is called with the arguments of parseStep (lexv,stack,and
211 :     queue). It returns the lexv, and a new stack and queue adjusted so
212 :     that the lexv can be parsed *)
213 :    
214 :     val ssParse =
215 :     fn (table,showTerminal,saction,fixError,arg) =>
216 :     let val prAction = prAction showTerminal
217 :     val action = LrTable.action table
218 :     val goto = LrTable.goto table
219 :     fun parseStep(args as
220 :     (lexPair as (TOKEN (terminal, value as (_,leftPos,_)),
221 :     lexer
222 :     ),
223 :     stack as (state,_) :: _,
224 :     queue)) =
225 :     let val nextAction = action (state,terminal)
226 :     val _ = if DEBUG1 then prAction(stack,lexPair,nextAction)
227 :     else ()
228 :     in case nextAction
229 :     of SHIFT s =>
230 :     let val newStack = (s,value) :: stack
231 :     val newLexPair = Stream.get lexer
232 :     val (_,newQueue) =Fifo.get(Fifo.put((newStack,newLexPair),
233 :     queue))
234 :     in parseStep(newLexPair,(s,value)::stack,newQueue)
235 :     end
236 :     | REDUCE i =>
237 :     (case saction(i,leftPos,stack,arg)
238 :     of (nonterm,value,stack as (state,_) :: _) =>
239 :     parseStep(lexPair,(goto(state,nonterm),value)::stack,
240 :     queue)
241 :     | _ => raise (ParseImpossible 197))
242 :     | ERROR => parseStep(fixError args)
243 :     | ACCEPT =>
244 :     (case stack
245 :     of (_,(topvalue,_,_)) :: _ =>
246 :     let val (token,restLexer) = lexPair
247 :     in (topvalue,Stream.cons(token,restLexer))
248 :     end
249 :     | _ => raise (ParseImpossible 202))
250 :     end
251 :     | parseStep _ = raise (ParseImpossible 204)
252 :     in parseStep
253 :     end
254 :    
255 :     (* distanceParse: parse until n tokens are shifted, or accept or
256 :     error are encountered. Takes a table, showTerminal function, and
257 :     semantic action function. Returns a parser which takes a lexPair
258 :     (lex result * lexer), a state stack, a queue, and a distance
259 :     (must be > 0) to parse. The parser returns a new lex-value, a stack
260 :     with the nth token shifted on top, a queue, a distance, and action
261 :     option. *)
262 :    
263 :     val distanceParse =
264 :     fn (table,showTerminal,saction,arg) =>
265 :     let val prAction = prAction showTerminal
266 :     val action = LrTable.action table
267 :     val goto = LrTable.goto table
268 :     fun parseStep(lexPair,stack,queue,0) = (lexPair,stack,queue,0,NONE)
269 :     | parseStep(lexPair as (TOKEN (terminal, value as (_,leftPos,_)),
270 :     lexer
271 :     ),
272 :     stack as (state,_) :: _,
273 :     queue,distance) =
274 :     let val nextAction = action(state,terminal)
275 :     val _ = if DEBUG1 then prAction(stack,lexPair,nextAction)
276 :     else ()
277 :     in case nextAction
278 :     of SHIFT s =>
279 :     let val newStack = (s,value) :: stack
280 :     val newLexPair = Stream.get lexer
281 :     in parseStep(newLexPair,(s,value)::stack,
282 :     Fifo.put((newStack,newLexPair),queue),distance-1)
283 :     end
284 :     | REDUCE i =>
285 :     (case saction(i,leftPos,stack,arg)
286 :     of (nonterm,value,stack as (state,_) :: _) =>
287 :     parseStep(lexPair,(goto(state,nonterm),value)::stack,
288 :     queue,distance)
289 :     | _ => raise (ParseImpossible 240))
290 :     | ERROR => (lexPair,stack,queue,distance,SOME nextAction)
291 :     | ACCEPT => (lexPair,stack,queue,distance,SOME nextAction)
292 :     end
293 :     | parseStep _ = raise (ParseImpossible 242)
294 :     in parseStep : ('_a,'_b) distanceParse
295 :     end
296 :    
297 :     (* mkFixError: function to create fixError function which adjusts parser state
298 :     so that parse may continue in the presence of an error *)
299 :    
300 :     fun mkFixError({is_keyword,terms,errtermvalue,
301 :     preferred_change,noShift,
302 :     showTerminal,error,...} : ('_a,'_b) ecRecord,
303 :     distanceParse : ('_a,'_b) distanceParse,
304 :     minAdvance,maxAdvance)
305 :    
306 :     (lexv as (TOKEN (term,value as (_,leftPos,_)),_),stack,queue) =
307 :     let val _ = if DEBUG2 then
308 :     error("syntax error found at " ^ (showTerminal term),
309 :     leftPos,leftPos)
310 :     else ()
311 :    
312 :     fun tokAt(t,p) = TOKEN(t,(errtermvalue t,p,p))
313 :    
314 :     val minDelta = 3
315 :    
316 :     (* pull all the state * lexv elements from the queue *)
317 :    
318 :     val stateList =
319 :     let fun f q = let val (elem,newQueue) = Fifo.get q
320 :     in elem :: (f newQueue)
321 :     end handle Fifo.Empty => nil
322 :     in f queue
323 :     end
324 :    
325 :     (* now number elements of stateList, giving distance from
326 :     error token *)
327 :    
328 :     val (_, numStateList) =
329 :     List.foldr (fn (a,(num,r)) => (num+1,(a,num)::r)) (0, []) stateList
330 :    
331 :     (* Represent the set of potential changes as a linked list.
332 :    
333 :     Values of datatype Change hold information about a potential change.
334 :    
335 :     oper = oper to be applied
336 :     pos = the # of the element in stateList that would be altered.
337 :     distance = the number of tokens beyond the error token which the
338 :     change allows us to parse.
339 :     new = new terminal * value pair at that point
340 :     orig = original terminal * value pair at the point being changed.
341 :     *)
342 :    
343 :     datatype ('a,'b) change = CHANGE of
344 :     {pos : int, distance : int, leftPos: 'b, rightPos: 'b,
345 :     new : ('a,'b) lexv list, orig : ('a,'b) lexv list}
346 :    
347 :    
348 :     val showTerms = concat o map (fn TOKEN(t,_) => " " ^ showTerminal t)
349 :    
350 :     val printChange = fn c =>
351 :     let val CHANGE {distance,new,orig,pos,...} = c
352 :     in (print ("{distance= " ^ (Int.toString distance));
353 :     print (",orig ="); print(showTerms orig);
354 :     print (",new ="); print(showTerms new);
355 :     print (",pos= " ^ (Int.toString pos));
356 :     print "}\n")
357 :     end
358 :    
359 :     val printChangeList = app printChange
360 :    
361 :     (* parse: given a lexPair, a stack, and the distance from the error
362 :     token, return the distance past the error token that we are able to parse.*)
363 :    
364 :     fun parse (lexPair,stack,queuePos : int) =
365 :     case distanceParse(lexPair,stack,Fifo.empty,queuePos+maxAdvance+1)
366 :     of (_,_,_,distance,SOME ACCEPT) =>
367 :     if maxAdvance-distance-1 >= 0
368 :     then maxAdvance
369 :     else maxAdvance-distance-1
370 :     | (_,_,_,distance,_) => maxAdvance - distance - 1
371 :    
372 :     (* catList: concatenate results of scanning list *)
373 :    
374 :     fun catList l f = List.foldr (fn(a,r)=> f a @ r) [] l
375 :    
376 :     fun keywordsDelta new = if List.exists (fn(TOKEN(t,_))=>is_keyword t) new
377 :     then minDelta else 0
378 :    
379 :     fun tryChange{lex,stack,pos,leftPos,rightPos,orig,new} =
380 :     let val lex' = List.foldr (fn (t',p)=>(t',Stream.cons p)) lex new
381 :     val distance = parse(lex',stack,pos+length new-length orig)
382 :     in if distance >= minAdvance + keywordsDelta new
383 :     then [CHANGE{pos=pos,leftPos=leftPos,rightPos=rightPos,
384 :     distance=distance,orig=orig,new=new}]
385 :     else []
386 :     end
387 :    
388 :    
389 :     (* tryDelete: Try to delete n terminals.
390 :     Return single-element [success] or nil.
391 :     Do not delete unshiftable terminals. *)
392 :    
393 :    
394 :     fun tryDelete n ((stack,lexPair as (TOKEN(term,(_,l,r)),_)),qPos) =
395 :     let fun del(0,accum,left,right,lexPair) =
396 :     tryChange{lex=lexPair,stack=stack,
397 :     pos=qPos,leftPos=left,rightPos=right,
398 :     orig=rev accum, new=[]}
399 :     | del(n,accum,left,right,(tok as TOKEN(term,(_,_,r)),lexer)) =
400 :     if noShift term then []
401 :     else del(n-1,tok::accum,left,r,Stream.get lexer)
402 :     in del(n,[],l,r,lexPair)
403 :     end
404 :    
405 :     (* tryInsert: try to insert tokens before the current terminal;
406 :     return a list of the successes *)
407 :    
408 :     fun tryInsert((stack,lexPair as (TOKEN(_,(_,l,_)),_)),queuePos) =
409 :     catList terms (fn t =>
410 :     tryChange{lex=lexPair,stack=stack,
411 :     pos=queuePos,orig=[],new=[tokAt(t,l)],
412 :     leftPos=l,rightPos=l})
413 :    
414 :     (* trySubst: try to substitute tokens for the current terminal;
415 :     return a list of the successes *)
416 :    
417 :     fun trySubst ((stack,lexPair as (orig as TOKEN (term,(_,l,r)),lexer)),
418 :     queuePos) =
419 :     if noShift term then []
420 :     else
421 :     catList terms (fn t =>
422 :     tryChange{lex=Stream.get lexer,stack=stack,
423 :     pos=queuePos,
424 :     leftPos=l,rightPos=r,orig=[orig],
425 :     new=[tokAt(t,r)]})
426 :    
427 :     (* do_delete(toks,lexPair) tries to delete tokens "toks" from "lexPair".
428 :     If it succeeds, returns SOME(toks',l,r,lp), where
429 :     toks' is the actual tokens (with positions and values) deleted,
430 :     (l,r) are the (leftmost,rightmost) position of toks',
431 :     lp is what remains of the stream after deletion
432 :     *)
433 :     fun do_delete(nil,lp as (TOKEN(_,(_,l,_)),_)) = SOME(nil,l,l,lp)
434 :     | do_delete([t],(tok as TOKEN(t',(_,l,r)),lp')) =
435 :     if t=t'
436 :     then SOME([tok],l,r,Stream.get lp')
437 :     else NONE
438 :     | do_delete(t::rest,(tok as TOKEN(t',(_,l,r)),lp')) =
439 :     if t=t'
440 :     then case do_delete(rest,Stream.get lp')
441 :     of SOME(deleted,l',r',lp'') =>
442 :     SOME(tok::deleted,l,r',lp'')
443 :     | NONE => NONE
444 :     else NONE
445 :    
446 :     fun tryPreferred((stack,lexPair),queuePos) =
447 :     catList preferred_change (fn (delete,insert) =>
448 :     if List.exists noShift delete then [] (* should give warning at
449 :     parser-generation time *)
450 :     else case do_delete(delete,lexPair)
451 :     of SOME(deleted,l,r,lp) =>
452 :     tryChange{lex=lp,stack=stack,pos=queuePos,
453 :     leftPos=l,rightPos=r,orig=deleted,
454 :     new=map (fn t=>(tokAt(t,r))) insert}
455 :     | NONE => [])
456 :    
457 :     val changes = catList numStateList tryPreferred @
458 :     catList numStateList tryInsert @
459 :     catList numStateList trySubst @
460 :     catList numStateList (tryDelete 1) @
461 :     catList numStateList (tryDelete 2) @
462 :     catList numStateList (tryDelete 3)
463 :    
464 :     val findMaxDist = fn l =>
465 :     foldr (fn (CHANGE {distance,...},high) => Int.max(distance,high)) 0 l
466 :    
467 :     (* maxDist: max distance past error taken that we could parse *)
468 :    
469 :     val maxDist = findMaxDist changes
470 :    
471 :     (* remove changes which did not parse maxDist tokens past the error token *)
472 :    
473 :     val changes = catList changes
474 :     (fn(c as CHANGE{distance,...}) =>
475 :     if distance=maxDist then [c] else [])
476 :    
477 :     in case changes
478 :     of (l as change :: _) =>
479 :     let fun print_msg (CHANGE {new,orig,leftPos,rightPos,...}) =
480 :     let val s =
481 :     case (orig,new)
482 :     of (_::_,[]) => "deleting " ^ (showTerms orig)
483 :     | ([],_::_) => "inserting " ^ (showTerms new)
484 :     | _ => "replacing " ^ (showTerms orig) ^
485 :     " with " ^ (showTerms new)
486 :     in error ("syntax error: " ^ s,leftPos,rightPos)
487 :     end
488 :    
489 :     val _ =
490 :     (if length l > 1 andalso DEBUG2 then
491 :     (print "multiple fixes possible; could fix it by:\n";
492 :     app print_msg l;
493 :     print "chosen correction:\n")
494 :     else ();
495 :     print_msg change)
496 :    
497 :     (* findNth: find nth queue entry from the error
498 :     entry. Returns the Nth queue entry and the portion of
499 :     the queue from the beginning to the nth-1 entry. The
500 :     error entry is at the end of the queue.
501 :    
502 :     Examples:
503 :    
504 :     queue = a b c d e
505 :     findNth 0 = (e,a b c d)
506 :     findNth 1 = (d,a b c)
507 :     *)
508 :    
509 :     val findNth = fn n =>
510 :     let fun f (h::t,0) = (h,rev t)
511 :     | f (h::t,n) = f(t,n-1)
512 :     | f (nil,_) = let exception FindNth
513 :     in raise FindNth
514 :     end
515 :     in f (rev stateList,n)
516 :     end
517 :    
518 :     val CHANGE {pos,orig,new,...} = change
519 :     val (last,queueFront) = findNth pos
520 :     val (stack,lexPair) = last
521 :    
522 :     val lp1 = foldl(fn (_,(_,r)) => Stream.get r) lexPair orig
523 :     val lp2 = foldr(fn(t,r)=>(t,Stream.cons r)) lp1 new
524 :    
525 :     val restQueue =
526 :     Fifo.put((stack,lp2),
527 :     foldl Fifo.put Fifo.empty queueFront)
528 :    
529 :     val (lexPair,stack,queue,_,_) =
530 :     distanceParse(lp2,stack,restQueue,pos)
531 :    
532 :     in (lexPair,stack,queue)
533 :     end
534 :     | nil => (error("syntax error found at " ^ (showTerminal term),
535 :     leftPos,leftPos); raise ParseError)
536 :     end
537 :    
538 :     val parse = fn {arg,table,lexer,saction,void,lookahead,
539 :     ec=ec as {showTerminal,...} : ('_a,'_b) ecRecord} =>
540 :     let val distance = 15 (* defer distance tokens *)
541 :     val minAdvance = 1 (* must parse at least 1 token past error *)
542 :     val maxAdvance = Int.max(lookahead,0)(* max distance for parse check *)
543 :     val lexPair = Stream.get lexer
544 :     val (TOKEN (_,(_,leftPos,_)),_) = lexPair
545 :     val startStack = [(initialState table,(void,leftPos,leftPos))]
546 :     val startQueue = Fifo.put((startStack,lexPair),Fifo.empty)
547 :     val distanceParse = distanceParse(table,showTerminal,saction,arg)
548 :     val fixError = mkFixError(ec,distanceParse,minAdvance,maxAdvance)
549 :     val ssParse = ssParse(table,showTerminal,saction,fixError,arg)
550 :     fun loop (lexPair,stack,queue,_,SOME ACCEPT) =
551 :     ssParse(lexPair,stack,queue)
552 :     | loop (lexPair,stack,queue,0,_) = ssParse(lexPair,stack,queue)
553 :     | loop (lexPair,stack,queue,distance,SOME ERROR) =
554 :     let val (lexPair,stack,queue) = fixError(lexPair,stack,queue)
555 :     in loop (distanceParse(lexPair,stack,queue,distance))
556 :     end
557 :     | loop _ = let exception ParseInternal
558 :     in raise ParseInternal
559 :     end
560 :     in loop (distanceParse(lexPair,startStack,startQueue,distance))
561 :     end
562 :     end;
563 :    
564 :     (* drt (12/15/89) -- needed only when the code above is functorized
565 :    
566 :     structure LrParser = ParserGen(structure LrTable=LrTable
567 :     structure Stream=Stream);
568 :     *)

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