[antlr-interest] Problem with C target output on example C grammar

Jim Idle jimi at temporal-wave.com
Wed Apr 2 09:41:04 PDT 2008



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Kamil Burzynski
> 
> Well, the thing is that it is natural way of doing in C++. In pure C
> returning struct by value is rarely used, I agree. But in C++ (and Java
> in fact), returning objects by value is much more common. Especially in
> my case - when the object was smart pointer itself. These entities are
> *meant* to be passed as value. And since they point to (usually)
> non-trivial class, you cannot reduce them away by returning a bunch of
> struct members at once.

If they are pointers, then they can be assign NULL so it should not be an issue, but as I said, if you use more than one element then you won't get the issue, so at worst, you could add a dummy int to the returns clause. Can you give me an example, other than struct, which you do not need to return, of something that you cannot because it cannot be assigned to NULL? I think, after a bit of looking, that I can avoid initializing the single return element, but something nags at the back of my mind about this. I would like to have an example of something that cannot be done that a user actually wants to do, so I can see if I can make it work. Thanks.

> Yeah, I am not familiar enough with antlr yet and do not know what tree
> parsing is for, gotta read more about it. Unfortunately I did not found
> any good documentation about it on antlr.org, maybe I was not looking
> carefully enough.

Best thing is to just buy yourself a copy of the reference book:
http://www.pragprog.com/titles/tpantlr

There is a lot of great information in there on how to do all sorts of things.

> > However, the answer to your problem is that the rule already
> > returns a struct if you have more than one return value, so if you
> > have just one element in your struct, then don't use the struct. If
> 
> But if you have object as in Java, you cannot return all its members
> separately, that would make no sense.

Would you want to return an object by value? Surely it will be by reference? However, as I said, if this really is the case, then add a dummy flag to the return for the moment, while I look in to it.

> > So, I think that we have reduced all your problems to the one
> > grammar error, one user error, one user misunderstanding and zero
> > problems with the C target, so I don't think you need to be concerned
> > about the C runtime :-)
> 
> Not so easy ;) There is one grammar error indeed. I do not know which
> problem you are thinking about my error, 

The fact that you did not relink your main program with a new .so and therefore got a segmentation violation when trying to run the binary with it. I explained that i n a previous eamil.

> In my other email I also indicated other error which are purely related
> to
> C runtime, I think: when rule uses 2 scopes, first of them is not
> accessible.

This was just that you did not relink the main executable with your library I believe. If not, then can you provide an example as I did not see anything in the prior emails. It might be there of course, but I didn't see anything else?

Jim





More information about the antlr-interest mailing list