Catching ANTLR's NoViableAltException in Java and ANTLRWorks Debugger

前端 未结 2 2074
悲哀的现实
悲哀的现实 2021-01-14 21:49

Consider we try to feed some incorrect input text to some grammar (e.g. text which contains some unknown token). In ANTLRWorks during interpretation we will see

2条回答
  •  星月不相逢
    2021-01-14 22:37

    You need to add the following as the very last rule in your lexer. It will create a token for the invalid character(s) and send it to the parser where the error will be properly reported.

    ANYCHAR : . ;
    

提交回复
热议问题