0
想象我有以下兩個語法:在ANTLR4中,我應該使用Token還是ParserRuleContext?
grammar Token;
rule : 'test' x=Identifier;
Identifier : [a-z]+;
grammar ParserRuleContext;
rule : 'test' x;
x : Identifier;
Identifier : [a-z]+;
在前者,我可以訪問「規則」作爲一個公共字段(類型令牌的價值)。在後者中,我將它作爲一個方法來訪問(值類型RuleContext擴展了ParserRuleContext)。最終結果是通過getText()獲取的,所以最終結果沒有區別。問題是我使用應該是,而爲什麼?