[antlr-interest] Keywords can appear in expressions

Peggy Fieland madcapmaggie at yahoo.com
Thu Jan 5 07:01:23 PST 2006


The way that has worked best for me is to enumerate
the keywords that can appear as identifiers:

non_keywords: "OPERATION;

object_name: identifier | non_keywords
;

I finally ended up writing myself a small generator
program that works off of an array of "real" keywords
and generates two rules:

keywords: "REAL_KEYWORD1" | "REAL_KEYWORD2"   (etc)
non_keywords: "CAN_APPEAR_AS_IDENTIFIER1" |
"CAN_APPEAR_AS_IDENTIFIER2" 
  (etc)

The program works off of an array of what the manual
told me were the "real" keywords and takes as input
the ...ParserTokenTypes.txt file
which it uses to generate the two rules (into separate
files, which I 
then merge into the parser by hand).

 I'm working on parsers for several SQL dialects and
as the language we support keeps changing (and as we
find bugs) we update the parsers.  I've had to modify
the "real_keywords" list but the whole thing works
well and is easy to maintain.


Peggy

--- Dimitrios Kolovos <dskolovos at gmail.com> wrote:

> Hi,
> 
> In my language some keywords can also appear in
> expressions e.g.
> 
> *operation* doSomething() {}
> 
> and
> 
> object.operation.name;
> 
> When I declare the "operation" keyword like that,
> 
> OPERATION : "operation";
> 
> it is recognized as keyword in the second case as
> well.
> 
> What I think might work is to declare OPERATION as
> (' ' | '\t' | '\n') 
> "operation" (' ' | '\t' | '\n') but I don't want
> characters before or 
> after "operation" to be consumed. Any ideas on how
> to do this?
> 
> Cheers,
> Dimitrios
> 



More information about the antlr-interest mailing list