Skip to main content



      Home
Home » Modeling » TMF (Xtext) » xtext create open declaration(xtext create open declaration)
xtext create open declaration [message #1740772] Thu, 18 August 2016 09:12 Go to next message
Eclipse UserFriend
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 10:33 Go to previous messageGo to next message
Eclipse UserFriend
hi i cannot follow you.

please share a MINIMAL grammar that shows your problem
Re: xtext create open declaration [message #1740793 is a reply to message #1740785] Thu, 18 August 2016 10:44 Go to previous messageGo to next message
Eclipse UserFriend
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 10:45] by Moderator

Re: xtext create open declaration [message #1740795 is a reply to message #1740793] Thu, 18 August 2016 10:54 Go to previous messageGo to next message
Eclipse UserFriend
sorry this is not a minimal grammar.
Re: xtext create open declaration [message #1740797 is a reply to message #1740795] Thu, 18 August 2016 10:57 Go to previous messageGo to next message
Eclipse UserFriend
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 11:07 Go to previous message
Eclipse UserFriend
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
Previous Topic:left recursive error
Next Topic:Ambiguous cross reference
Goto Forum:
  


Current Time: Mon Jul 28 15:46:02 EDT 2025

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

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

Back to the top