ANTLR中自动生成的DFA字符串,例如eotS、eofS、acceptS是什么意思以及它们是如何生成的
当我从语法文件中使用 antlr 生成词法分析器时,我注意到它生成了一系列十六进制格式的字符串。
DFA 使用这些字符串来预测下一个标记是什么。
这些字符串的含义是什么以及它们是如何生成的。
我引用的字符串出现在生成的词法分析器中,如下所示(aand 被传递给构造函数中的 DFA):
static final String DFA1_eotS = ....
static final String DFA1_eofS = ....
static final String DFA1_minS = ....
static final String DFA1_maxS = ....
static final String DFA1_acceptS = ....
static final String DFA1_specialS = ....
static final String[] DFA1_transitionS = ....
编辑:
我将开始回答自己的问题以让我们开始
接受S[i] = 包含可能的标识符的数组令牌(我不知道为什么它包含许多-1值)
When I generate a lexer with antlr from a grammer file I notice it generates a series of strings in hex format.
These strings are utilised by the DFA to predict what tokens my be next.
What do these strings mean and how are they generated.
the strings I am referreing to appear in the generated lexer like this (aand are passed to the DFA in the constructor):
static final String DFA1_eotS = ....
static final String DFA1_eofS = ....
static final String DFA1_minS = ....
static final String DFA1_maxS = ....
static final String DFA1_acceptS = ....
static final String DFA1_specialS = ....
static final String[] DFA1_transitionS = ....
Edit:
I will begin answering by own question to get us started
acceptS[i] = an array containing an identifier for possible tokens (I don't know why it contains many -1 values)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DFA_minS、DFA_maxS 我认为指的是当它在状态表
DFA_transitionS中移动时可以落在之间的字符范围。我认为状态表
DFA_specialsS 我认为与将语义谓词添加到规则有关,并且
DFA_acceptS 似乎是开关中指定哪个的 case 值集令牌正在被 DFA 接受
注意:我仍然想知道这些是否正确以及它们是如何生成的
DFA_minS, DFA_maxS I think refers to range of chars it can fall between as it moves through the state table
DFA_transitionS. I think is the state table
DFA_specialsS I think is something to do with adding the semanticet predicates to the rules and
DFA_acceptS seems to be the set of case values in a switch specifying which token is being accepted by the DFA
Note: I still would like to know if these are correct and how they are generated