antlr - ANTLR4 parsing error: no viable alternative at input -


i have grammar erroneous parsing simple file generates strange error messages.

i simplified following grammar as without altering error (if remove 'this' tree gui output of antlrworks colors token int of sample file differently although structure seems equal).

grammar depclsj_no_java_debug;  module   : ( methoddecl )* ;  methoddecl   : pathtype identifier '()' block ;  pathtype   : identifier | 'this' ;  block   : '{'     ( localdecl ';'  )*     ( statement  )*     ( expr  )?     '}'   ;  localdecl   : pathtype identifier ( '=' expr )?;  statement   : block | expr ';' ;  expr   : dotexpr ( '=' dotexpr  )* ;    dotexpr   : identifier ( '.' identifier )* ;  identifier   : ('a'..'z'|'a'..'z'|'_') ('a'..'z'|'a'..'z'|'0'..'9'|'_')* ; 

demo code:

void main() {     = c;     int b; } 

antlrworks 2 gives me following error messages:

line 3:8 no viable alternative @ input 'intb' line 3:9 mismatched input ';' expecting '()' 

int b; localdecl, according block rule in grammar cannot appear after first statement. if had instead relaxed grammar using following, have used parse tree listener produce meaningful error message after parse completed successfully.

block   : '{'     (localdecl ';' | statement)*     expr?     '}'   ; 

Comments

Popular posts from this blog

Line ending issue with Mercurial or Visual Studio -

python - Received unregistered task using Celery with Django -

c# - Delving into the world of XML (Windows Phone) Error I dont understand (The ' ' character, hexadecimal value 0x20, cannot be included in a name.) -