The ANTLR 4 parser generator can combine groups of transitions to form a single "set transition" in certain cases, reducing static and dynamic memory overhead as well as improving runtime performance. This can only occur if all alternatives of a block contain a single element or set. For example, the following code allows INT
and FLOAT
to be combined into a single transition:
// example 1
number
: INT
| FLOAT
;
// example 2, elements grouped into a set
primary
: '(' expression ')'
| (INT | FLOAT)
;
However, in the following situation the elements cannot be combined by the compiler so they'll be treated separately:
primary
: '(' expression ')'
| INT
| FLOAT
;
The hint suggests places where the simple addition of (
... )
is enough to allow the compiler to collapse a set that it would otherwise not be able to. Altering your code to the following would address the warning.
expression
: expression operator=DIV expression
| expression operator=MUL expression
| expression operator=ADD expression
| expression operator=SUB expression
| ( INT
| FLOAT
| BOOLEAN
| NULL
| ID
)
;