Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » grammar with implicit variable declarations(Issue with cyclic references)
grammar with implicit variable declarations [message #651261] Fri, 28 January 2011 15:59 Go to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi,

Simplified my grammar does something like this:
case 1:
   x = 1
case 2:
   x = 2
y = x * 2

This needs an implicit declaration of variables since x is defined twice but all references to x need to refer to the same object which needs to know all its definitions.

I implemented this based on Sven's suggestion ( http://www.eclipse.org/forums/index.php?t=msg&S=2e4a29d7 fff0322e71b35e3a3aa63e3f&th=198813&goto=634090#msg_6 34090)

So the name of a variable definition is a reference to a variable declaration. If linking fails then a declaration object is created in a dummy resource. The declaration also registers all its definitions.

This part seems to works despite I am not sure that there are no negative side effects.

The problem comes when I have cyclic references. Ignore that the example does not make sense. It is just a simplification.
x = z + 1
y = x + 1
z = x - 2

z cannot be resolved in the definition of x.

I can work around it by breaking the cycle, e.g. by removing x from the definition of y. Then a declaration of z is created, and it become referable by x, even after undoing this change.

But after re-building the project z is not referable again.

This might sound a little bit complicated, but on the bottom line it is just "implicit variable declaration" and "cyclic reference".

Any suggestion to overcome this would be much appreciated.

Thanks,
Marco
Re: grammar with implicit variable declarations [message #651273 is a reply to message #651261] Fri, 28 January 2011 16:38 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Correction: For the work around it is not necessary to break the cyclic reference. It is enough to dummy edit the definition with the unresolved z by adding a whitespace to the line.

Anyway, this behavior is still not acceptable.

Regards,
Marco
Re: grammar with implicit variable declarations [message #651405 is a reply to message #651273] Sun, 30 January 2011 13:24 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Marco,

I didn't get it. Are you saying that you implemented something on your
own which does not work as expected and consider this to be not
acceptable from the framework's point of view? In other words: You blame
Xtext for something that you (tried to) put on top of it which contains
a bug? If I got it wrong, please be so kind and provide more
information about your problem and the way you tried to solve it.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 28.01.11 17:38, schrieb Marco:
> Correction: For the work around it is not necessary to break the cyclic
> reference. It is enough to dummy edit the definition with the unresolved
> z by adding a whitespace to the line.
>
> Anyway, this behavior is still not acceptable.
>
> Regards,
> Marco
icon5.gif  Re: grammar with implicit variable declarations [message #651514 is a reply to message #651405] Mon, 31 January 2011 13:58 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi Sebastian,

I do not blame at all. I ask for help.

Sven made a suggestion about creating objects for unresolveable references, which I guess was followed by others too.

My use case combines this with another requirement which might not be that uncommon: cyclic references.

I do not know the process of linking in that detail, and hope that somebody can give me hints about what could cause the described issue.

I simply do not understand what makes the resolution of a cyclic reference different from the resolution of other references?

What mechanism allows to make forward references? All objects are instantiated before the references are resolved, right? So what can then make the difference between forward, backward, and cyclic references?

Thanks,
Marco
Re: grammar with implicit variable declarations [message #652524 is a reply to message #651514] Fri, 04 February 2011 11:39 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Marco,

yes, all objects are instantiated prior to the linking. The next step is
the installation of proxies instead of actual references. This allows to
leverage EMF's proxy semantics that is a reference will be transparently
resolved when someone navigates along its path.
Cyclic resolution can happen when your scope provider implementation
contains a bug.

Consider the following artificial example:

entity A extends B {}
entity B {}

The parser would instantiate two entities, one name A, another B.
The LazyLinker would install a proxy for the extends B. When this proxy
is going to be resolved, the call chain will finally end up in your
scope provider e.g. in

scope_Entity_extends(Entity a, EReference extendsRef) {
..
}

Now comes the tricky part (which is not that tricky in this stupid
example. You have to resolve the extends relationship without invoking
a.getExtends() because this would be a reentrant call to the proxy
resolution mechanism and thereby lead to cyclic resolution errors. That
is the only restriction that Xtext has with respect to cyclic resolutions.

Does that clarifiy things?

To conclude: I'd expect that your code or your "specification" has a bug
that does not allow resolve the scenario that you mentionend in your
first post.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 31.01.11 14:58, schrieb Marco:
> Hi Sebastian,
>
> I do not blame at all. I ask for help.
>
> Sven made a suggestion about creating objects for unresolveable
> references, which I guess was followed by others too.
>
> My use case combines this with another requirement which might not be
> that uncommon: cyclic references.
>
> I do not know the process of linking in that detail, and hope that
> somebody can give me hints about what could cause the described issue.
>
> I simply do not understand what makes the resolution of a cyclic
> reference different from the resolution of other references?
>
> What mechanism allows to make forward references? All objects are
> instantiated before the references are resolved, right? So what can then
> make the difference between forward, backward, and cyclic references?
>
> Thanks,
> Marco
Previous Topic:Getting Started not working
Next Topic:How to deal with partitions when partition is not terminal
Goto Forum:
  


Current Time: Thu Apr 25 06:02:38 GMT 2024

Powered by FUDForum. Page generated in 0.07432 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top