Language allows for operator definition [message #645039] |
Wed, 15 December 2010 10:22 |
No real name Messages: 25 Registered: April 2010 |
Junior Member |
|
|
Hi,
Im currently trying to write the grammar for language which allows for operator definition, and defines its own operators in a base file. Unfortunately, I cannot change any design choices since I am just writing the plugin for an existing language.
Now the problem comes in when I want to accommodate for postfix expressions. My code looks as follows:
Expression:
expr+=UniraryExpression ( op+=[OperatorDeclaration | OperationSymbol] expr+=UniraryExpression)*;
UniraryExpression:
PreOperatorExpression
| PostOperatorExpression
;
PreOperatorExpression:
{PreOperatorExpression} op=[PreOperatorDeclaration | OperationSymbol] expression=PrimaryExpression;
PostOperatorExpression:
{PostOperatorExpression} expression=PrimaryExpression (op=[PostOperatorDeclaration | OperationSymbol])? ;
PrimaryExpression:
{NumberLiteral} value=NumberLiteral
| {BooleanLiteral} value=BooleanLiteral
| {FloatLiteral} value=FloatLiteral
| {NameLiteral} value=NameLiteral
| {StringLiteral} value=StringLiteral
| '(' Expression ')'
;
This doesnt work, because once the parser gets to a PrimaryExpression and sees a OperationSymbol, it doesnt know if that symbol is part of the Expression or PostExpression.
Is there any walkaround or should I just bite the bullet and hardcode the standard operators?
|
|
|
Powered by
FUDForum. Page generated in 0.02710 seconds