OCL: Iterate over code lines [message #894885] |
Tue, 10 July 2012 18:29  |
Eclipse User |
|
|
|
Hey
Example:
num a = 1
num b = 2
num c = 3
num d = 4
num e = 5
a.plus(b)
c.plus(d)
a.plus(c)
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?
Thanks.
|
|
|
|
Re: OCL: Iterate over code lines [message #895138 is a reply to message #894913] |
Wed, 11 July 2012 15:24  |
Eclipse User |
|
|
|
Ed Willink wrote on Wed, 11 July 2012 01:34Hi
There is an OCL newsgroup for OCL discussions.
Thanks for pointing this out! I'll post the same question there.
Ed Willink wrote on Wed, 11 July 2012 01:34Your discussion seems to suggest that you are performing run-time
evaluation at compile-time, which is of course possible but a bit
peculiar. For the simple expressions you provide, it may work, but it
will collapse as soon as your expression language elaborates to
incorporate a variable/parameter.
This is just a simplified example of what I actually want to accomplish. What a really want to do is reference checking (just to see whether two objects are the same). That's all, but again with the same possibility to store the result in the first argument. The variable/parameter problem will never occur.
Ed Willink wrote on Wed, 11 July 2012 01:34In OCL you would need to iterate a Set(Tuple(name:String,value:Integer))
to maintain the accumulated state. (Imperative OCL provides a Dict,
which is mutable)
Can you be a bit more specific (eg give an example)? That would help a lot!
Thanks.
[Updated on: Wed, 11 July 2012 15:25] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.46921 seconds