Commit ac83731e by POTTIER Francois

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

parent c3c60224
2015/07/20:
Added the command line options --unused-token <symbol> and --unused-tokens.
2015/06/29:
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 @@
\newcommand{\oexternaltokens}{\texttt{-{}-external-tokens}\xspace}
\newcommand{\ofixedexc}{\texttt{-{}-fixed-exception}\xspace}
\newcommand{\ograph}{\texttt{-{}-graph}\xspace}
\newcommand{\oignoreone}{\texttt{-{}-unused-token}\xspace}
\newcommand{\oignoreall}{\texttt{-{}-unused-tokens}\xspace}
\newcommand{\oinfer}{\texttt{-{}-infer}\xspace}
\newcommand{\ointerpret}{\texttt{-{}-interpret}\xspace}
\newcommand{\ointerpretshowcst}{\texttt{-{}-interpret-show-cst}\xspace}
......
......@@ -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
unused.
\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,16 +717,18 @@ let check_parameterized_grammar_is_well_defined grammar =
) grammar.p_rules;
(* Check that every token is used. *)
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
Error.warning [p]
(Printf.sprintf "the token %s is unused." token)
) grammar.p_tokens
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
|| StringSet.mem token Settings.ignored_unused_tokens) then
Error.warning [p]
(Printf.sprintf "the token %s is unused." token)
) grammar.p_tokens
end;
grammar
......
......@@ -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 =
!fixedexc
let ignored_unused_tokens =
!ignored_unused_tokens
let ignore_all_unused_tokens =
!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