[antlr-interest] C++ compliance of antlr generated code
Kay Roepke
kroepke at classdump.org
Mon Jan 1 08:11:13 PST 2007
Happy New Year :)
On 31. Dec 2006, at 14:59 , Maurizio de Pascale wrote:
> I've read the old post you pointed to, and I agree this is not a
> bug/issue, but the real (still to be answered) question is:
> Is there a good reason to keep in ANTLR3 C++ generated code
> variables starting with '_' ?
> Why is _ttype better than ttype, tokenType, token_type, or whatever
> one can choose?
The reason why we have switched to the '_' prefix is that we want to
force people to use the $label syntax in actions.
For example the usual action to change the token channel is
WS: ' '|'\t'|'\r'|'\n' { $channel = HIDDEN; } // $channel = 99 as it
used to be
The actual variable is called _channel and not channel. By forcing
people to use $channel or $label we have the chance
to validate access and rewrite it if necessary. Thus changes to the
internal structure don't require people to
change their grammar's actions. In other words, we wanted to have a
way to hide the implementation.
Just as programmers using '_' identifiers in C++ and other languages
know that they are treading on unsteady ground,
it is the same with ANTLR. If you access something which hasn't a '$'
prefix, you better have a very good reason for it,
because it might be totally different in the next version. Using
$label will always work, no matter what the actual variable
is named. Obviously this is different for custom members you defined...
> P.S. is ANTLR3 C++ target complete?
No, it isn't AFAIK. I haven't heard anything on Ric's progress lately
so it seems he's incredibly busy with other things.
I have no idea what his timescale is.
At the current time the only thing that's "complete" is the Java
target, naturally. Jim and I are busy picking up the
latest changes Ter has made, Jim for the C target and myself for the
Objective-C target.
What the state is for C#, I don't know, but it should be pretty far
along as well.
I think Benjamin Niemann has recently started working on a Python
target.
There's been work for Ruby by Martin Traverso, but I'm not sure how
far along he is, either.
The other targets are pretty much non-existent at the moment.
I'm pretty sure that Ric would be delighted if someone steps up to
help with the C++ target. ;)
cheers!
-k
--
Kay Röpke
http://classdump.org/
More information about the antlr-interest
mailing list