I'm working on the lexer for a language which allows abbreviated keywords Any suggestions for handling this in ANTLR's lexer?

Monty Zukowski

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; 
        } 
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact