[antlr-interest] Using predicates for keywords

Heiko Folkerts Heiko.Folkerts at david-bs.de
Mon Aug 17 03:04:20 PDT 2009


Hi,
I want to use an abstract syntax in wich the keyword e.g. for an if statement is available at runtime with a database call. So I don't want to hard code 'if' in the parser but use an expression for a ifkeyword which checks the database and returns wether the token is an if keyword or not.

I've tried with syntactic and semantic predicates, but even after reading the sections from the antlr reference I don't know which way is the right one for me.

The grammar would like something like this:
Statement:
Ifexpresseion
| loopexpression
;

Ifexpression: ifkeyword condition thenkeyword actionexpression;
Loopexpression: loopkeyword condition ':' actionexpression;

So how to code the ifkeyword and loopkeyword rules?

Thx in advance.
Btw.: thx to Jim for the help compiling the generated C code.

Mit freundlichem Gruß
Heiko Folkerts
Systementwicklung und -design
--
______________________________________________
DAVID GmbH · Wendenring 1 · 38114 Braunschweig
Tel.: +49 531 24379-14
Fax.: +49 531 24379-79
E-Mail: mailto:Heiko.Folkerts at david-bs.de
WWW:   http://www.david-bs.de 
Eintragung: Amtsgericht Braunschweig, HRB 3167
Geschäftsführer: Frank Ptok
______________________________________________

 


More information about the antlr-interest mailing list