Catching ANTLR's NoViableAltException in Java and ANTLRWorks Debugger

前端 未结 2 2075
悲哀的现实
悲哀的现实 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 : . ;
    
    0 讨论(0)
  • 2021-01-14 22:42

    Well, this answer given by 280Z28 to my second part of this question solves both problems well. So, this is the proper answer.

    0 讨论(0)
提交回复
热议问题