|
Re: [XText] about grammar ambiguity, left recursion [message #46296 is a reply to message #46205] |
Fri, 29 May 2009 12:15 |
Sven Efftinge 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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03442 seconds