[antlr-interest] labels and return types - multiple elements sharing label name
mb.fgel at ownit.nu
Tue Oct 30 15:02:46 PDT 2007
When I read 'Migrating from ANTLR 2 to ANTLR 3' I was soo happy to see that I can now have multiple elements sharing the same label name, so I removed all my temporary variables.
However, this seems to be true only when the label is set on a token, not when it is set on a parser rule, because all parser rules get their own return types. The reason for this is probably to support multiple return values.
In my case I know that all the return types are identical, so is there a way to specify which return type ANTLR should
generate for a rule? (Note: I'm talking of Java return types here, not return types within the grammar. This can be a bit confusing...)
If that's not possible, is there a way to set the type of the label to ParserRuleReturnScope (and thus be a legal variable for all the return types, as they all extend ParserRuleReturnScope), which would work just as well in my scenario?
Or, will I have to reintroduce all my temporary variables? :-(
(When I started, the labeled elements were indeed tokens, but I had too many such tokens (keywords), so I had to move them to the parser, and in all other aspects I think that was a good move.)
(I found a similar question in the archive, but there was no reply, so I try again.)
More information about the antlr-interest