Commit abb0189f authored by POTTIER Francois's avatar POTTIER Francois

Report an error if one the start symbols produces the empty language

or the singleton language {epsilon}.
parent caf6b8df
...@@ -796,14 +796,8 @@ let compute (basecase : bool) : (bool array) * (Symbol.t -> bool) = ...@@ -796,14 +796,8 @@ let compute (basecase : bool) : (bool array) * (Symbol.t -> bool) =
); );
property, symbol_has_property property, symbol_has_property
let () = let (nonempty : bool array), _ =
let nonempty, _ = compute true in compute true
for nt = Nonterminal.start to Nonterminal.n - 1 do
if not nonempty.(nt) then
Error.grammar_warning
(Nonterminal.positions nt)
(Printf.sprintf "%s generates the empty language." (Nonterminal.print false nt))
done
let (nullable : bool array), (nullable_symbol : Symbol.t -> bool) = let (nullable : bool array), (nullable_symbol : Symbol.t -> bool) =
compute false compute false
...@@ -849,6 +843,34 @@ let () = ...@@ -849,6 +843,34 @@ let () =
TerminalSet.compare original updated <> 0 TerminalSet.compare original updated <> 0
) )
(* ------------------------------------------------------------------------ *)
let () =
(* If a start symbol generates the empty language or generates
the language {epsilon}, report an error. In principle, this
could be just a warning. However, in [Engine], in the function
[start], it is convenient to assume that neither of these
situations can arise. This means that at least one token must
be read. *)
StringSet.iter (fun symbol ->
let nt = Nonterminal.lookup symbol in
if not nonempty.(nt) then
Error.error
(Nonterminal.positions nt)
(Printf.sprintf "%s generates the empty language." (Nonterminal.print false nt));
if TerminalSet.is_empty first.(nt) then
Error.error
(Nonterminal.positions nt)
(Printf.sprintf "%s generates the language {epsilon}." (Nonterminal.print false nt))
) Front.grammar.start_symbols;
(* If a nonterminal symbol generates the empty language, issue a warning. *)
for nt = Nonterminal.start to Nonterminal.n - 1 do
if not nonempty.(nt) then
Error.grammar_warning
(Nonterminal.positions nt)
(Printf.sprintf "%s generates the empty language." (Nonterminal.print false nt));
done
(* ------------------------------------------------------------------------ *) (* ------------------------------------------------------------------------ *)
(* Dump the analysis results. *) (* Dump the analysis results. *)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment