equal
deleted
inserted
replaced
16 Node of string * parsetree list | |
16 Node of string * parsetree list | |
17 Tip of Lexicon.token |
17 Tip of Lexicon.token |
18 exception PARSETREE of parsetree |
18 exception PARSETREE of parsetree |
19 val pretty_parsetree: parsetree -> Pretty.T |
19 val pretty_parsetree: parsetree -> Pretty.T |
20 val parse: gram -> string -> Lexicon.token list -> parsetree list |
20 val parse: gram -> string -> Lexicon.token list -> parsetree list |
21 val guess_infix_lr: gram -> string -> (string * bool * bool * int) option |
|
22 val branching_level: int Config.T |
21 val branching_level: int Config.T |
23 end; |
22 end; |
24 |
23 |
25 structure Parser: PARSER = |
24 structure Parser: PARSER = |
26 struct |
25 struct |
716 (case earley gram start (toks @ [Lexicon.mk_eof end_pos]) of |
715 (case earley gram start (toks @ [Lexicon.mk_eof end_pos]) of |
717 [] => raise Fail "Inner syntax: no parse trees" |
716 [] => raise Fail "Inner syntax: no parse trees" |
718 | pts => pts); |
717 | pts => pts); |
719 in r end; |
718 in r end; |
720 |
719 |
721 |
|
722 fun guess_infix_lr (Gram gram) c = (*based on educated guess*) |
|
723 let |
|
724 fun freeze a = map_range (curry Vector.sub a) (Vector.length a); |
|
725 val prods = maps (prods_content o #2) (freeze (#prods gram)); |
|
726 fun guess (SOME ([Nonterminal (_, k), Terminal tok, Nonterminal (_, l)], _, j)) = |
|
727 if Lexicon.is_literal tok then |
|
728 if k = j andalso l = j + 1 then SOME (Lexicon.str_of_token tok, true, false, j) |
|
729 else if k = j + 1 then if l = j then SOME (Lexicon.str_of_token tok, false, true, j) |
|
730 else if l = j + 1 then SOME (Lexicon.str_of_token tok, false, false, j) |
|
731 else NONE |
|
732 else NONE |
|
733 else NONE |
|
734 | guess _ = NONE; |
|
735 in guess (find_first (fn (_, s, _) => s = c) prods) end; |
|
736 |
|
737 end; |
720 end; |