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

Pille

The following grammar does not work properly with Antlr4.5 and Java 1.8.45 (IDE: IntelliJ Ultimate 14.1.4):

grammar PlayerAIShots;
file : row row EOF ;
row : START (randomshot)? SPACE direction Dot (LineBreak | EOF);

randomshot: RANDOM ;
direction : DIRECTION ;

RANDOM : 'randomly' ;
DIRECTION : ('to the left'|'to the right'|'central') ;
START : 'The opponent shoots' ;
SPACE : ' ' ;
Dot : '.' ;

// line break
LineBreak : '\r'?'\n' | '\r';

WS : [\t\r\n]+ -> skip ; // skip tabs, newlines

Letting the generated lexer and parser being evaluated results to:

line 1:22 mismatched input 'randomly' expecting DIRECTION

In the used data (text file) the second line was properly processed, but as in the above stated error message not the first one. Here is the text file being used:

The opponent shoots randomly to the left.
The opponent shoots to the right. 

Removing those SPACE within the definition of "row" the error does not occur. Why?

janisz

First line of your input is wrong. You didn't specify that you require space between START and randomshot like this

row : START (SPACE randomshot)? SPACE direction Dot (LineBreak | EOF);

When you remove 'SPACE' from 'row' definition you will get even more errors

line 1:19 extraneous input ' ' expecting {'randomly', DIRECTION}
line 1:28 extraneous input ' ' expecting DIRECTION
line 2:19 extraneous input ' ' expecting {'randomly', DIRECTION}

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 Grammar line 1:6 mismatched input '<EOF>' expecting '.'

From Dev

Antlr : beginner 's mismatched input expecting ID

From Dev

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

From Dev

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

From Dev

ANTLR4 : mismatched input

From Dev

ANTLR Pattern "line 1:9 extraneous input ' ' expecting WORD"

From Dev

Bad Request: line 1:115 mismatched input ';' expecting K_VALUES in cassandra

From Dev

Antlr v4: 'mismatched input'

From Dev

Mismatched input ',' expecting ')'

From Dev

ANTLR mismatched input error

From Dev

ANTLR mismatched input '<EOF>'

From Dev

ANTLR mismatched input '<EOF>'

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

Antlr v4 Can I ignore mismatched input?

From Dev

Antlr v4 Can I ignore mismatched input?

From Dev

ANTLR4 Grammar extraneous / mismatched input error

From Dev

mismatched input in antlr generated parser

From Dev

FAILED: Parse Error: line 7:19 mismatched input '(' expecting FROM in from clause

From Dev

Jython @property SyntaxError: mismatched input '' expecting CLASS

From Dev

How to share values for different tokens - mismatched input 'COMMAND1' expecting FUNCTIONNAME2" -

From Dev

Antlr - mismatched input error - token not recognised

From Dev

Mismatched input 'STRING' expecting : near 'name' in column specification

From Dev

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

From Dev

Pig: Failed to parse: mismatched input 'id' expecting set null

From Dev

Xtext grammar : mismatched input '0' expecting RULE_INT

From Dev

Pig: Failed to parse: mismatched input 'id' expecting set null

Related Related

  1. 1

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

  2. 2

    Antlr : beginner 's mismatched input expecting ID

  3. 3

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

  4. 4

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

  5. 5

    ANTLR4 : mismatched input

  6. 6

    ANTLR Pattern "line 1:9 extraneous input ' ' expecting WORD"

  7. 7

    Bad Request: line 1:115 mismatched input ';' expecting K_VALUES in cassandra

  8. 8

    Antlr v4: 'mismatched input'

  9. 9

    Mismatched input ',' expecting ')'

  10. 10

    ANTLR mismatched input error

  11. 11

    ANTLR mismatched input '<EOF>'

  12. 12

    ANTLR mismatched input '<EOF>'

  13. 13

    ANTLR 4.2.2: mismatched input

  14. 14

    ANTLR mismatched input error

  15. 15

    mismatched input ')' expecting EOF in CQL

  16. 16

    mismatched input ')' expecting EOF in CQL

  17. 17

    Antlr v4 Can I ignore mismatched input?

  18. 18

    Antlr v4 Can I ignore mismatched input?

  19. 19

    ANTLR4 Grammar extraneous / mismatched input error

  20. 20

    mismatched input in antlr generated parser

  21. 21

    FAILED: Parse Error: line 7:19 mismatched input '(' expecting FROM in from clause

  22. 22

    Jython @property SyntaxError: mismatched input '' expecting CLASS

  23. 23

    How to share values for different tokens - mismatched input 'COMMAND1' expecting FUNCTIONNAME2" -

  24. 24

    Antlr - mismatched input error - token not recognised

  25. 25

    Mismatched input 'STRING' expecting : near 'name' in column specification

  26. 26

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

  27. 27

    Pig: Failed to parse: mismatched input 'id' expecting set null

  28. 28

    Xtext grammar : mismatched input '0' expecting RULE_INT

  29. 29

    Pig: Failed to parse: mismatched input 'id' expecting set null

HotTag

Archive