Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Simple Grammar causes Infinite Loop.
Simple Grammar causes Infinite Loop. [message #719576] Sat, 27 August 2011 23:18 Go to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
Hi there.

I started a new private project using xtext. During writing my grammar I encountered a really wierd infinite loop. I prepared this small grammar:

CompilationUnit:
    'package' name = FQN ';' 
    
    rootDeclaration=ClassDeclaration    
;

FQN:
    ID ('.' ID)*
;

ClassDeclaration:
    modifiers=ClassModifiers 'class' name=ID '{'
        members+=ClassDeclaration* 
    '}'	
;

enum Visibility:
    PUBLIC='public' | PROTECTED='protected' | PRIVATE='private'
;

ClassModifiers returns Modifiers:
    {Modifiers}
    (
        final?='final'?
        &
        abstract?='abstract'?   
        &
        extern?='extern'?
        & 
        visibility=Visibility?
    )
;



If I hit the code completion on any place within a dsl-file the members assignment causes an infinite loop:

at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.ruleClassDeclaration(InternalTestLangParser.java:288)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__MembersAssignment_4(InternalTestLangParser.java:2537)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__4__Impl(InternalTestLangParser.java:1575)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__4(InternalTestLangParser.java:1518)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__3(InternalTestLangParser.java:1448)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__2(InternalTestLangParser.java:1363)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__1(InternalTestLangParser.java:1288)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__0(InternalTestLangParser.java:1203)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.ruleClassDeclaration(InternalTestLangParser.java:288)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__MembersAssignment_4(InternalTestLangParser.java:2537)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__4__Impl(InternalTestLangParser.java:1575)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__4(InternalTestLangParser.java:1518)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__3(InternalTestLangParser.java:1448)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__2(InternalTestLangParser.java:1363)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__1(InternalTestLangParser.java:1288)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__0(InternalTestLangParser.java:1203)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.ruleClassDeclaration(InternalTestLangParser.java:288)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__MembersAssignment_4(InternalTestLangParser.java:2537)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__4__Impl(InternalTestLangParser.java:1575)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__4(InternalTestLangParser.java:1518)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__3(InternalTestLangParser.java:1448)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__2(InternalTestLangParser.java:1363)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__1(InternalTestLangParser.java:1288)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__0(InternalTestLangParser.java:1203)
at at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.ruleClassDeclaration(InternalTestLangParser.java:288)


It seems the generated UI antlr parse has a bug.

[edit]
meanwhile I found out how to solve the error by rewriting the grammar but the error is still wierd. It seems it's caused by the predicates:
This solution works
CompilationUnit:
    'package' name = FQN ';' 
    
    rootDeclaration=ClassDeclaration    
;

FQN:
    ID ('.' ID)*
;

ClassDeclaration:
    modifiers=ClassModifiers? 'class' name=ID '{'
        members+=ClassDeclaration* 
    '}'	
;

enum Visibility:
    PUBLIC='public' | PROTECTED='protected' | PRIVATE='private'
;

ClassModifiers returns Modifiers:
    final?='final'?  
    &
    abstract?='abstract'?   
    &
    extern?='extern'? 
    &
    visibility=Visibility
;


Cheers
Daniel

[Updated on: Sat, 27 August 2011 23:30]

Report message to a moderator

Re: Simple Grammar causes Infinite Loop. [message #719670 is a reply to message #719576] Sun, 28 August 2011 09:55 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Daniel,

which version of Xtext do you use? There was a fix for 2.0.1 which is
available on the Xtext update site.

If you already use 2.0.1, you seem to be bitten by this one:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=347012

Could you please add your grammar to the ticket and include a sample
input file + cursor position that allows to reproduce the issue?

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

On 28.08.11 01:18, Daniel wrote:
> Hi there.
> I started a new private project using xtext. During writing my grammar I
> encountered a really wierd infinite loop. I prepared this small grammar:
>
>
> CompilationUnit:
> 'package' name = FQN ';' rootDeclaration=ClassDeclaration ;
>
> FQN:
> ID ('.' ID)*
> ;
>
> ClassDeclaration:
> modifiers=ClassModifiers 'class' name=ID '{'
> members+=ClassDeclaration* '}'
> ;
>
> enum Visibility:
> PUBLIC='public' | PROTECTED='protected' | PRIVATE='private'
> ;
>
> ClassModifiers returns Modifiers:
> {Modifiers}
> (
> final?='final'?
> &
> abstract?='abstract'? &
> extern?='extern'?
> & visibility=Visibility?
> )
> ;
>
>
>
> If I hit the code completion on any place within a dsl-file the members
> assignment causes an infinite loop:
>
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.ruleClassDeclaration(InternalTestLangParser.java:288)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__MembersAssignment_4(InternalTestLangParser.java:2537)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__4__Impl(InternalTestLangParser.java:1575)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__4(InternalTestLangParser.java:1518)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__3(InternalTestLangParser.java:1448)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__2(InternalTestLangParser.java:1363)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__1(InternalTestLangParser.java:1288)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__0(InternalTestLangParser.java:1203)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.ruleClassDeclaration(InternalTestLangParser.java:288)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__MembersAssignment_4(InternalTestLangParser.java:2537)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__4__Impl(InternalTestLangParser.java:1575)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__4(InternalTestLangParser.java:1518)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__3(InternalTestLangParser.java:1448)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__2(InternalTestLangParser.java:1363)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__1(InternalTestLangParser.java:1288)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__0(InternalTestLangParser.java:1203)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.ruleClassDeclaration(InternalTestLangParser.java:288)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__MembersAssignment_4(InternalTestLangParser.java:2537)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__4__Impl(InternalTestLangParser.java:1575)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__4(InternalTestLangParser.java:1518)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__3(InternalTestLangParser.java:1448)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__2(InternalTestLangParser.java:1363)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__1(InternalTestLangParser.java:1288)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.rule__ClassDeclaration__Group__0(InternalTestLangParser.java:1203)
>
> at
> at.mydsl.testlang.ui.contentassist.antlr.internal.InternalTestLangParser.ruleClassDeclaration(InternalTestLangParser.java:288)
>
>
>
> It seems the generated UI antlr parse has a bug. Has anyone an idea how
> to solve this problem?
>
> Cheers
> Daniel
Re: Simple Grammar causes Infinite Loop. [message #736081 is a reply to message #719670] Thu, 13 October 2011 14:25 Go to previous messageGo to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
I just encountered this problem again in the latest stable build.
I reported the bug here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=360834
Re: Simple Grammar causes Infinite Loop. [message #775170 is a reply to message #719576] Thu, 05 January 2012 13:56 Go to previous messageGo to next message
Ralph Mayr is currently offline Ralph MayrFriend
Messages: 13
Registered: August 2011
Junior Member
Hello,

I've encountered an issue running Xtext 2.0.1 of which I think it might be the same as described here. For testing purposes I updated to Xtext 2.2.1 and am still able to reproduce the endless loop.

The bug 360834 is closed (RESOLVED FIXED). Could it be that the same issue still exists in 2.2.1, or do you think it's something completely different in my case?

Here's what I found out so far:

In public final void rule__<SomeRule>__Group__6__Impl() in my parser a call to rule__<SomeRule>__Alternatives_6() causes a RecognitionException ("No viable alternative..."). The exception is handled by ...__Alternatives_6(). In Group__6__Impl() state._fsp is decremented. After that, Group__6__Impl() returns, but winds up at the beginning of the switch statement that lead to the call to ...__Alternatives_6() again, and so forth.

In my case it also happens when invoking content assist. If it's helpful, I guess I also could provide a small grammar for reproduction purpose.

Thanks for any advice,
Ralph.
Re: Simple Grammar causes Infinite Loop. [message #775178 is a reply to message #775170] Thu, 05 January 2012 14:04 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Ralph,

a reproducable example is most welcome.

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

Am 05.01.12 14:56, schrieb Ralph Mayr:
> Hello,
>
> I've encountered an issue running Xtext 2.0.1 of which I think it might
> be the same as described here. For testing purposes I updated to Xtext
> 2.2.1 and am still able to reproduce the endless loop.
>
> The bug 360834 is closed (RESOLVED FIXED). Could it be that the same
> issue still exists in 2.2.1, or do you think it's something completely
> different in my case?
>
> Here's what I found out so far:
>
> In public final void rule__<SomeRule>__Group__6__Impl() in my parser a
> call to rule__<SomeRule>__Alternatives_6() causes a RecognitionException
> ("No viable alternative..."). The exception is handled by
> ...__Alternatives_6(). In Group__6__Impl() state._fsp is decremented.
> After that, Group__6__Impl() returns, but winds up at the beginning of
> the switch statement that lead to the call to ...__Alternatives_6()
> again, and so forth.
>
> In my case it also happens when invoking content assist. If it's
> helpful, I guess I also could provide a small grammar for reproduction
> purpose.
>
> Thanks for any advice,
> Ralph.
Re: Simple Grammar causes Infinite Loop. [message #775708 is a reply to message #775178] Fri, 06 January 2012 14:59 Go to previous messageGo to next message
Ralph Mayr is currently offline Ralph MayrFriend
Messages: 13
Registered: August 2011
Junior Member
Hi Sebastian,

thanks for your reply!

Reducing our grammar to an illustrative example wasn't quite as easy as I had hoped, but here's something that should work:

Model:
  (classDef+=ClassDef | instanceDef+=InstanceDef)* ;

ClassDef:
  access=Access "class"  name=ID (":" baseClass=[ClassDef])?
  "{"
    (assignments+=Assignment | attributes+=Attribute | (attributeRef+=[Attribute] ";"))*
  "}" ;

InstanceDef:
  access=Access "instance" instanceClass=[ClassDef] name=ID
  "{"
  (assignments+=Assignment)*
  "}" ;

Assignment:
  attribute=[Attribute] "=" value=STRING ;

Attribute:
  access=Access (type="integer"|type="string") name=ID (
    ("{" "}") | ";"
  ) ;

Access:
  {Access} (obsolete?="obsolete")? (private?="private")? ;


Now, when typing something like:

class MyClass :  {
}


in the editor, and putting the cursor after the colon, pressing CTRL+Space to invoke content assist leads to a "freezing" Eclipse. Actually, one can see that the Content Assist Parser runs into an endless loop, as described before. I was using the latest 2.2.1 release.

Thanks in advance,
Ralph.
Re: Simple Grammar causes Infinite Loop. [message #780124 is a reply to message #719576] Tue, 17 January 2012 08:29 Go to previous messageGo to next message
Ralph Mayr is currently offline Ralph MayrFriend
Messages: 13
Registered: August 2011
Junior Member
Hi,

any updates on this one? Or should I rather file a bug report?

Thanks,
Ralph.
Re: Simple Grammar causes Infinite Loop. [message #780138 is a reply to message #780124] Tue, 17 January 2012 08:58 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Ralph,

please file a ticket with the sample grammar and a sample model file
attached.

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

Am 17.01.12 09:29, schrieb Ralph Mayr:
> Hi,
>
> any updates on this one? Or should I rather file a bug report?
>
> Thanks,
> Ralph.
Previous Topic:DSL with "private" sections
Next Topic:deactivate default autocompletion
Goto Forum:
  


Current Time: Fri Apr 26 06:36:31 GMT 2024

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

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

Back to the top