Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [XText] about grammar ambiguity, left recursion
[XText] about grammar ambiguity, left recursion [message #46205] Fri, 29 May 2009 11:45 Go to next message
Mikai Yang is currently offline Mikai YangFriend
Messages: 149
Registered: July 2009
Senior Member
Hi,
for my DSL, I have developed its ecore metamodel, which is directly mapped to its abstract sytax. As we know, we do not consider ambiguity and
left recursion in the abstract syntax. XText grammar would deal with concrete syntax and unamibiguous parsing, so XText deals with such situlations as
ambiguity, left recursion and operation precedence?
Thanks.
Michael.
Re: [XText] about grammar ambiguity, left recursion [message #46296 is a reply to message #46205] Fri, 29 May 2009 12:15 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
It is not allowed to write left recursive grammars. You'll have to
"left-factor" them.
Operator precedence is also defined through the way you write the parser
rules. Ambiguity is not allowed.

If you want for example write a simple arithmetic calculator, rules
could look like so:

PlusOperation returns Expression:
MultiplyOperation ({BinaryOp.left=current} operator=('+'|'-')
right=MultiplyOperation)*;

MultiplyOperation returns Expression:
PrimaryExpression ({BinaryOp.left=current} operator=('*'|'/')
right=PrimaryExpression)*;

PrimaryExpression returns Expression:
NumberLiteral |
'(' PlusOperation ')';

NumberLiteral :
value=INT;

Regards,
Sven

Michael schrieb:
> Hi,
> for my DSL, I have developed its ecore metamodel, which is directly
> mapped to its abstract sytax. As we know, we do not consider ambiguity
> and left recursion in the abstract syntax. XText grammar would deal with
> concrete syntax and unamibiguous parsing, so XText deals with such
> situlations as
> ambiguity, left recursion and operation precedence?
> Thanks.
> Michael.
Re: [XText] about grammar ambiguity, left recursion [message #369111 is a reply to message #46296] Tue, 28 July 2009 16:45 Go to previous message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
Another question to the grammar below:

The example grammar for expressions works fine, but any complex
expression needs parantheses. Is it possible to write the grammar such
that you can omit the parantheses in the PrimaryExpression when
referencing the PlusOperation?
All my tries lead to recursive cycles.

Cheers,
Hauke

Sven Efftinge schrieb:
> If you want for example write a simple arithmetic calculator, rules
> could look like so:
>
> PlusOperation returns Expression:
> MultiplyOperation ({BinaryOp.left=current} operator=('+'|'-')
> right=MultiplyOperation)*;
>
> MultiplyOperation returns Expression:
> PrimaryExpression ({BinaryOp.left=current} operator=('*'|'/')
> right=PrimaryExpression)*;
>
> PrimaryExpression returns Expression:
> NumberLiteral |
> '(' PlusOperation ')';
>
> NumberLiteral :
> value=INT;
Previous Topic:Inserting editor generated by Xtext to FormPage
Next Topic:Xtext + GMF synchronized editor
Goto Forum:
  


Current Time: Thu Dec 26 15:02:13 GMT 2024

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

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

Back to the top