[antlr-interest] C runtime: crash in dupNode; UP/DOWN/etc. missing factory?

Ned Gill thomas.gill at csr.com
Tue Jun 2 02:30:23 PDT 2009


On Mon, 01 Jun 2009 17:11:24 +0100, Jim Idle  
<jimi at temporal-wave.com> wrote:

> Ah, hang on. This is in the tree parser's error message routines. That
> means your tree parser is incorrect, or at least the input it is
> receiving has a mismatch.

This is in the recovery code rather than the error reporting, I think. In  
particular I am overriding displayRecognitionError. Should I think about  
overriding the recovery code too?

I think I'm abusing the token parser/tree parser split a little. My parser  
is part of an assembler for a rather intricate DSP instruction set.  
Naturally I've got to keep compatibility with the old assembler which had  
a buggy ad-hoc hand written parser. I started by using just a token  
parser, but I found that the amount of left-factoring required was  
completely prohibitive, even using syntactic predicates. I wanted to avoid  
global backtracking because I didn't have any confidence that I would be  
able to avoid ambiguity without the help of the parser.

My solution was to write a token parser matching a broad super-set of the  
language, generating trees. That grammar has a lot of left factoring, but  
because it's less strict it's much more managable. I could then arrange  
that the trees are parsable without significant amounts of left-factoring.

Which is all a long way of saying: I expect my tree parser to sometimes  
see invalid input, and I need to handle that.


> However, you are really expected to install your own error message
> display routines of course, so your fix for the moment is to make a
> copy of the tree parser displayRecognitionError, have it check that
> the token being duped to create the missing symbol has a tree factory
> and if it does not, then use LT(-2) etc

Would it be appropriate to modify getMissingSymbol to do something like  
that?


Thanks,
Ned.



More information about the antlr-interest mailing list