Commit eb0b523f by POTTIER Francois

New flag --unused-precedence-levels.

parent 91a823fc
# Changes
## 2017/12/22
* Add a flag `--unused-precedence-levels` to suppress all warnings about
useless `%left`, `%right`, `%nonassoc` and `%prec` declarations.
(Suggested by Zachary Tatlock.)
## 2017/12/06
* Fix the termination test that takes place before parameterized symbols are
......
......@@ -127,6 +127,7 @@
\newcommand{\ograph}{\texttt{-{}-graph}\xspace}
\newcommand{\oignoreone}{\texttt{-{}-unused-token}\xspace}
\newcommand{\oignoreall}{\texttt{-{}-unused-tokens}\xspace}
\newcommand{\oignoreprec}{\texttt{-{}-unused-precedence-levels}\xspace}
\newcommand{\oinfer}{\texttt{-{}-infer}\xspace}
\newcommand{\oinspection}{\texttt{-{}-inspection}\xspace}
\newcommand{\ointerpret}{\texttt{-{}-interpret}\xspace}
......
......@@ -183,13 +183,6 @@ 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},
......@@ -364,6 +357,16 @@ logged to the standard error channel. This is analogous to \texttt{ocamlrun}'s
\texttt{p=1} parameter, except this switch must be enabled at compile time:
one cannot selectively enable or disable tracing at runtime.
\docswitch{\oignoreprec} This switch suppresses all warnings about
useless \dleft, \dright, \dnonassoc and \dprec declarations.
\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{\oupdateerrors \nt{filename}} This switch causes \menhir to
read the \messages file \nt{filename} and to produce on the standard output
channel a new \messages file that is identical, except the auto-generated
......
......@@ -1508,8 +1508,10 @@ end
should be invoked after only the automaton has been constructed. *)
let diagnostics () =
TokPrecedence.diagnostics();
Production.diagnostics()
if not Settings.ignore_all_unused_precedence_levels then begin
TokPrecedence.diagnostics();
Production.diagnostics()
end
(* ------------------------------------------------------------------------ *)
(* %on_error_reduce declarations. *)
......
......@@ -203,6 +203,9 @@ let ignore_unused_token t =
let ignore_all_unused_tokens =
ref false
let ignore_all_unused_precedence_levels =
ref false
let list_errors =
ref false
......@@ -294,6 +297,7 @@ 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, " Generate tracing instructions";
"--unused-precedence-levels", Arg.Set ignore_all_unused_precedence_levels, " Do not warn about unused precedence levels";
"--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";
"--update-errors", Arg.String set_update_errors, "<filename> Update auto-comments in a .messages file";
......@@ -497,6 +501,9 @@ let ignored_unused_tokens =
let ignore_all_unused_tokens =
!ignore_all_unused_tokens
let ignore_all_unused_precedence_levels =
!ignore_all_unused_precedence_levels
let list_errors =
!list_errors
......
......@@ -192,6 +192,10 @@ val ignored_unused_tokens: StringSet.t
val ignore_all_unused_tokens: bool
(* This flag suppresses all warnings about unused precedence levels. *)
val ignore_all_unused_precedence_levels: bool
(* This flag causes Menhir to produce a list of erroneous input sentences.
Enough sentences are computed to produce exactly one error in every state
where an error can occur. *)
......
Grammar has 2 nonterminal symbols, among which 1 start symbols.
Grammar has 8 terminal symbols.
Grammar has 8 productions.
nullable(main) = false
nullable(expr) = false
first(main) = MINUS LPAREN INT
first(expr) = MINUS LPAREN INT
follow(main) = #
follow(expr) = TIMES RPAREN PLUS MINUS EOL DIV
Built an LR(0) automaton with 18 states.
The grammar is not SLR(1) -- 5 states have a conflict.
Built an LR(1) automaton with 18 states.
20 shift/reduce conflicts were silently solved.
7 out of 18 states have a default reduction.
7 out of 18 states are represented.
0 out of 13 symbols keep track of their start position.
0 out of 13 symbols keep track of their end position.
4 out of 9 productions exploit shiftreduce optimization.
0 out of 18 states can peek at an error.
53 functions before inlining, 11 functions after inlining.
--unused-precedence-levels
(* A copy of calc.mly, with an extra intentionally useless
precedence declaration -- warning suppressed via a flag. *)
%token <int> INT
%token PLUS MINUS TIMES DIV
%token LPAREN RPAREN
%token EOL
%left EOL
%left PLUS MINUS
%left TIMES DIV
%nonassoc UMINUS
%start main
%type <int> main
%%
main:
expr EOL { $1 }
;
expr:
INT { $1 }
| LPAREN expr RPAREN { $2 }
| expr PLUS expr { $1 + $3 }
| expr MINUS expr { $1 - $3 }
| expr TIMES expr { $1 * $3 }
| expr DIV expr { $1 / $3 }
| MINUS expr %prec UMINUS { - $2 }
;
%start main
%token DIV
%token EOL
%token <int> INT
%token LPAREN
%token MINUS
%token PLUS
%token RPAREN
%token TIMES
%left EOL
%left MINUS PLUS
%left DIV TIMES
%nonassoc UMINUS
%type <int> main
%%
main:
_1 = expr _2 = EOL
{ ( _1 )}
expr:
_1 = INT
{ ( _1 )}
| _1 = LPAREN _2 = expr _3 = RPAREN
{ ( _2 )}
| _1 = expr _2 = PLUS _3 = expr
{ ( _1 + _3 )}
| _1 = expr _2 = MINUS _3 = expr
{ ( _1 - _3 )}
| _1 = expr _2 = TIMES _3 = expr
{ ( _1 * _3 )}
| _1 = expr _2 = DIV _3 = expr
{ ( _1 / _3 )}
| _1 = MINUS _2 = expr %prec UMINUS
{ ( - _2 )}
%%
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