Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下 ANTLR 规则:
procedure : ('int' | 'char') IDENT '(' args ')' body -> ^(PROCEDURE IDENT (args)* body) ;
我想捕获('int' | 'char')AST 中的部分。如您所见,在右侧它没有出现,但我不确定如何选择'int'或'char'出现在 AST 中。我希望'int'or 'char'部分位于根下的树中,PROCEDURE但在IDENT.
('int' | 'char')
'int'
'char'
char'
PROCEDURE
IDENT
您可以标记该对,然后在重写中引用该标签:
procedure : primType=('int' | 'char') IDENT '(' args ')' body -> ^(PROCEDURE $primType IDENT args body) ;