[XText] about grammar ambiguity, left recursion [message #46205] |
Fri, 29 May 2009 07:45  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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;
|
|
|
Powered by
FUDForum. Page generated in 0.03306 seconds