I'd like to know how:
- return a runtime value from a rule action
- access that value from the parent rule's action.
With ANTLR I want to build a custom tree using actions (not listeners/visitors which are too complex). And I'd like to have a parser implementation where each action knows about its children but not about its parent.
It is possible to access parent action's $variables but instead I'd like to access runtime values returned from children (and I don't know how).
For example with Ruby's treetop
I can build a custom tree like below. Is this approach available for ANTLR too?
// sample input: "hello joe"
grammar Test
rule greeting
'hello' name {
// here `name.value` returns an instance of Name (below)
return new Greeting(name.value)
}
end
rule name
ID {
return new Name(ID.text)
}
end