[antlr-interest] Reuse rule-return "shortcuts"
felix_do at web.de
Wed Apr 2 13:53:37 PDT 2008
Jim Idle wrote:
> the label is just that, a label named as per your choice, hence it is generated as a label in the target language, typed according to the rule name. Just as in say Java you cannot have both an int and a String called 'felix', you cannot use the same name on different rules as they have different return types and hence the variable types need to be different. If you want suffixes you must add them yourself. Just think of the labels as variable names and it should make sense to you.
Of course you are right with what you say - from your perspective.
Change it and consider the various alternatives of a rule like
"subfunctions" of which only one will be of importance, then, the scope
of that label is just the subfunction. Thus you could reuse the same
label within different alternatives,just like you can use "x" in foo()
and in bar(), which I find quite useful.
It's just that the rule is mapped to a single java method, so Antlr
would have to secretly make each label unique with a number suffix. A
similar Strategy is applied when you use $Node, which won't be just
"Node" in the code, but "NodeX".
Hope I could make myself clear.
More information about the antlr-interest