antlr4 - ANTLR - how to skip missing tokens in a 'for' loop -
i'm developing 'toy' language learn antlr. my construct for loop this. for(4,10){ //program expressions }; i have grammar think works, it's little ugly. i'm not sure i've handled semantically unimportant tokens well. for example, comma in middle there appears token, it's unimportant parser, needs 2 , 3 loop bounds. means when see child() elements parts of loop token, have skip unimportant ones. you can see best if examine antlr viewer , @ parse tree this. red arrows point tokens think redundant. feel should making more use of skip() feature am, can't see how insert grammar tokens @ level. loop: 'for(' foridxitem ',' foridxitem '){' (programexpression)+ '}'; foridxitem: num #forindexnumÌ | var #forindexvar; the short answer antlr produces parse-tree, there cruft step on or otherwise ignore when walking tree. the longer answer there tension between skip...