文件中的 Antlr 令牌
向 Antlr 提供大量代币的最佳方式是什么? 假设我们有 100,000 个英语动词的列表,我们如何将它们添加到我们的语法中?我们当然可以包含一个像 verbs.g 这样的巨大语法文件,但也许有一种更优雅的方法,通过修改 .token 文件等?
grammar verbs;
VERBS:
'eat' |
'drink' |
'sit' |
...
...
| 'sleep'
;
标记还应该是词法分析器或解析器标记,即 VERBS: 或 verbs: ?可能是动词:。
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:.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我宁愿使用语义谓词。
为此,您必须定义一个标记
,并在每个要使用动词(而不是通用单词)的站点上放置一个语义谓词来检查解析的单词是否在动词列表中。
使用建议不要使用解析器/词法分析器来执行此类任务
I rather would use semantic predicates.
For this you have to define a token
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