Commit ac83731e authored by POTTIER Francois's avatar POTTIER Francois

Added the options --unused-token <token> and --unused-tokens.

parent c3c60224
Added the command line options --unused-token <symbol> and --unused-tokens.
Changed the treatment of the positional keywords $i. They are now
rewritten into variables of the form '_i' where 'i' is an integer.
......@@ -104,10 +104,6 @@
le cours de compilation où on démarre avec une grammaire à trous),
par exemple les non-terminaux inaccessibles
* add a way of turning off the "unused token" warning for a specific token
(or for all of them) This is legitimate because the lexer might be designed
to produce certain tokens that the parser does not use at all.
* move to a new license (GPL V2?), as per Hongbo Zhang's request.
* Les fichiers dans demos/ ne devraient pas être sous QPL mais libres...
......@@ -109,6 +109,8 @@
......@@ -156,6 +156,13 @@ vertices are the grammar's nonterminal symbols. There is a directed edge from
vertex $A$ to vertex $B$ if the definition of $A$ refers to $B$. The file is
in a format that is suitable for processing by the \emph{graphviz} toolkit.
\docswitch{\oignoreone \nt{symbol}} This switch suppresses the warning that
is normally emitted when \menhir finds that the terminal symbol \nt{symbol} is
\docswitch{\oignoreall} This switch suppresses all of the warnings that are
normally emitted when \menhir finds that some terminal symbols are unused.
\docswitch{\oinfer} This switch causes the semantic actions to be checked for
type consistency \emph{before} the parser is generated. This is done by
invoking the \ocaml compiler. Use of \oinfer is \textbf{strongly recommended},
......@@ -717,13 +717,15 @@ let check_parameterized_grammar_is_well_defined grammar =
) grammar.p_rules;
(* Check that every token is used. *)
begin match Settings.token_type_mode with
if not Settings.ignore_all_unused_tokens then begin
match Settings.token_type_mode with
| Settings.TokenTypeOnly ->
| Settings.TokenTypeAndCode
| Settings.CodeOnly _ ->
StringMap.iter (fun token { tk_position = p } ->
if not (StringSet.mem token !used_tokens) then
if not (StringSet.mem token !used_tokens
|| StringSet.mem token Settings.ignored_unused_tokens) then
Error.warning [p]
(Printf.sprintf "the token %s is unused." token)
) grammar.p_tokens
......@@ -159,6 +159,15 @@ type suggestion =
let suggestion =
ref SuggestNothing
let ignored_unused_tokens =
ref StringSet.empty
let ignore_unused_token t =
ignored_unused_tokens := StringSet.add t !ignored_unused_tokens
let ignore_all_unused_tokens =
ref false
let options = Arg.align [
"--base", Arg.Set_string base, "<basename> Specifies a base name for the output file(s)";
"--canonical", Arg.Unit (fun () -> construction_mode := ModeCanonical), " Construct a canonical Knuth LR(1) automaton";
......@@ -208,6 +217,8 @@ let options = Arg.align [
"--table", Arg.Set table, " Use the table-based back-end";
"--timings", Arg.Set timings, " Display internal timings";
"--trace", Arg.Set trace, " Include tracing instructions in the generated code";
"--unused-token", Arg.String ignore_unused_token, "<token> Do not warn that <token> is unused";
"--unused-tokens", Arg.Set ignore_all_unused_tokens, " Do not warn about any unused token";
"--version", Arg.Set version, " Show version number and exit";
"-b", Arg.Set_string base, "<basename> Synonymous with --base <basename>";
"-lg", Arg.Set_int logG, " Synonymous with --log-grammar";
......@@ -389,3 +400,8 @@ let strict =
let fixedexc =
let ignored_unused_tokens =
let ignore_all_unused_tokens =
......@@ -163,3 +163,13 @@ val strict: bool
val fixedexc: bool
(* This is a set of tokens which may be unused and about which we should not
emit a warning. *)
val ignored_unused_tokens: StringSet.t
(* This flag supersedes the set [ignored_unused_tokens]. If it is set, then
we should not emit a warning about any unused tokens. *)
val ignore_all_unused_tokens: bool
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