Catching errors in ANTLR and finding parent
Posted
by
Andreas
on Stack Overflow
See other posts from Stack Overflow
or by Andreas
Published on 2011-01-07T15:40:45Z
Indexed on
2011/01/07
16:53 UTC
Read the original article
Hit count: 248
I have found out that I can catch errors during parsing by overwriting displayRecognitionError, but how do I find the parent "node" of this error?
ex. if I have the grammar: prog: stat expr; stat: STRING; expr: INTEGER;
And give it the input "abc def".
Then I will get an error at "def" which should be an integer. At this point I then want to get the parent which is "expr" (since it fails inside the INTEGER part) and it's parent "prog". Kind of like printing stack trace in java.
I tried to look at the node from RecognitionException parsed to displayRecognitionError, but it is null, and using CommonErrorNode the parent is null.
Should I maybe take a completely different approach?
© Stack Overflow or respective owner