[antlr-interest] Semantik Predicates

Dagi.Troegner at dlr.de Dagi.Troegner at dlr.de
Sun Oct 24 08:23:52 PDT 2010


Hi,

I have a problem with using semantic predicates in my grammar. I have certain rules to identify simple, basic sentences of a natural language (English). In addition I want to restrict the language to a set of keywords. Those keywords are adaptively generated from an external c++ routine, meaning I cannot put them statically into my ANTLR code. Therefore, within one rule of my grammar, I'm comparing the actual token to an array of keywords. If a keyword is found, I'm setting an ANTLR variable to true. At the end of the rule it shall be evaluted if this varible is true and if so, the token shall be accepted. If the variable is false, it mustn't be accepted.

Here is the sample:
rule:    {C++ routine assigning value to $sentence::adjective_recognized}
           {$sentence::adjective_recognized}? ID ;

In my case $sentence::adjective_recognized is set to true when an adjective is found that is a keyword. The problem that I have is that the routine to set this variable is not evaluated at the beginning of the parsing. I have to initialize this variable to true in order to make the parser accept the whole sentence. If I'm initializing this variable to false the parser cannot map the input sentence to the grammar. I'm supposing the parser is trying to map the input sentence (look ahead)  in advance before actually going through all the rule actions? Is there a way to tell the parser to evaluate the variable i.e. my routine every time? Thank you very much for your help.

Yours, Dagi


More information about the antlr-interest mailing list