[antlr-interest] ANTLR and guarded predicates

mzukowski at bco.com mzukowski at bco.com
Wed Mar 20 10:06:10 PST 2002

I don't have time to look into why it's not working right now, but you could
certainly get by with a subrule:

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

Also note that PCCTS properly hoisted predicates into calling rules.  ANTLR
does not, you will have to manually hoist the rule yourself, like I did with
the typedef rule in the GCC grammar.


> -----Original Message-----
> From: David Wigg [mailto:wiggjd at sbu.ac.uk]
> Sent: Wednesday, March 20, 2002 9:42 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] ANTLR and guarded predicates
> 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
> C/C++).
> 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
> have
> 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?
> Thanks.
> David Wigg
> South Bank University
> London, UK.
> Your use of Yahoo! Groups is subject to 


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

More information about the antlr-interest mailing list