Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext non-LL(*) for Declaration and Assignment
Xtext non-LL(*) for Declaration and Assignment [message #1726452] Mon, 14 March 2016 01:32 Go to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
This is my grammar.
I simply want to make a C like language. Problem occurs when I add the BoolAssignment and IntAssignment statements. I get the following error
error(211): ../org.xtext.cbb/src-gen/org/xtext/parser/antlr/internal/InternalCbb.g:114:2: [fatal] rule ruleStatement has non-LL(*) decision due to recursive rule invocations reachable from alts 3,4.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.


1. I have tried setting the backtrack=true and the error persists
2. I know Antlr shouldn't be used for such languages

* What is the correct way to have both the Declaration and Assignments both to work?
* Are there any improvements in the grammar that I can make?
* Are there any tools out there that do a similar job to Xtext and have the UI capabilities found in Xtext that would be easier to develop such language?

Thanks

Module:
    (statements+=Statement)*;

Statement:
    Boolean |
    Integer |
    BoolAssignment |
    IntAssignment;

//BOOLEANS

Boolean:
    ('bool' name=ID ('=' expr=BoolExpression)? ';') |
    ('const' 'bool' name=ID '=' expr=BoolExpression ';');

BoolAssignment:
    assignee=[Boolean] '=' expr=BoolExpression';';

BoolExpression:
    Logical;

Logical returns BoolExpression:
    Comparison (({Not.left=current} '!' | {And.left=current} '&&'| {Or.left=current} '||') right=Comparison)*;

Comparison returns BoolExpression:
    PrimaryBoolExpression (({Equal.left=current} '==' | {NotEqual.left=current} '!=' | {LessThan.left=current} '<' | {LessThanEqual.left=current} '<=' | {GreaterThan.left=current} '>' | {GreaterThanEqual.left=current} '>=') right=PrimaryBoolExpression)*;

PrimaryBoolExpression returns BoolExpression:
    '(' BoolExpression ')' |
    {BooleanLiteral} value=boolean_value |
    {BooleanReference} ref=[Boolean];

boolean_value:
    'true' | 'false';

// INTEGERS

Integer:
    'const' 'int' name=ID '=' expr=IntExpression ';' | 
    'int' name=ID (assignment_operator expr=IntExpression)? ';';

IntAssignment: 
    assignee=[Integer] assignment_operator expr=IntExpression';';

IntExpression:
    Addition;

Addition returns IntExpression:
    Multiplication (({Plus.left=current} '+' | {Minus.left=current} '-') right=Multiplication)*;

Multiplication returns IntExpression:
    Bitwise (({Multi.left=current} '*' | {Div.left=current} '/') right=Bitwise)*;

Bitwise returns IntExpression:
    PrimaryIntExpression (({Not.left=current} '~' | {And.left=current} '&' | {Or.left=current} '|' | {Xor.left=current} '^' | {RightShift.left=current} '>>' | {LeftShift.left=current} '<<') right=PrimaryIntExpression)*;

PrimaryIntExpression returns IntExpression:
    '(' IntExpression ')' |
    {IntegerLiteral} value=integer_value |
    {IntegerIncrementDecrement} (increment_decrement_operator ref=[Integer]|ref=[Integer] increment_decrement_operator) |
    {IntegerReference} ref=[Integer];

assignment_operator:
    '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<='  | '>>=';

increment_decrement_operator:
    '++' | '--';

integer_value:
    '-'?INT+;
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726458 is a reply to message #1726452] Mon, 14 March 2016 06:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Hi

the Problem is here

{IntegerReference} ref=[Integer];

and here

{BooleanReference} ref=[Boolean];

this both parses as ID

=>

you have to unify both Expression chains and do handling the "this can be boolean only or this can int only" in the typesystem/validator.

if you look for alternatives and do not stick to eclipse as platform have a look at http://mbeddr.com/


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726505 is a reply to message #1726458] Mon, 14 March 2016 11:06 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
How can I unify the expressions?

And I got to have no errors when I remove those:
BoolAssignment:
    assignee=[Boolean] '=' expr=BoolExpression';';

IntAssignment: 
    assignee=[Integer] assignment_operator expr=IntExpression';';


What does this mean?

[Updated on: Mon, 14 March 2016 11:16]

Report message to a moderator

Re: Xtext non-LL(*) for Declaration and Assignment [message #1726506 is a reply to message #1726505] Mon, 14 March 2016 11:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
ayman salah <forums-noreply@xxxxxxxx> wrote:
> So there is no way to workaround this problem? and achieve the same functionality?
>

Not without a grammar and thus a meta model change


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726508 is a reply to message #1726506] Mon, 14 March 2016 11:17 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Please check my message edit
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726509 is a reply to message #1726508] Mon, 14 March 2016 11:19 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
What changes should be made to get this to work?
I don't have any problems with changing anything.
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726512 is a reply to message #1726509] Mon, 14 March 2016 11:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
If you you have following model

bool a = true;
int b = 1;
a = a;
b = b;
then for both a=a; and b=b;

ID = ID; will be parsed which is ambigous


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726514 is a reply to message #1726512] Mon, 14 March 2016 11:42 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Yeah I understand the problem now.

So how can I unify the expression. By unify you meant to have all the expressions in the same rule and check using the validator for types?
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726516 is a reply to message #1726514] Mon, 14 March 2016 11:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
yes only one rule.

e.g.

Type : Integer | Boolean;

Assignment: assignee=[Type] '=' value=Expression;...
Expression: .... //chain that unites both


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726518 is a reply to message #1726516] Mon, 14 March 2016 11:46 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
If you check the expressions out, you can see that they have different operators. How can I have one expression for both while restricting some operators to each of them.
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726520 is a reply to message #1726518] Mon, 14 March 2016 11:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
as i said you would put such things into the typesystem / validator

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726521 is a reply to message #1726520] Mon, 14 March 2016 11:53 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Okay Thanks a lot. I will try it out and let you know if I face any problems.
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726522 is a reply to message #1726521] Mon, 14 March 2016 11:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
ok if you do not want to implement the typesystem manually. you may have a look at Lorenzo Bettinis XSemantics framework

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726526 is a reply to message #1726522] Mon, 14 March 2016 12:31 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Surfing the web I came across XSemantics. But I don't know how does it work. Is it like a plugin to Xtext that I can use some parts from?
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726532 is a reply to message #1726526] Mon, 14 March 2016 13:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
ayman salah <forums-noreply@xxxxxxxx> wrote:
> Surfing the web I came across XSemantics. But I don't know how does it
> work. Is it like a plugin to Xtext that I can use some parts from?
>

It is a framework that lets you describe and implement type systems for
xtext declaratively


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext non-LL(*) for Declaration and Assignment [message #1726650 is a reply to message #1726526] Tue, 15 March 2016 11:05 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1784
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 14/03/2016 13:31, ayman salah wrote:
> Surfing the web I came across XSemantics. But I don't know how does it
> work. Is it like a plugin to Xtext that I can use some parts from?

Please, make sure to have a look at the documentation

http://xsemantics.sourceforge.net/documentation/

cheers
Lorenzo

--
Prof. Lorenzo Bettini, Computer Science, DISIA, Univ. Firenze
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:Standalone Testing Main function
Next Topic:Testing XText-based interpreter calling out to Henshin
Goto Forum:
  


Current Time: Tue Sep 21 12:23:21 GMT 2021

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

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

Back to the top