Should we warn about unused productions?
twd2 opened this issue · comments
Before write this line, should we check if ts
is empty? If it is empty, the production is unused, and should we warn about it?
Currently, in some situation, this program may generate a Table.java
like this:
// ...
switch (lookahead) {
case PRINT:
case CASE:
case COMPLEX:
case VOID:
case FOR:
case '!':
case '-':
case CLASS:
case READ_LINE:
case WHILE:
case RETURN:
case NULL:
case INT:
case PRINT_COMP:
case SCOPY:
case '}':
case '@':
case DO:
case IDENTIFIER:
case NEW:
case '$':
case IF:
case THIS:
case INSTANCEOF:
case STRING:
case LITERAL:
case BRANCH:
case ELSE:
case '(':
case ';':
case '#':
case OD:
case DCOPY:
case BOOL:
case SUPER:
case BREAK:
case READ_INTEGER:
case '{':
return new Pair<>(131, Arrays.asList()); // <---
return new Pair<>(43, Arrays.asList(ELSE, Stmt)); // <---
default: return null;
}
// ...
This two lines make Java compiler unhappy.
Please provide some syntax that ts
can be empty.
A modified decaf grammar:
// ...
ElseClause : /* empty */ // higher priority
| ELSE Stmt
{
$$.stmt = $2.stmt;
}
;
// ...
Note that the priority is swapped.
It seems that we should warn, closing.