[antlr-interest] ANTLR and guarded predicates

David Wigg wiggjd at sbu.ac.uk
Wed Mar 20 09:41:44 PST 2002

We are trying to convert a grammar file written for PCCTS to use with
ANTLR to produce C++ code (so that all our own embedded code can stay in

We appear to find that guarded predicates do not actually work in the
same way in PCCTS and ANTLR which is causing us grief as we cannot find
an easy way round the problem.

We refer to the paper "ANTLR 2 Meta-Language" which implies that if we

production: (syntax guard)=>{semantic test}? another_production
          | some_other_production

that the syntax guard will be tested first and if true then the semantic
test second. In fact our experience is the reverse and this is not
necessarily the required result because the semantic test may only be
appropriate for the actual syntax guarded. If the semantic test is
selected first before the syntax guard and the semantic test is
inappropriate for the syntax guarded then the result will be wrong.

Please could someone confirm or otherwise our understanding of what
happens in practice (as seen in a specific case) and if we are correct
could someone explain how we might obtain the operation we require that
the semantic test is only carried out for the correct tokens (in the
syntax guard)?

Ideally, of course, we would prefer the actual code to be performed in
the same sequence as shown in the documentation i.e. guard first,
semantic test afterwards. Could this be possible?


David Wigg
South Bank University
London, UK.


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list