什么 - >运算符在ANTLR3中意味着什么?(What does -> operator mean in ANTLR3?)

我正在尝试编译语法并使其在ANTLR4中运行。 语法是为ANTLR3编写的,我收到了很多编译错误。 这是其中之一:

syntax error: '->' came as a complete surprise to me while looking for rule element

这是导致错误的规则

tokens { ZONE; ZONE_OFFSET; } time_zone_abbreviation : UTC -> ZONE["UTC"] | EST -> ZONE["America/New_York"] | CST -> ZONE["America/Chicago"] | PST -> ZONE["America/Los_Angeles"] | MST -> ZONE["America/Denver"] | AKST -> ZONE["America/Anchorage"] | HAST -> ZONE["Pacific/Honolulu"] ;

我知道->运算符可用于在ANTLR4中指定lexer命令。 但是运营商在ANTLR3中的含义是什么?

I'm trying to compile a grammar and get it works in ANTLR4. The grammar was written for ANTLR3 and I'm getting a lot of compilation errors. Here is one of them:

syntax error: '->' came as a complete surprise to me while looking for rule element

This is the rule causing the error

tokens { ZONE; ZONE_OFFSET; } time_zone_abbreviation : UTC -> ZONE["UTC"] | EST -> ZONE["America/New_York"] | CST -> ZONE["America/Chicago"] | PST -> ZONE["America/Los_Angeles"] | MST -> ZONE["America/Denver"] | AKST -> ZONE["America/Anchorage"] | HAST -> ZONE["Pacific/Honolulu"] ;

I know the -> operator can be used to specify lexer command in ANTLR4. But what does the operator mean in ANTLR3?

最满意答案

在解析器规则内部, ->表示ANTLR 3中的重写规则,该规则从解析器规则构造AST。 更多关于此问答的内容: 如何输出使用ANTLR构建的AST?

在ANTLR 4中, ->仅用于词法规则,以将某些令牌放在不同的通道上(或者从令牌流中将它们全部跳过)。 由于ANTLR 4不适用于AST ,因此->不再具有等价物。 将ANTLR v3语法翻译成v4语法时,只需删除->及其右侧的所有内容即可。

Inside parser rules, the -> denotes a rewrite rule in ANTLR 3 that constructs an AST from the parser rule. More about this in this Q&A: How to output the AST built using ANTLR?

In ANTLR 4, the -> is only used in lexer rules to put certain tokens on a different channel (or skip them all together from the token stream). Since ANTLR 4 does not work with AST's, the -> no longer has an equivalent. When translating an ANTLR v3 grammar to a v4 grammar, simply remove the -> and everything on the right hand side of it.

什么 - >运算符在ANTLR3中意味着什么?(What does -> operator mean in ANTLR3?)

我正在尝试编译语法并使其在ANTLR4中运行。 语法是为ANTLR3编写的,我收到了很多编译错误。 这是其中之一:

syntax error: '->' came as a complete surprise to me while looking for rule element

这是导致错误的规则

tokens { ZONE; ZONE_OFFSET; } time_zone_abbreviation : UTC -> ZONE["UTC"] | EST -> ZONE["America/New_York"] | CST -> ZONE["America/Chicago"] | PST -> ZONE["America/Los_Angeles"] | MST -> ZONE["America/Denver"] | AKST -> ZONE["America/Anchorage"] | HAST -> ZONE["Pacific/Honolulu"] ;

我知道->运算符可用于在ANTLR4中指定lexer命令。 但是运营商在ANTLR3中的含义是什么?

I'm trying to compile a grammar and get it works in ANTLR4. The grammar was written for ANTLR3 and I'm getting a lot of compilation errors. Here is one of them:

syntax error: '->' came as a complete surprise to me while looking for rule element

This is the rule causing the error

tokens { ZONE; ZONE_OFFSET; } time_zone_abbreviation : UTC -> ZONE["UTC"] | EST -> ZONE["America/New_York"] | CST -> ZONE["America/Chicago"] | PST -> ZONE["America/Los_Angeles"] | MST -> ZONE["America/Denver"] | AKST -> ZONE["America/Anchorage"] | HAST -> ZONE["Pacific/Honolulu"] ;

I know the -> operator can be used to specify lexer command in ANTLR4. But what does the operator mean in ANTLR3?

最满意答案

在解析器规则内部, ->表示ANTLR 3中的重写规则,该规则从解析器规则构造AST。 更多关于此问答的内容: 如何输出使用ANTLR构建的AST?

在ANTLR 4中, ->仅用于词法规则,以将某些令牌放在不同的通道上(或者从令牌流中将它们全部跳过)。 由于ANTLR 4不适用于AST ,因此->不再具有等价物。 将ANTLR v3语法翻译成v4语法时,只需删除->及其右侧的所有内容即可。

Inside parser rules, the -> denotes a rewrite rule in ANTLR 3 that constructs an AST from the parser rule. More about this in this Q&A: How to output the AST built using ANTLR?

In ANTLR 4, the -> is only used in lexer rules to put certain tokens on a different channel (or skip them all together from the token stream). Since ANTLR 4 does not work with AST's, the -> no longer has an equivalent. When translating an ANTLR v3 grammar to a v4 grammar, simply remove the -> and everything on the right hand side of it.