[antlr-interest] predicate question

Gavin Lambert antlr at mirality.co.nz
Tue May 6 13:24:16 PDT 2008


At 00:46 7/05/2008, Mark Wright wrote:
 >Which is fine if you are lucky enough to be parsing a context 
free
 >language that does not need dis-ambiguating semantic predicates.

True, but since I mostly only work with small DSLs I have the 
luxury of changing the language if it becomes difficult to parse 
:)

 >> For example, what about this case:
 >>    rule: A {bar();} b=B ({foo($b)}? C D)? E;
[...]
 >Likewise for foo() needing to look at B:
 >
 >- An action could be introduced after consuming token B to store
 >information about B in the symbol table, then foo() could look
 >up the information about B in the symbol table.
 >
 >- foo() could scan backwards looking for B.
 >
 >- An action could be introduced after consuming token B to store
 >information about B in the symbol table, and a pointer to the
 >symbol table information could be stored in token B.  Then foo()
 >foo() could scan backwards looking for B.

I don't think that will work, since if foo() is hoisted then B 
will not yet have been consumed, and may be arbitrarily far ahead 
in the input stream (depends on how far it got hoisted).

Mind you, it's possible ANTLR avoids this by not hoisting this 
kind of predicate at all.  As I said, this was a bit of a 
contrived example and I'm not entirely sure how ANTLR reacts to it.



More information about the antlr-interest mailing list