Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xtext create open declaration(xtext create open declaration)
xtext create open declaration [message #1740772] Thu, 18 August 2016 13:12 Go to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

Can anyone tell me to write grammar for open declaration like

a=b
a="b"
a=sm_cancel(true)

here the above open declarations sm_cancel and true are keywords.
Re: xtext create open declaration [message #1740785 is a reply to message #1740772] Thu, 18 August 2016 14:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi i cannot follow you.

please share a MINIMAL grammar that shows your problem


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext create open declaration [message #1740793 is a reply to message #1740785] Thu, 18 August 2016 14:44 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

I have grammar :

Sm_lib : 'sm_cancel' (exp=Expression);

Expression:
LogicalOr
;
LogicalOr :
BitwiseOr ({LogicalOr.left=current} '||' right=BitwiseOr)*
;
BitwiseOr :
LogicalAnd ({BitwiseOr.left=current} '|' right=LogicalAnd)*
;
LogicalAnd :
BitwiseAnd ({LogicalAnd.left=current} '&&' right=BitwiseAnd)*
;
BitwiseAnd :
Equivalency ({BitwiseAnd.left=current} '&' right=Equivalency)*
;
Equivalency :
Relational (({Equivalency.left=current} '==' | {NotEquivalency.left=current} '!=' | {Assignment.left=current}'=') right=Relational)*
;
Relational :
PlusMinus (({Ge.left=current} '>='| {le.left=current} '<='| {Gt.left=current} '>'| {lt.left=current} '<') right=PlusMinus)*
;
PlusMinus:
DivMult (({Plus.left=current}'+'| {Minus.left=current}'-') right=DivMult)*
;
DivMult:
LogicalNot (({Multiply.left=current} '*'| {Division.left=current}'/') right=LogicalNot)*
;
LogicalNot :
OnesComplement ({LogicalNot.left=current} '!' right=OnesComplement)*
;
OnesComplement :
Exponentiation ({OnesComplement.left=current} ('~') right=Exponentiation)*
;
Exponentiation :
ColonOperator ({Exponentialtion.left=current} '^' right=ColonOperator)*
;
ColonOperator :
PercentOperator | ({ColonOperator} (':'('+')?) expr=PercentOperator)
;
PercentOperator :
ArrowExpression | ({PercentOperator} ('%'|'%t'|'%.'|'%:') expr=ArrowExpression)
;
ArrowExpression :
Concatenation | ({ArrowExpression} ('->') expr=Concatenation)
;
Concatenation :
Primary ({Concatenation.left=current} '##' right=Primary)*
;
Primary:
string=STRING | number=NUMBER | variable=ID (ArrayLiteral+=ArrayLiteral* & SizeLiteral+=SizeLiteral*) | ('(' expression=Expression ')') | FieldNum;

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: SIGN? (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')+;

terminal fragment SIGN : '+' | '-' ;

Now I want to create assignment grammar without any keyword preceded.
Like

a = sm_cancel(true)

Here 'a' is just a variable without a type. And sm_cancel is parser rule. My code is not working because ' a = ' cannot be parsed.

[Updated on: Thu, 18 August 2016 14:45]

Report message to a moderator

Re: xtext create open declaration [message #1740795 is a reply to message #1740793] Thu, 18 August 2016 14:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
sorry this is not a minimal grammar.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext create open declaration [message #1740797 is a reply to message #1740795] Thu, 18 August 2016 14:57 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
For this assignment I didn't write any rule. I want to write rule to satisfy above declaration
Re: xtext create open declaration [message #1740799 is a reply to message #1740797] Thu, 18 August 2016 15:07 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
as i said i dont want to digg trough 100 lines of grammar to find out which grammar rules you think could satisfy your assignment or not.
this makes everyone no wanting to answer your questions. i mean this serious.

this is why i e.g. dont understand

Sm_lib : 'sm_cancel' (exp=Expression);

why not

Sm_lib : 'sm_cancel' '(' (params+=Expression (','params+=Expression)*)?);

and obiously dont see any try to declare sm_lib to be a Relational. (direcly or indirectly.
e.g. making sm:lib a Primary


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:left recursive error
Next Topic:Ambiguous cross reference
Goto Forum:
  


Current Time: Fri Apr 19 21:30:32 GMT 2024

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

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

Back to the top