Maybe you can use a setter to set what 'ifKeyword' is and use that in a
semantic predicate.
Something like:
@members {
String ifKeyword;
Public void setIfKeyword(String str) {
this.ifKeyword = str;
}
}
ifKeyword
: { LT(1).getText().equals(ifKeyword) }?=> /*nothing*/
;
Lexer will lex 'if' as just an ID.
Hope that helps.
Cheers, Indhu
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Heiko Folkerts
Sent: Monday, August 17, 2009 3:34 PM
To: [email protected]
Subject: [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
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
-~----------~----~----~----~------~----~------~--~---