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: [email protected]
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" <[email protected]> 
Gesendet von: [email protected]
17.08.2009 12:04

An
<[email protected]>
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:[email protected]
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


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

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

Reply via email to