4
votes

How can I debug/trace/dump the paths the ANTLR4-generated lexer chooses? Many times I am out of luck to see in the grammar itself what went wrong.

2

2 Answers

4
votes

You can use ANTLRWorks. Under run -> Interpret lexer you can see the output for the lexer grammar. Maybe also click Window -> Lexer debugger Controller window, if it's not automatically displayed. Under it, you can see types, tokens, channels, modes, lookahead. Tokens are quite useful to see which "string" was recognized as which token. Also, if I have lexer modes I always use antlrworks.

enter image description here

enter image description here

2
votes

The Intellij ANTLR plugin is very good for debugging ANTLR grammars. See https://stackoverflow.com/a/53130989/721855