|
Question
|
I'm working on the lexer for a language which allows abbreviated keywords (ex: "display" "disp" "displ" and "displa" are all treated as "display"). Any suggestions for handling this in ANTLR's lexer?
|
|
Topics
|
Tools:ANTLR:Recognition:Lexical analysis
|
|
Author
|
Monty Zukowski PREMIUM
|
|
Created
|
Oct 26, 2000
|
Modified
|
Oct 31, 2000
|
|
Answer
There is a method called testLiteralsTable() which looks in the "literals" Hashtable to match keywords. Override that for the behavior you want.
// Test the token text against the literals table
// Override this method to perform a different literals test
public int testLiteralsTable(int ttype) {
hashString.setBuffer(text.getBuffer(), text.length());
Integer literalsIndex = (Integer)literals.get(hashString);
if (literalsIndex != null) {
ttype = literalsIndex.intValue();
}
return ttype;
}
Is this item
helpful? yes no
Previous votes Yes: 0 No: 1
|
|
Comments and alternative answers
There are currently no comments
|
|
 |
|