1141 \\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ |
1141 \\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ |
1142 \\000" |
1142 \\000" |
1143 ), |
1143 ), |
1144 (0, "")] |
1144 (0, "")] |
1145 fun f x = x |
1145 fun f x = x |
1146 val s = map f (rev (tl (rev s))) |
1146 val s = List.map f (List.rev (tl (List.rev s))) |
1147 exception LexHackingError |
1147 exception LexHackingError |
1148 fun look ((j,x)::r, i: int) = if i = j then x else look(r, i) |
1148 fun look ((j,x)::r, i: int) = if i = j then x else look(r, i) |
1149 | look ([], i) = raise LexHackingError |
1149 | look ([], i) = raise LexHackingError |
1150 fun g {fin=x, trans=i} = {fin=x, trans=look(s,i)} |
1150 fun g {fin=x, trans=i} = {fin=x, trans=look(s,i)} |
1151 in Vector.fromList(map g |
1151 in Vector.fromList(List.map g |
1152 [{fin = [], trans = 0}, |
1152 [{fin = [], trans = 0}, |
1153 {fin = [(N 2)], trans = 1}, |
1153 {fin = [(N 2)], trans = 1}, |
1154 {fin = [(N 2)], trans = 1}, |
1154 {fin = [(N 2)], trans = 1}, |
1155 {fin = [(N 84)], trans = 3}, |
1155 {fin = [(N 84)], trans = 3}, |
1156 {fin = [(N 71)], trans = 0}, |
1156 {fin = [(N 71)], trans = 0}, |
1326 let fun action (i,nil) = raise LexError |
1326 let fun action (i,nil) = raise LexError |
1327 | action (i,nil::l) = action (i-1,l) |
1327 | action (i,nil::l) = action (i-1,l) |
1328 | action (i,(node::acts)::l) = |
1328 | action (i,(node::acts)::l) = |
1329 case node of |
1329 case node of |
1330 Internal.N yyk => |
1330 Internal.N yyk => |
1331 (let fun yymktext() = substring(!yyb,i0,i-i0) |
1331 (let fun yymktext() = String.substring(!yyb,i0,i-i0) |
1332 val yypos = i0+ !yygone |
1332 val yypos = i0+ !yygone |
1333 open UserDeclarations Internal.StartStates |
1333 open UserDeclarations Internal.StartStates |
1334 in (yybufpos := i; case yyk of |
1334 in (yybufpos := i; case yyk of |
1335 |
1335 |
1336 (* Application actions *) |
1336 (* Application actions *) |
1412 val NewAcceptingLeaves = fin::AcceptingLeaves |
1412 val NewAcceptingLeaves = fin::AcceptingLeaves |
1413 in if l = !yybl then |
1413 in if l = !yybl then |
1414 if trans = #trans(Vector.sub(Internal.tab,0)) |
1414 if trans = #trans(Vector.sub(Internal.tab,0)) |
1415 then action(l,NewAcceptingLeaves |
1415 then action(l,NewAcceptingLeaves |
1416 ) else let val newchars= if !yydone then "" else yyinput 1024 |
1416 ) else let val newchars= if !yydone then "" else yyinput 1024 |
1417 in if (size newchars)=0 |
1417 in if (String.size newchars)=0 |
1418 then (yydone := true; |
1418 then (yydone := true; |
1419 if (l=i0) then UserDeclarations.eof yyarg |
1419 if (l=i0) then UserDeclarations.eof yyarg |
1420 else action(l,NewAcceptingLeaves)) |
1420 else action(l,NewAcceptingLeaves)) |
1421 else (if i0=l then yyb := newchars |
1421 else (if i0=l then yyb := newchars |
1422 else yyb := substring(!yyb,i0,l-i0)^newchars; |
1422 else yyb := String.substring(!yyb,i0,l-i0)^newchars; |
1423 yygone := !yygone+i0; |
1423 yygone := !yygone+i0; |
1424 yybl := size (!yyb); |
1424 yybl := String.size (!yyb); |
1425 scan (s,AcceptingLeaves,l-i0,0)) |
1425 scan (s,AcceptingLeaves,l-i0,0)) |
1426 end |
1426 end |
1427 else let val NewChar = Char.ord(String.sub(!yyb,l)) |
1427 else let val NewChar = Char.ord(String.sub(!yyb,l)) |
1428 val NewChar = if NewChar<128 then NewChar else 128 |
1428 val NewChar = if NewChar<128 then NewChar else 128 |
1429 val NewState = Char.ord(String.sub(trans,NewChar)) |
1429 val NewState = Char.ord(String.sub(trans,NewChar)) |
1430 in if NewState=0 then action(l,NewAcceptingLeaves) |
1430 in if NewState=0 then action(l,NewAcceptingLeaves) |
1431 else scan(NewState,NewAcceptingLeaves,l+1,i0) |
1431 else scan(NewState,NewAcceptingLeaves,l+1,i0) |
1432 end |
1432 end |
1433 end |
1433 end |
1434 (* |
1434 (* |
1435 val start= if substring(!yyb,!yybufpos-1,1)="\n" |
1435 val start= if String.substring(!yyb,!yybufpos-1,1)="\n" |
1436 then !yybegin+1 else !yybegin |
1436 then !yybegin+1 else !yybegin |
1437 *) |
1437 *) |
1438 in scan(!yybegin (* start *),nil,!yybufpos,!yybufpos) |
1438 in scan(!yybegin (* start *),nil,!yybufpos,!yybufpos) |
1439 end |
1439 end |
1440 in continue end |
1440 in continue end |
3602 val memo = Array.array(numstates+numrules,ERROR) |
3602 val memo = Array.array(numstates+numrules,ERROR) |
3603 val _ =let fun g i=(Array.update(memo,i,REDUCE(i-numstates)); g(i+1)) |
3603 val _ =let fun g i=(Array.update(memo,i,REDUCE(i-numstates)); g(i+1)) |
3604 fun f i = |
3604 fun f i = |
3605 if i=numstates then g i |
3605 if i=numstates then g i |
3606 else (Array.update(memo,i,SHIFT (STATE i)); f (i+1)) |
3606 else (Array.update(memo,i,SHIFT (STATE i)); f (i+1)) |
3607 in f 0 handle Subscript => () |
3607 in f 0 handle General.Subscript => () |
3608 end |
3608 end |
3609 in |
3609 in |
3610 val entry_to_action = fn 0 => ACCEPT | 1 => ERROR | j => Array.sub(memo,(j-2)) |
3610 val entry_to_action = fn 0 => ACCEPT | 1 => ERROR | j => Array.sub(memo,(j-2)) |
3611 end |
3611 end |
3612 val gotoT=Array.fromList(string_to_table(string_to_pairlist(NT,STATE),gotoT)) |
3612 val gotoT=Array.fromList(string_to_table(string_to_pairlist(NT,STATE),gotoT)) |
3613 val actionRows=string_to_table(string_to_pairlist_default(T,entry_to_action),actionRows) |
3613 val actionRows=string_to_table(string_to_pairlist_default(T,entry_to_action),actionRows) |
3614 val actionRowNumbers = string_to_list actionRowNumbers |
3614 val actionRowNumbers = string_to_list actionRowNumbers |
3615 val actionT = let val actionRowLookUp= |
3615 val actionT = let val actionRowLookUp= |
3616 let val a=Array.fromList(actionRows) in fn i=>Array.sub(a,i) end |
3616 let val a=Array.fromList(actionRows) in fn i=>Array.sub(a,i) end |
3617 in Array.fromList(map actionRowLookUp actionRowNumbers) |
3617 in Array.fromList(List.map actionRowLookUp actionRowNumbers) |
3618 end |
3618 end |
3619 in LrTable.mkLrTable {actions=actionT,gotos=gotoT,numRules=numrules, |
3619 in LrTable.mkLrTable {actions=actionT,gotos=gotoT,numRules=numrules, |
3620 numStates=numstates,initialState=STATE 0} |
3620 numStates=numstates,initialState=STATE 0} |
3621 end |
3621 end |
3622 end |
3622 end |