[antlr-interest] Defining keywords with varying length
Martin Probst
mail at martin-probst.com
Tue Nov 29 02:15:36 PST 2005
Well, you can have a rule:
tokens {
LIBRARY,
FOO,
BAR
}
KEYWORD {
}:
('a'..'z'|'A'..'Z')+
{ $setType(myKeywords.lookup($getText()));
/* LIBRARY for "LIB", "LIBR" etc., FOO for "foo", ... */ }
And then you'd have to maintain a structure myKeywords which maps from
word-start to token types. You'd probably want to use a TRIE for that.
Martin
More information about the antlr-interest
mailing list