After some wrestling with the templates I have found a way to preserve the tree 
rewriting semantics but allow a more C like behavior for grammars whereby if 
the grammar programmer does not initialize a return value from a rule, then it 
is just left as it would be in C, being uninitialized and therefore likely to 
be garbage.

 

While this may break backwards compatibility (and so I will emphasize this in 
the release notes), it seems better to behave like C than Java in this respect. 
Because I am able to preserve the tree rewriting semantics, I feel that those 
few affected by this will agree that not initializing return values without 
being told to makes more sense in the long run.

 

So, the ways to initialize parameters are:

 

r returns [enum FRED = FRED_VAL1]

 : ... ;

 

And the initialization will be generated for you. Or you can place 
initialization in the @init section of a rule, or otherwise initialize via 
actions. Note all the same rules apply about @after vs @finally vs exception 
code (see Markmail search if you don't remember seeing that email - will 
document for next release).

 

I think that should keep just about everyone happy. Please remember though that 
the C rules return a struct unless there is only one return parameter and no 
tree nodes are being generated. This limits some of the things that you can 
declare as return types. Also, because there are some limitations in the 
generic parsing of the return element specs, it is quite often desirable to 
make a typedef of a complex declaration. Finally, passing things around in a 
parser instead of waiting for a tree parse is not generally a good idea anyway, 
because of the complications of freeing things if you hit a parsing error.

 

Jim



--

You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to