[antlr-interest] Re: Defining keywords with varying length

Susan Jolly easjolly at ix.netcom.com
Tue Nov 29 09:34:25 PST 2005


I'd make one modification to what Martin wrote.  Rather than using a TRIE,
I'd start with a simpler structure that is likely less efficient but
probably quicker to implement.

This would depend on the number of different minimal lengths of the unique
abbreviations. If there are only a few minimal lengths, say either 3
characters as for LIBRARY or 4 characters as for XXXY...., the structure
could be a simple hashtable with LIB and LIBR and XXXY (and the other 3 and
4 character starting strings) as the keys.  Then, if the user entry has more
than 4 characters, you would use its first four characters, rather than the
complete entry, to locate the full keyword.

You would then need to compare the complete user entry with relevant portion
of the full keyword to eliminate items like LIBRX. 

Susan





More information about the antlr-interest mailing list