[antlr-interest] On the guessing mode in C++

Ric Klaren klaren at cs.utwente.nl
Mon May 3 05:48:37 PDT 2004


Hi,

On Sat, May 01, 2004 at 12:23:27AM +0700, Andrey R. Urazov wrote:
> > It depends a bit where they get assigned. If you mean assignments to
> > return values inside the rule they should be returned from, those
> > don't happen (unless they're done in an init action) From the calling
> > rule the assignment is done. Due to the way antlr generates the return
> > value it's more or less an issue of initialization in the rule. Just
> > like plain old C garbage in garbage out. I'd rather not clutter the
> > codegen with if's for this (also I could think of things where you'd
> > want the return value (leaves a bit more room for cheating anltr with
> > initactions)).

> I see your point.

I see yours too :)

> But in my opinion allowing assignments in the calling rules in guessing
> mode is rather dangereous. First of all, because this does not have any
> clear semantics in general: what is the sense of assignment of a value
> whose computation was not triggered (except init actions)? 

The way antlr generates code it will always return something. So something
will get constructed if you're unlucky (and did not anticipate on it)

> Secondly, running assignment operators may have side effects
> which are inacceptable in guessing mode. User might want assignment
> operator of his own object to do anything, for instance, it might
> perform some registration of an object in a special object-directory and
> increment some counter. Surely, running this registration operation
> several times won't be desired.

You could wonder if you should be using such side effect containing objects
in a part of the parser where you're still using guessing mode. E.g. one or
two tree transformations away you can do it in one go without having to use
predicates. (Apart from the discussion if it's a good idea to have too many
side effects in operators, but that's nitpicking ;) )

> In my humble opinion it's better if such semantically dubious situations
> are prohibited. At least I would like a program I use to run in the safe
> mode by default. And for users who do know what they are doing there
> might be a special loose mode.

It could be good yes. But it might be an attempt to overengineer. The user
is usually a pure genious when it comes to finding a way to use a tool in a
way that it was never intended ;)

Well enough 'shoddy' arguments against it, I peeked at the codegen a bit
and I'm not seeing a way to implement this is in the current framework
without serious redesigning/writing. I guess you'll have to live with it...

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755  ----
-----+++++*****************************************************+++++++++-------
 'And this 'rebooting' business? Give it a good kicking, do you?' 'Oh, no,
  of course, we ... that is ... well, yes, in fact,' said Ponder. 'Adrian
    goes round the back and ... er ... prods it with his foot. But in a
     technical way,' he added. --- From: Hogfather by Terry Pratchett.



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list