Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » My xtext grammar showing when I am using object specifier inside expression(My xtext grammar showing when I am using object specifier inside expression)
My xtext grammar showing when I am using object specifier inside expression [message #1733589] Mon, 30 May 2016 10:33
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

I have OpenAssignment in my edit like a = b or math a = b or math %2.0a = b

I have written grammar for OpenAssignment as shown in below grammar. Parser not parsing the below grammar

OpenAssignment: {OpenAssignment} ('math')? (precision=Precision)? ((exp+=Expression) (','? (exp+=Expression))*);

but if I remove '?' after 'math' keyword it is working.

OpenAssignment: {OpenAssignment} ('math') (precision=Precision)? ((exp+=Expression) (','? (exp+=Expression))*);

How can I handle this case?

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

Statement: (OpenAssignment);

OpenAssignment: {OpenAssignment} ('math')? (precision=Precision)? ((exp+=Expression) (','? (exp+=Expression))*);

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.left=current} '!' right=OnesComplement)*
;
OnesComplement returns Expression:
Exponentiation ({OnesComplement.left=current} ('~') right=Exponentiation)*
;
Exponentiation returns Expression:
Concatenation ({Exponentialtion.left=current} '^' right=Concatenation)*
;
Concatenation returns Expression:
Primary ({Concatenation.left=current} '##' right=Primary)*
;
Primary returns Expression: {Expression}
( => jplId=JPLID | number=NUMBER | str=STRING | ('[' arrSize=(ID|NUMBER) ']') | ('(' ((ID|NUMBER|STRING) (','? (ID|NUMBER|STRING))*)? ')') | ('{' (id+=ID|num+=NUMBER) (','? (id+=ID|num+=NUMBER))*) '}' )
;
GSD returns Expression:
JPLID {GSD.left=current} ('[' occurence=(NUMBER|STRING) ']')?('(' m=NUMBER (',' (n=NUMBER))? ')')? '->' right=JPLID
;

terminal DBMS: ('DBMS'|'Dbms'|'dbms') (('\\'(' '* '\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'| ('\\'(' '* '\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')+;
Previous Topic:Formatter in IntelliJ
Next Topic:Design considerations supporting Heredoc with Xtext/antlr lexer
Goto Forum:
  


Current Time: Tue Nov 12 22:05:55 GMT 2019

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

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

Back to the top