23.08.2013 Views

Specification of Reactive Hardware/Software Systems - Electronic ...

Specification of Reactive Hardware/Software Systems - Electronic ...

Specification of Reactive Hardware/Software Systems - Electronic ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

256 Data Part <strong>of</strong> POOSL<br />

8.7 Example: Complex Numbers<br />

In this paragraph we give an example <strong>of</strong> the calculation <strong>of</strong> the semantics <strong>of</strong> a configuration<br />

representing the addition <strong>of</strong> two complex numbers. A definition <strong>of</strong> a system Sys<br />

which contains a class Complex <strong>of</strong> complex numbers is as follows:<br />

Sys<br />

<br />

data class Complex<br />

instance variables re<br />

im<br />

instance methods init(r¥ i) add(comp)<br />

re : r; ¡ i r res ¡<br />

7<br />

im : i; r : self real (comp real );<br />

self i : self imag (comp imag );<br />

res : new (Complex) init(r¥ i);<br />

real res<br />

re<br />

imag<br />

im<br />

Calculating the sum <strong>of</strong> complex numbers, say (3+4i) and (8+9i), can be performed by<br />

evaluating<br />

( new (Complex) init(3¥ 4)) add( new (Complex) init(8¥ 9))<br />

Syntactic entities 3, 4, 8, and 9 denote the direct naming <strong>of</strong> natural numbers 3, 4, 8 and 9.<br />

The evaluation <strong>of</strong> this expression is reflected by a derivation sequence, starting with<br />

configuration<br />

<br />

( new init(3¥ (Complex) 4)) add( new init(8¥ 9))¥ ¤ ¥ ¥ ¤ ¥ Sys<br />

(Complex)<br />

In this configuration we have put brackets around expression new init(3¥ (Complex) 4),<br />

although they are not part <strong>of</strong> the abstract syntax defined in Section 8.3. Such brackets<br />

are used in ambiguous situations to explain the intended structure <strong>of</strong> expressions or<br />

statements.<br />

To ease readability we represent functions in a way explained by the following example:<br />

Assume<br />

F : A ¦£ (B ¦£ C)<br />

7 Note that instead <strong>of</strong> self real and self imag we could have written re respectively im.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!