Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] assignement in Xpand
[Xpand] assignement in Xpand [message #521440] Wed, 17 March 2010 11:40 Go to next message
Eclipse UserFriend
Hi all,

I'm working on a project with Xtext and Xpand ( OpenArchitectureWare) and I have a problem with the assignment in an Xpand. In my grammar, I have a rule
Table: (Column = columns +) +
and
Column: length = INT.

in my file Xpand, I have a statement "FOREACH" on Column, and I want to add at each iteration the length value of current column to a variable that I declare before the statement "FOREACH".

I think that i can use a GLOBALVAR but i want to know if there are an other ways to do it.

Best regards

[Updated on: Wed, 17 March 2010 12:20] by Moderator

Re: [Xpand] assignement in Xpand [message #521452 is a reply to message #521440] Wed, 17 March 2010 12:01 Go to previous messageGo to next message
Eclipse UserFriend
PLZZZ, some one help me..
I have to resolve this problem to presente my exemple in a meeting tomorrow.
I don't know if working with Xpand, and Xtend was a good idea or i have to work with an other framwork ( ATL or OCL or something like that...)
Re: [Xpand] assignement in Xpand [message #521476 is a reply to message #521452] Wed, 17 March 2010 13:24 Go to previous messageGo to next message
Eclipse UserFriend
hello - do you use this var within the foreach or just at the end e.g. for a sum. if you just want to summarize just write a little extension like this one

Integer getLengthSum(Table table) : table.columns.getLengthSum();

private Integer getLengthSum(List[Column] cols) :
	cols.size == 0 ? 0 : cols.first().length + (cols.withoutFirst()).getLengthSum();


Re: [Xpand] assignement in Xpand [message #521483 is a reply to message #521476] Wed, 17 March 2010 14:00 Go to previous messageGo to next message
Eclipse UserFriend
thank you for your answer,

well, what i have to do is to print the value of my variable after each iteration
this value is the somme of the other past columns length, and the actual column length.

here is the source code of my Xpand end Xtend file:


«LET 1 AS inter»

«FOREACH columns AS column»
the actual value is : sum(inter,column.length) «REM» value should be printed here.«ENDREM»
«ENDFOREACH»
«ENDLET»
«ENDDEFINE»


and for my extension :

sum(Integer inter,Integer length_col) : 
	inter<-inter+length_col;



So that didn't work

[Updated on: Wed, 17 March 2010 14:01] by Moderator

Re: [Xpand] assignement in Xpand [message #521487 is a reply to message #521440] Wed, 17 March 2010 14:23 Go to previous messageGo to next message
Eclipse UserFriend
what about this

«DEFINE main FOR Table»
«FILE "test.txt"»
«FOREACH columns AS c ITERATOR i»
«this.getLengthSum(i.counter1)»   
«ENDFOREACH»
«ENDFILE» 
«ENDDEFINE»


Integer getLengthSum(Table table, Integer upTo) : table.columns.getLengthSum(upTo);

private Integer getLengthSum(List[Column] cols, Integer upTo) :
	cols.size == 0 || upTo ==0 ? 0 : cols.first().length + (cols.withoutFirst()).getLengthSum(upTo-1);
Re: [Xpand] assignement in Xpand [message #521647 is a reply to message #521487] Thu, 18 March 2010 08:08 Go to previous message
Eclipse UserFriend
thank you for your help, that's works!! you saved my life Smile
i didn't think that working with those frameworks gonna to be so abstract!! thnx
Previous Topic:[Xpand] Modular code generation?
Next Topic:[XTend] Importing *.ext files from Base Workspace fails when working in Runtime Workspace *solved*
Goto Forum:
  


Current Time: Sun Jul 20 16:27:21 EDT 2025

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

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

Back to the top