Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [XText] about grammar ambiguity, left recursion
[XText] about grammar ambiguity, left recursion [message #46205] Fri, 29 May 2009 07:45 Go to next message
Eclipse UserFriend
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 08:15 Go to previous messageGo to next message
Eclipse UserFriend
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 12:45 Go to previous message
Eclipse UserFriend
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: Wed May 07 22:19:58 EDT 2025

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

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

Back to the top