diff --git a/src/grammar.ml b/src/grammar.ml index 066b1ff30662ee6e74c16dce1c360f82b21353b4..b934dd290d2a9998e46c695e30e3da3fdde494ca 100644 --- a/src/grammar.ml +++ b/src/grammar.ml @@ -127,6 +127,14 @@ module Nonterminal = struct with Not_found -> None + let ocamltype_of_start_symbol nt = + match ocamltype nt with + | Some typ -> + typ + | None -> + (* Every start symbol has a type. *) + assert false + let tabulate f = Array.get (Array.init n f) diff --git a/src/grammar.mli b/src/grammar.mli index 70b5e9c5bd402da1c3b826b582a82ef1e93bf60c..4f22d1a207fd69f5f19fcb964fc1fb3af00dc203 100644 --- a/src/grammar.mli +++ b/src/grammar.mli @@ -46,6 +46,11 @@ module Nonterminal : sig val ocamltype: t -> Stretch.ocamltype option + (* A start symbol always has a type. This allows us to define + a simplified version of [ocamltype] for start symbols. *) + + val ocamltype_of_start_symbol: t -> Stretch.ocamltype + (* Iteration over nonterminals. The order in which elements are examined, and the order of [map]'s output list, correspond to the numeric indices produced by [n2i] above. *) diff --git a/src/lr1.ml b/src/lr1.ml index d179897498ae63ce11dba17de275f3b055dd0556..90701ab22b07878c9415976326c9375daf9d34d6 100644 --- a/src/lr1.ml +++ b/src/lr1.ml @@ -1102,11 +1102,7 @@ let fold_entry f accu = assert false (* this is a start production *) in let t : Stretch.ocamltype = - match Nonterminal.ocamltype nt with - | Some t -> - t - | None -> - assert false (* every start symbol should carry a type *) + Nonterminal.ocamltype_of_start_symbol nt in f prod state nt t accu ) entry accu