-
I have the following grammar and I'm genuinely confused how to fix it so that there are no ambiguities and we avoid left recursion. NewExpression:
"new" expression=NewExpression ("<" typeParameters+=TypeExpression ("," typeParameters+=TypeExpression)* ">")? "(" (parameters+=Expression ("," parameters+=Expression)*)? ")"
| CallExpression;
CallExpression:
callRoot=MemberAccessExpression (
("<" typeParameters+=TypeExpression ("," typeParameters+=TypeExpression)* ">")? "(" (parameters+=Expression ("," parameters+=Expression)*)? ")"
)*
| MemberAccessExpression;
MemberAccessExpression:
memberRoot=ArrayAccessExpression (
"." member=ID
)*
| ArrayAccessExpression;
ArrayAccessExpression:
arrayRoot=PrimaryExpression ( "[" indexExpression=Expression "]")*;
I think I need some general help too, because I've read the docs front and back, and I think I am missing something 👍 . All in-all this software has been genuinely amazing and it really does the job, I just think I need one last little push over the edge and it can be incredibly useful for my needs. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Hey @jtenner, thanks we're always glad to hear positive feedback :) So basically, you're almost there, you can fix your ambiguities by using assigned actions. For example your rule
This can be read as follows: Parse an |
Beta Was this translation helpful? Give feedback.
-
For anyone reading about this problem, Langium has an excellent means of dealing with MemberAccess and right associative left recursive stuff like this: PathExpression:
PrimaryExpression (
{infer CallExpression.callRoot=current} ("<" typeParameters+=TypeExpression ("," typeParameters+=TypeExpression)* ">")? "(" (parameters+=Expression ("," parameters+=Expression)*)? ")"
| {infer MemberAccessExpression.memberRoot=current} "." member=ID
| {infer ArrayAccessExpression.arrayRoot=current} "[" indexExpression=Expression "]"
)+
| PrimaryExpression; |
Beta Was this translation helpful? Give feedback.
For anyone reading about this problem, Langium has an excellent means of dealing with MemberAccess and right associative left recursive stuff like this: