grammar: warn about unused precedence for symbols

Symbols with precedence but no associativity, and whose precedence is
never used, can be declared with %token instead.  The used precedence
relationships are recorded and a warning about useless ones is issued.

* src/conflicts.c (resolve_sr_conflict): Record precedence relation.
* src/symtab.c, src/symtab.h (prec_nodes, init_prec_nodes)
(symgraphlink_new, register_precedence_second_symbol)
(print_precedence_warnings): New.
Record relationships in a graph and warn about useless ones.
* src/main.c (main): Print precedence warnings.
* tests/conflicts.at: New.
This commit is contained in:
Valentin Tolmer
2013-01-29 14:55:53 +01:00
committed by Akim Demaille
parent fbecd2ab59
commit 284bc49c83
6 changed files with 211 additions and 1 deletions

View File

@@ -224,6 +224,52 @@ extern symbol *startsymbol;
extern location startsymbol_location;
/*-------------------.
| Symbol Relations. |
`-------------------*/
/* The symbol relations are represented by a directed graph. */
/* The id of a node */
typedef int graphid;
typedef struct symgraphlink symgraphlink;
struct symgraphlink
{
/** The second \c symbol or group of a precedence relation.
* See \c symgraph. */
graphid id;
symgraphlink *next;
};
/* Symbol precedence graph, to store the used precedence relations between
* symbols. */
typedef struct symgraph symgraph;
struct symgraph
{
/** Identifier for the node: equal to the number of the symbol. */
graphid id;
/** The list of related symbols that have a smaller precedence. */
symgraphlink *succ;
/** The list of related symbols that have a greater precedence. */
symgraphlink *pred;
};
/** Register a new precedence relation as used. */
void register_precedence (graphid first, graphid snd);
/** Print a warning for each symbol whose precedence is useless. */
void print_precedence_warnings (void);
/*-----------------.
| Semantic types. |
`-----------------*/