score:1

Accepted answer

change syntax like this.

grammar hello;
r         : (statement ';')+ ;         
statement : decl | init ;
decl      : 'int' id  ; 
init      : decl '=' numexpr ;
numexpr   : number op number | number ;
op        : '+' | '-' | '/' | '*' ; 
ws        : [ \t\r\n\u000c]+ -> skip ;
number    : [0-9]+ ;
id        : [a-za-z]+ ; 

enter image description here

score:0

after looking at the documentation on antlr4, it seems like you have to have a specification for all of the character combinations that you expect to see in your file, from start to finish - not just those that you want to handle.

in that regards, it's expected that you would have to explicitly state the whitespace, with something like:

ws : [ \t\r\n]+ -> skip;

that's why the skip command exists:

a 'skip' command tells the lexer to get another token and throw out the current text.

though note that sometimes this can cause a little trouble such as in this post.


Related Query

More Query from same tag