antlr3 - Parsing ANTLRv3 tree doent not produce full tree -
i'm using antlrv3. i've defined grammar. want display parse tree (like in antlrworks parse tree or stack). i've tried http://www.antlr.org/wiki/display/antlr3/interfacing+ast+with+java (walking throuht children) ommits clauses in grammar not appear in parsing string.
eg. have sql grammar. i'm parsing select title,description document . in antlrworks can see(in parse tree) root_statement->select_statement->select_expression->select_list->[displayed_column,displayed_colulmn] want.
but when ast tree root_statement (through getchildren) don't select_statement, select_expression. children string "select title,description document".
how can throught tree in same way in antlv4? (root_statement.select_statemet.select_expression)
antlr 3 builds asts custom shape defined special syntax in grammar (operators ^, !, , ->). antlr 4 builds parse trees automatically follow shape of grammar itself.
to make antlr 3 behave antlr 4, you'd need create rewrite rules every parser rule in grammar root node has name of rule itself. example:
myparserrule : x y* -> ^(myparserrule x y*) | z+ -> ^(myparserrule z+) ; as other direction, there isn't "easy" way make antlr 4 behave antlr 3.
Comments
Post a Comment