|OCL: Iterate over code lines [message #895139]
||Wed, 11 July 2012 19:26
| Wouter Schaekers
Registered: July 2012
num a = 1
num b = 2
num c = 3
num d = 4
num e = 5
a.plus(e) <- ERROR
I want to iterate over all lines (eg the grammar lines that define the 'plus') and make sure that the first argument is never higher than the second argument. So:
a.plus(b) -> a becomes 3
c.plus(d) -> c becomes 7
a.plus(d) -> a becomes 10
a.plus(e) -> 10 > 5 -> ERROR
Ofcourse it isn't difficult if you store the solution of every operation in a new variable, but that's not what I want. I want to put the sum in the first argument.
I know how to iterate over a collection in OCL. (eg self.rules->iterate(n : Name; sum : Integer = 0 | sum + n.int1) < 15) But in here, I have to use some sort of index or use a next() or previous() command if that exists.
Is it possible to do such a thing in OCL?
PS: I posted the same question here, but I was advised to post this question on this forum.
[Updated on: Wed, 11 July 2012 19:27]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.01769 seconds