How can I handle languages where keywords can also be identifiers?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Steve_Eckmann
Posted On:   Sunday, April 29, 2001 11:59 AM

The FAQ includes an answer by Monty Zukowski to the subject question.
Since my language has only about 10 keywords, I'm interested in the
alternative approach he alludes to in that answer: write a rule that
contains _all_ of the literals in it. I guess I'm not clever enough to
do it, though. Will someone please sketch this alternative approach
for me?

Re: How can I handle languages where keywords can also be identifiers?

Posted By:   Monty_Zukowski  
Posted On:   Tuesday, May 1, 2001 06:59 AM

Here's what I did in my AREV parser.


literalID
: d:("function"
| "select"
| "lt"
| "delete"
| "osdelete"
| "null"
| "loop"
| "on"
| "off"
| "clearselect"
| "clearfile"
| "flush"
| "readnext"
| "data"
)
{#literalID.setType(ID);
}
;



id: d:literalID
| ID
;



Then when you use these rules you have to be aware of antlr's ambiguity warnings, and use syntactic predicates when necessary. I don't have any simple examples from my AREV grammar, so post your own example if you run into trouble and I'll help fix it.
About | Sitemap | Contact