Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext grammar ambiguity problem(Xtext grammar ambiguity problem)
Xtext grammar ambiguity problem [message #1741866] Tue, 30 August 2016 09:39 Go to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

I am not able to execute the below grammar for Assignment. Could you please tell me how to avoid ambiguity for parser rule assignment?

Model: {Model} NL* statements+=Statement*;

Statement: (NonRecursingStatement) ';'? NL+ | HASH_COMMENT NL*;

NonRecursingStatement returns Statement:
(Assignment)
;

Assignment: exp+=(CompleteExpression) =>'=' exp+=(CompleteExpression);

ArrayDecl : {ArrayDecl} ('[' ']') | ('[' size=CompleteExpression ']');

Parenthesis : {Parenthesis} ('(' ')') | ('(' size=CompleteExpression ')');

Expression:
LogicalOr
;
LogicalOr returns Expression:
BitwiseOr ({LogicalOr.left=current} '||' right=BitwiseOr)*
;
BitwiseOr returns Expression:
LogicalAnd ({BitwiseOr.left=current} '|' right=LogicalAnd)*
;
LogicalAnd returns Expression:
BitwiseAnd ({LogicalAnd.left=current} '&&' right=BitwiseAnd)*
;
BitwiseAnd returns Expression:
Equivalency ({BitwiseAnd.left=current} '&' right=Equivalency)*
;
Equivalency returns Expression:
Relational ({Equivalency.left=current} ('=='|'!='|'=') right=Relational)*
;
Relational returns Expression:
PlusMinus ({Relational.left=current} ('>='|'<='|'>'|'<') right=PlusMinus)*
;
PlusMinus returns Expression:
DivMult ({PlusMinus.left=current} ('+'|'-') right=DivMult)*
;
DivMult returns Expression:
LogicalNot ({DivMult.left=current} ('/'|'*') right=LogicalNot)*
;
LogicalNot returns Expression:
OnesComplement | ({LogicalNot} '!' expr=OnesComplement)
;
OnesComplement returns Expression:
Exponentiation ({OnesComplement.left=current} ('~') right=Exponentiation)*
;
Exponentiation returns Expression:
Concatenation ({Exponentialtion.left=current} '^' right=Concatenation)*
;
Concatenation returns Expression:
ArrowExpression ({Concatenation.left=current} '##' right=ArrowExpression)*
;
ArrowExpression returns Expression:
Primary ({ArrowExpression.left=current} '->' right=Primary)*
;
Primary returns Expression: {Expression}
name=NUMBER | name=STRING | name=ID (ArrayDecl=ArrayDecl? & Parenthesis=Parenthesis?) | ArrayDecl=ArrayDecl | Parenthesis=Parenthesis
;

CompleteExpression:
c+=Expression (','? c+=Expression)*
;

terminal DBMS: ('DBMS'|'Dbms'|'dbms') (('\\'((' '|'\t')* '\r'? '\n')) | !('\n' | '\r'))*;

terminal ID : ('a'..'z'|'A'..'Z'|'$'|'.'|'@'|'_')('a'..'z'|'A'..'Z'|'$'|'.'|'0'..'9'|'@'|'*'|'_')*;

terminal STRING : '"' ( '\\'('"'|('\r'? '\n')) | !('\n'|'"') )* '"' |
"'" ( '\\'("'"|('\r'? '\n')) | !('\n'|"'") )* "'";

terminal SL_COMMENT: '//' !('\n' | '\r')*;

terminal HASH_COMMENT : ('#'('\r'? '\n')?) | ('#' !('#'|'\n'|'\r')+ ('\r'? '\n')?) | (('#''#''#') !('\n'|'\r')* ('\r'? '\n')?);

terminal WS : (' '|'\t'| ('\\'((' '|'\t')* '\r'? '\n')))+;

terminal NL : ('\r'? '\n')+;

terminal NUMBER: (OCTAL|FLOAT|INT|BINARY|HEX);

terminal OCTAL returns ecore::EInt: ('0') ('0'..'7')+;

terminal FLOAT returns ecore::EFloat: ('0'..'9' ('0'..'9')*) '.' ('0'..'9')*;

terminal INT returns ecore::EInt: '0'..'9' ('0'..'9')*;

terminal RANGE: '0'..'9' '..' ('0'..'9')*;

terminal BINARY returns ecore::EInt: ('0b'|'0B') ('0'|'1')+;

terminal HEX returns ecore::EInt:('0x'|'0X')('0'..'9'|'a'..'f'|'A'..'F')+;
Re: Xtext grammar ambiguity problem [message #1741868 is a reply to message #1741866] Tue, 30 August 2016 09:47 Go to previous message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
I tried this

Assignment: CompleteExpression ({Assignment.lhs=current} '=' value=CompleteExpression);

its working.

Could you please explain how it works?
Previous Topic:Left recursion
Next Topic:Unit testing using CompilationTestHelper
Goto Forum:
  


Current Time: Mon Apr 19 13:38:29 GMT 2021

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

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

Back to the top