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 140 - (view) (download)

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

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