[antlr-interest] a few questions
Lloyd Dupont
lloyd at nova-mind.com
Mon May 30 17:52:51 PDT 2005
1st about lookahaed...
I have a big super grammar (the C grammar from ANTLR web site), which is uncorrectly implemented in some place
So I thought of culling out unworking keyword (namely __attribute__ & __inline__)(as they don't bother me too much) with something like
class ObjectiveCLexer extends GnuCLexer;
ID:
("__attribute__") => SKIP_ATTRIBUTE { $setType(Token.SKIP); }
| ( "__inline__") => "__inline__" { $setType(Token.SKIP); }
| // classical ID code
;
protected SKIP_ATTRIBUTE
: "__attribute__" (Whitespace)? LPAREN LPAREN ATTRIBUTE_PARAMS RPAREN RPAREN
;
protected ATTRIBUTE_PARAMS
: ( ~('(' | ')')
| LPAREN SKIP_ATTRIBUTE RPAREN
)*
;
It work's ok in most cases, excpet sometime I have ID like "__isacii" or "__inline__this_function_next" which confuse the lexer due to insuffisent lookahead.
I cannot override the symbol table (because it would require me to copy/paste all the class code, which I rather avoid), so I was thinking to put a lookahead of, let's say, 25 characters. what about that? any counter-indication?
2nd I have a problem with some unreservde keyword. something like that:
typeQualifier
: "const"
| "volatile"
// -- ObjectiveC addition --
| protocolQualifier
;
protocolQualifier
: "in"
| "out"
| "inout"
| "bycopy"
| "byref"
| "oneway"
;
these protocolQualifiers are not reserved word! so they could be used as variable name, for example like that:
struct MyStruct
{
int byref;
int out;
}
and because they are not ID they break my parsing of MyStruct..... any ideas?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050531/7a3df1e9/attachment-0001.html
More information about the antlr-interest
mailing list