[antlr-interest] Antwort: Using predicates for keywords

lars.vonwedel at bayertechnology.com lars.vonwedel at bayertechnology.com
Mon Aug 17 04:49:16 PDT 2009


Hello,

I would suggest to look into the solution for abbreviated keywords, which 
could work out here as well, if I correctly understand your concern.

You could realize a generic lexer rule for identifier. Code associated 
with that rule could look into the database and obtain the correct token 
id depending on the content (text) of the identifier matched by the lexer. 
The parser would then only work with token IDs and look like a "normal" 
Antlr grammar without lots of predicates.

Freundliche Grüße / Best Regards
Lars von Wedel
_________________________________________

Bayer Technology Services GmbH
BTS-PT-PD-ES
Leverkusen, E 41
Phone: +49 214 30 56456
Fax: +49 214 30 62677
E-mail: lars.vonwedel at bayertechnology.com
Web: www.bayertechnology.com

Geschäftsführer: Achim Noack
Aufsichtsratsvorsitzender: Dr. Wolfgang Plischke
Sitz der Gesellschaft: Leverkusen   |   Eintragung: Amtsgericht Köln, HRB 
49896




"Heiko Folkerts" <Heiko.Folkerts at david-bs.de> 
Gesendet von: antlr-interest-bounces at antlr.org
17.08.2009 12:04

An
<antlr-interest at antlr.org>
Kopie

Thema
[antlr-interest] Using predicates for keywords






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
______________________________________________

 

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090817/1aa10286/attachment.html 


More information about the antlr-interest mailing list