What is the best way to feed Antlr with huge numbers of tokens? Say we have a list of 100,000 English verbs, how could we add them to our grammar? We could of cause include a huge grammar file like verbs.g, but maybe there is a more elegant way, by modifying a .token file etc?
grammar verbs;
VERBS:
'eat' |
'drink' |
'sit' |
...
...
| 'sleep'
;
Also should the tokens rather be lexer or parser tokens, ie VERBS: or verbs: ? Probably VERBS:.
I rather would use semantic predicates.
For this you have to define a token
word : [a-z]+
and at every site you want to use a verb (instead of a generic word) put a semantic predicate that checks if the parsed word is in the list of verbs.
Using recommend not to use the parser/lexer for such a task
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With