Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
POTTIER Francois
menhir
Commits
abb0189f
Commit
abb0189f
authored
Dec 11, 2014
by
POTTIER Francois
Browse files
Report an error if one the start symbols produces the empty language
or the singleton language {epsilon}.
parent
caf6b8df
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/grammar.ml
View file @
abb0189f
...
...
@@ -796,14 +796,8 @@ let compute (basecase : bool) : (bool array) * (Symbol.t -> bool) =
);
property
,
symbol_has_property
let
()
=
let
nonempty
,
_
=
compute
true
in
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
(
nonempty
:
bool
array
)
,
_
=
compute
true
let
(
nullable
:
bool
array
)
,
(
nullable_symbol
:
Symbol
.
t
->
bool
)
=
compute
false
...
...
@@ -849,6 +843,34 @@ let () =
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. *)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment