antlr - Is "Implicit token definition in parser rule" something to worry about? -
i'm creating first grammar antlr , antlrworks 2. have finished grammar (it recognizes code written in described language , builds correct parse trees), haven't started beyond that.
what worries me every first occurrence of token in parser rule underlined yellow squiggle saying "implicit token definition in parser rule".
for example, in rule, 'var' has squiggle:
variabledeclaration: 'var' identifier ('=' expression)?; how looks exactly:

the odd thing antlr doesn't seem mind these rules (when doing test rig test, can't see of these warning in parser generator output, incorrect java version being installed on machine), it's antlrworks complaining.
is worry or should ignore these warnings? should declare tokens explicitly in lexer rules? exaples in official bible the defintive antlr reference seem done way write code.
i highly recommend correcting instances of warning in code of importance.
this warning created (by me actually) alert situations following:
shiftexpr : id (('<<' | '>>') id)?; since antlr 4 encourages action code written in separate files in target language instead of embedding them directly in grammar, it's important able distinguish between << , >>. if tokens not explicitly created these operators, assigned arbitrary types , no named constants available referencing them.
this warning helps avoid following problematic situations:
- a parser rule contains misspelled token reference. without warning, lead silent creation of additional token may never matched.
a parser rule contains unintentional token reference, such following:
number : 0 | integer; 0 : '0'; // <-- implicit definition causes 0 own token
Comments
Post a Comment