Skip to main content



      Home
Home » Modeling » TMF (Xtext) » left recursion problem(I don't understand the left recursion)
left recursion problem [message #754645] Thu, 03 November 2011 14:01 Go to next message
Eclipse UserFriend
Hi,

I have a problem with the left recursion. I looked it up in the xtext documentation, but I didn't understand it. I hope you can help me out.

The error message is:

error(211): ../org.xtext.gui/src-gen/org/xtext/gui/parser/antlr/internal/InternalGuiDsl.g:257:1: [fatal] rule ruleWindow has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
warning(200): ../org.xtext.gui/src-gen/org/xtext/gui/parser/antlr/internal/InternalGuiDsl.g:257:1: Decision can match input such as "'tabContainer' RULE_ID '{' '}'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input



Here is my dsl:


Window:
'window' name=ID '{'
(tabContainer+=TabContainer)? /* HERE IS THE PROBLEM */
(components+=Component)*
'}'
;

TabContainer:
'tabContainer' name=ID '{'
(tabItems+=TabItem)*
'}'
;

TabItem:
'tabItem' name=ID '{'
panel+=Panel
'}'
;

Component:
Panel | TabContainer | Label | Button | ComboBox | ListBox | CheckBox | DropDown
;


Panel:
'panel' name=ID '{'
(layoutManager+=LayoutManager)?
(components+= Component)+
'}'
;
Re: left recursion problem [message #754648 is a reply to message #754645] Thu, 03 November 2011 14:09 Go to previous messageGo to next message
Eclipse UserFriend
If you have one tabcontainer - is this the optional one or one from
the components list? Regards Christian
Re: left recursion problem [message #754653 is a reply to message #754648] Thu, 03 November 2011 14:45 Go to previous messageGo to next message
Eclipse UserFriend
hi Christian,

sorry I updated my dsl.

The window can have either one TabContainer or 1-* Panels. I have still the
left recursion problem. The problem exists now in the panel (because of the OR-statement.


Remark:
If I try it like this, it works (instead of the OR-statement):

Panel:
'panel' name=ID '{'
(layoutManager+=LayoutManager)?
(components+= Component)+
'}'
;




DSL:

Window:
'window' name=ID '{'
(tabContainer+=TabContainer) |
(panel+=Panel)+
'}'
;

Panel:
'panel' name=ID '{'
(layoutManager+=LayoutManager)? | /* here is the problem */
(components+= Component)+
'}'
;

LayoutManager:
'layoutManager' name=ID '{'
(components+=Component)*
'}'
;

Component:
Panel | TabContainer | Label | Button | ComboBox | ListBox | CheckBox | DropDown
;

[Updated on: Thu, 03 November 2011 14:49] by Moderator

Re: left recursion problem [message #754655 is a reply to message #754653] Thu, 03 November 2011 14:58 Go to previous messageGo to next message
Eclipse UserFriend
No,

the problem is still the same.

if you have only one tabcontainer. is this the tabcontainer or one panel?

~Christian
Re: left recursion problem [message #754662 is a reply to message #754653] Thu, 03 November 2011 15:16 Go to previous messageGo to next message
Eclipse UserFriend
How does your layout mgr rule look like?

On 2011-11-03 18:45:08 +0000, Jens said:

> hi Christian,
> sorry I updated my dsl.
> The window can have either one TabContainer or 1-* Panels. I have still
> the left recursion problem. The problem exists now in the panel
> (because of the OR-statement.
>
>
> Window:
> 'window' name=ID '{'
> (tabContainer+=TabContainer) | (panel+=Panel)+
> '}'
> ;
>
> Panel:
> 'panel' name=ID '{'
> (layoutManager+=LayoutManager)? | /* here is the problem */
> (components+= Component)+
> '}'
> ;
Re: left recursion problem [message #754663 is a reply to message #754662] Thu, 03 November 2011 15:22 Go to previous messageGo to next message
Eclipse UserFriend
hi,

LayoutManager:
'layoutManager' name=ID '{'
(components+=Component)*
'}'
;
Re: left recursion problem [message #754664 is a reply to message #754663] Thu, 03 November 2011 15:32 Go to previous messageGo to next message
Eclipse UserFriend
On 2011-11-03 19:22:25 +0000, Jens said:

> LayoutManager:
> 'layoutManager' name=ID '{'
> (components+=Component)*
> '}'
> ;

Works perfect for me,
can you post a complete reproducable grammar?

thx Christian
Re: left recursion problem [message #754678 is a reply to message #754664] Thu, 03 November 2011 16:28 Go to previous messageGo to next message
Eclipse UserFriend
sure.



DomainModel:
(elements+=PackageDeclaration);

PackageDeclaration:
'package' name=QualifiedName '{'
(elements+=Window)*
'}';

QualifiedNameWithWildcard:
QualifiedName '.*'?;

QualifiedName:
ID ('.' ID)*;

Window:
'window' name=ID '{'
tabContainer+=TabContainer |
(components+=Component)+
'}'
;

TabContainer:
'tabContainer' name=ID '{'
(tabItems+=TabItem)*
'}'
;

TabItem:
'tabItem' name=ID '{'
panel+=Panel
'}'
;

Component:
Panel | TabContainer | Label | Button | ComboBox | ListBox | CheckBox | DropDown
;

Panel:
'panel' name=ID '{'
(layoutManager+=LayoutManager)?
(components+= Component)+
'}'
;

LayoutManager:
'layoutManager' name=ID '{'
(components+=Component)*
'}'
;

Array:
'array' name=ID '' datatype[] array2 '{' QualifiedName '}';
;

Label:
'label' name=ID '{' text=ID '}'
;

CheckBox:
'checkbox' name=ID
;

ListBox:
'listbox' name=ID
;

ComboBox:
'combobox' name=ID
;

DropDown:
'dropdown' name=ID
;

Button:
'button' name=ID
;
Re: left recursion problem [message #754679 is a reply to message #754664] Thu, 03 November 2011 16:30 Go to previous messageGo to next message
Eclipse UserFriend
sorry i have posted the wrong one - here you go:

DomainModel:
(elements+=PackageDeclaration);

PackageDeclaration:
'package' name=QualifiedName '{'
(elements+=Window)*
'}';

QualifiedNameWithWildcard:
QualifiedName '.*'?;

QualifiedName:
ID ('.' ID)*;

Window:
'window' name=ID '{'
tabContainer+=TabContainer |
(components+=Component)+
'}'
;

TabContainer:
'tabContainer' name=ID '{'
(tabItems+=TabItem)*
'}'
;

TabItem:
'tabItem' name=ID '{'
panel+=Panel
'}'
;

Component:
Panel | TabContainer | Label | Button | ComboBox | ListBox | CheckBox | DropDown
;

Panel:
'panel' name=ID '{'
(layoutManager+=LayoutManager) |
(components+= Component)+
'}'
;

LayoutManager:
'layoutManager' name=ID '{'
(components+=Component)*
'}'
;

Label:
'label' name=ID '{' text=ID '}'
;

CheckBox:
'checkbox' name=ID
;

ListBox:
'listbox' name=ID
;

ComboBox:
'combobox' name=ID
;

DropDown:
'dropdown' name=ID
;

Button:
'button' name=ID
;
Re: left recursion problem [message #754680 is a reply to message #754679] Thu, 03 November 2011 16:35 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

i guess there is a missunderstanding obout precedence in xtext in your grammar. you might actually want to have

Panel:
'panel' name=ID '{'
((layoutManager+=LayoutManager) |
(components+= Component)+)
'}'
;


~Christian
Re: left recursion problem [message #754684 is a reply to message #754680] Thu, 03 November 2011 16:39 Go to previous message
Eclipse UserFriend
hi,

that works, thanks a lot.
So I don't need the left recursion right now.
Previous Topic:Scoping problem
Next Topic:xtext-utils: multiple test methods in single class causes exception??
Goto Forum:
  


Current Time: Sun Oct 19 17:25:31 EDT 2025

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

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

Back to the top