jGuru
Register Email     Password Forgot your
password?
HOME FAQS FORUMS DOWNLOADS ARTICLES PEERSCOPE LEARN

  Search   jGuru Search Help

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

Comment on this FAQ entry

There are currently no comments

Ask A Question



 
Related Links

ANTLR FAQ

ANTLR Forum

Download now!

Resources

Documentation

Book in progress

ANTLR Consulting

Wish List
Features
About jGuru
Contact Us

 



The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers