i converting antlr3 grammar antlr4 grammar, means had remove tree rewriting rules because have implemented in code , visiting parsetree with custom visitor it's possible generate ast.
the old grammar had rewrite rules prevented ambiguities , automatically generated wanted tree. couldn't find useful resource online showing how can done visitor/listener paradigm.
- a
visitorneeds type used return typevisit*functions. if need generate ast, return type should use? antlr3 usedcommontreeobjects. - when entering
visit*node, can create node of tree, how should track parent node? - is there example on how convert tree rewrite rule method generating node of ast? if not, possible have example rule 1 below?
here rule (3):
ctor_initializer: '::'? identifier '(' expr? ')' -> ^(ctor_initializer^(initializer_id '::'? identifier) ^(ctor_expr expr?) );
idiomatically, antlr4 creates , supports use of parse-trees. there no direct support creating , modifying asts.
some of motivating factors preferring parse-trees on asts summarized here.
antlr4 not preclude constructing asts -- structure can defined in manner desired. examples here , here.
Comments
Post a Comment