ANTLR mismatched input '<EOF>'

Jared Beck

Given the following ANTLR 4.1 grammar, with one line intentionally commented out ...

grammar Foobar;

//whyDoesThisRuleHelp : expression ;
expression : operand | binaryOperation ;
binaryOperation : operand WS BINARY_OPERATOR WS expression ;
operand : LETTER ;

BINARY_OPERATOR : 'EQ' ;
LETTER : [a-z] ;
WS : [ \n]+ ;

.. why does echo -n "a EQ b" | grun Foobar expression produce

line 1:6 mismatched input '<EOF>' expecting WS

.. but if we uncomment the block : expression ; line above then grun produces no errors?

Sam Harwell

You are seeing the effects of a rare but known bug:
No viable alternative can be incorrectly thrown for start rules without explicit EOF

The performance implications of properly fixing this are currently staggering, so we have no intention of applying the patch for the foreseeable future. The workaround is to create a rule that ends with an explicit EOF, and start parsing there.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ANTLR mismatched input '<EOF>'

From Dev

ANTLR Grammar line 1:6 mismatched input '<EOF>' expecting '.'

From Dev

ANTLR mismatched input error

From Dev

ANTLR 4.2.2: mismatched input

From Dev

ANTLR mismatched input error

From Dev

mismatched input ')' expecting EOF in CQL

From Dev

mismatched input ')' expecting EOF in CQL

From Dev

mismatched input in antlr generated parser

From Dev

ANTLR4 : mismatched input

From Dev

"Mismatched input <EOF>" with very simple grammar

From Dev

"Mismatched input <EOF>" with very simple grammar

From Dev

Antlr : beginner 's mismatched input expecting ID

From Dev

ANTLR 4.5 - Mismatched Input 'x' expecting 'x'

From Dev

Antlr v4: 'mismatched input'

From Dev

Antlr - mismatched input error - token not recognised

From Dev

Why am I getting "mismatched input 'addr' expecting {<EOF>, 'addr'}"

From Dev

Antlr v4 Can I ignore mismatched input?

From Dev

Antlr v4 Can I ignore mismatched input?

From Dev

ANTLR 4.5: line 1:22 mismatched input 'randomly' expecting DIRECTION

From Dev

ANTLR4 Grammar extraneous / mismatched input error

From Dev

Mismatched input ',' expecting ')'

From Dev

mismatched input '.' in rule

From Dev

Solving ambiguous input: mismatched input

From Dev

Antlr4: line 1:14 extraneous input 'w' expecting {<EOF>, ';', ' '}

From Dev

Jython @property SyntaxError: mismatched input '' expecting CLASS

From Dev

Drools decision table, "mismatched input '>' in rule "

From Dev

Why am I getting mismatched input?

From Dev

Handling EOF in user input

From Dev

Antlr Extraneous Input