Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL: Iterate over code lines
OCL: Iterate over code lines [message #895139] Wed, 11 July 2012 19:26
Wouter Schaekers is currently offline Wouter SchaekersFriend
Messages: 17
Registered: July 2012
Junior Member
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.

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

Previous Topic:parsing ocl in guards
Next Topic:Package as Ocl Context
Goto Forum:
  


Current Time: Mon Dec 22 07:55:21 GMT 2014

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

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