antlr2 구문으로 작성된 문법 파일이 있고 antlr4 구문의 일부 파서 규칙을 다시 작성하는 방법을 이해하는 데 도움이 필요합니다. 나는 antlr4가 대서양 횡단 (AST) 구축의 필요성을 제거 했으므로 어떤 규칙을 해야할지 잘 모르겠다는 것을 알고있다. 대서양 첩보원 번역. ANTLR Tree Construction은 구문의 일부와 # 구조를 사용하는 방법을 설명하지만이 규칙을 읽고 다시 작성하는 방법을 여전히 확신 할 수 없습니다.ANTLR4에 대한 AST 작업 변환 다시 작성
temp_root :
temp { #temp_root = #([ROOT, "root"], #temp_root); } EOF;
temp :
c:temp_content
{ #temp = #(#([FUNCTION_CALL, "template"], #template), c);
reparent((MyAST)#temp, MyAST)#c); };
temp_content :
(foo | bar);
foo :
{
StringBuilder result = new StringBuilder("");
}
: (c:FOO! { result.append(c.getText()); })+
{ #foo = #([TEMPLATE_STRING_LITERAL, result.toString()], #foo); };
bar :
BEGIN_BAR! expr END_BAR!
exception
catch [Exception x] {
bar_AST = handleException(x);
};
각 '#'은 노드에 "하위 트리"가 있어야 함을 나타냅니다. – Raven