Start of Interpreter for program algarv.tri at Wed May 03 16:01:25 2006

Program

#
READ n
alg:=0
IF (n<2) THEN
GOTO l6pp
alg:=1
i:=2
WHILE (i<n) DO
BEGIN
j:=i
DO
BEGIN
j:=(j+i)
IF (j=n) THEN
BEGIN
alg:=0
GOTO l6pp
END
END
WHILE (j<n)
i:=(i+1)
END
l6pp:
WRITE alg
#

Parsing tree

root
READ
n
:=
alg0
IF
<
n2
GOTO
label
l6pp
:=
alg1
:=
i2
LOOP
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1
label
l6pp
WRITE
alg

Table of constants

c1=0c2=2c3=1

Table of identifiers

i1=ni2=algi3=l6ppi4=ii5=j

label 'l6pp' is address of the operator {kirjutamine} (00420130)

Modified tree

root
READ
n
:=
alg0
IF
<
n2
GOTO
label
l6pp
:=
alg1
:=
i2
LOOP
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1
WRITE
alg


Stackid n=0
interpreting the operator READ n
READ
n
:=
alg0
IF
<
n2
GOTO
label
l6pp
:=
alg1
:=
i2
LOOP
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1
WRITE
alg
Input n=5

Stack

Stackid alg=0

Stackid alg=0const=0
interpreting the operator alg:=0
:=
alg0
IF
<
n2
GOTO
label
l6pp
:=
alg1
:=
i2
LOOP
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1
WRITE
alg

alg:=0

Stack

Stackid n=5

Stackid n=5const=2
interpreting the operator (n<2)
<
n2

5 < 2 ?

Stacktm=0
interpreting the operator IF (n<2) THEN
IF
<
n2
GOTO
label
l6pp
:=
alg1
:=
i2
LOOP
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1
WRITE
alg

Stackid alg=0

Stackid alg=0const=1
interpreting the operator alg:=1
:=
alg1
:=
i2
LOOP
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1
WRITE
alg

alg:=1

Stack

Stackid i=0

Stackid i=0const=2
interpreting the operator i:=2
:=
i2
LOOP
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1
WRITE
alg

i:=2

Stack

Stackid i=2

Stackid i=2id n=5
interpreting the operator (i<n)
<
in

2 < 5 ?

Stacktm=1
interpreting the operator WHILE (i<n)
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1

Stack

Stackid j=0

Stackid j=0id i=2
interpreting the operator j:=i
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1

j:=2

Stack

Stackid j=2

Stackid j=2id j=2

Stackid j=2id j=2id i=2
interpreting the operator (j+i)
+
ji

4 = 2 + 2

Stackid j=2tm=4
interpreting the operator j:=(j+i)
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp

j:=4

Stack

Stackid j=4

Stackid j=4id n=5
interpreting the operator (j=n)
=
jn

4 = 5 ?

Stacktm=0
interpreting the operator IF (j=n) THEN
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
interpreting the operator PLOKK
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn

Stack

Stackid j=4

Stackid j=4id n=5
interpreting the operator (j<n)
<
jn

4 < 5 ?

Stacktm=1
interpreting the operator WHILE (j<n)
WHILE
<
jn

Stack
interpreting the operator DO PLOKK WHILE (j<n)
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1

Stackid j=4

Stackid j=4id j=4

Stackid j=4id j=4id i=2
interpreting the operator (j+i)
+
ji

6 = 4 + 2

Stackid j=4tm=6
interpreting the operator j:=(j+i)
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp

j:=6

Stack

Stackid j=6

Stackid j=6id n=5
interpreting the operator (j=n)
=
jn

6 = 5 ?

Stacktm=0
interpreting the operator IF (j=n) THEN
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
interpreting the operator PLOKK
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn

Stack

Stackid j=6

Stackid j=6id n=5
interpreting the operator (j<n)
<
jn

6 < 5 ?

Stacktm=0
interpreting the operator WHILE (j<n)
WHILE
<
jn

Stackid i=2

Stackid i=2id i=2

Stackid i=2id i=2const=1
interpreting the operator (i+1)
+
i1

3 = 2 + 1

Stackid i=2tm=3
interpreting the operator i:=(i+1)
:=
i+
i1

i:=3

Stack
interpreting the operator PLOKK
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1

Stack
interpreting the operator WHILE (i<n) DO PLOKK
LOOP
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1
WRITE
alg

Stackid i=3

Stackid i=3id n=5
interpreting the operator (i<n)
<
in

3 < 5 ?

Stacktm=1
interpreting the operator WHILE (i<n)
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1

Stack

Stackid j=6

Stackid j=6id i=3
interpreting the operator j:=i
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1

j:=3

Stack

Stackid j=3

Stackid j=3id j=3

Stackid j=3id j=3id i=3
interpreting the operator (j+i)
+
ji

6 = 3 + 3

Stackid j=3tm=6
interpreting the operator j:=(j+i)
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp

j:=6

Stack

Stackid j=6

Stackid j=6id n=5
interpreting the operator (j=n)
=
jn

6 = 5 ?

Stacktm=0
interpreting the operator IF (j=n) THEN
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
interpreting the operator PLOKK
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn

Stack

Stackid j=6

Stackid j=6id n=5
interpreting the operator (j<n)
<
jn

6 < 5 ?

Stacktm=0
interpreting the operator WHILE (j<n)
WHILE
<
jn

Stackid i=3

Stackid i=3id i=3

Stackid i=3id i=3const=1
interpreting the operator (i+1)
+
i1

4 = 3 + 1

Stackid i=3tm=4
interpreting the operator i:=(i+1)
:=
i+
i1

i:=4

Stack
interpreting the operator PLOKK
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1

Stack
interpreting the operator WHILE (i<n) DO PLOKK
LOOP
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1
WRITE
alg

Stackid i=4

Stackid i=4id n=5
interpreting the operator (i<n)
<
in

4 < 5 ?

Stacktm=1
interpreting the operator WHILE (i<n)
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1

Stack

Stackid j=6

Stackid j=6id i=4
interpreting the operator j:=i
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1

j:=4

Stack

Stackid j=4

Stackid j=4id j=4

Stackid j=4id j=4id i=4
interpreting the operator (j+i)
+
ji

8 = 4 + 4

Stackid j=4tm=8
interpreting the operator j:=(j+i)
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp

j:=8

Stack

Stackid j=8

Stackid j=8id n=5
interpreting the operator (j=n)
=
jn

8 = 5 ?

Stacktm=0
interpreting the operator IF (j=n) THEN
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
interpreting the operator PLOKK
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn

Stack

Stackid j=8

Stackid j=8id n=5
interpreting the operator (j<n)
<
jn

8 < 5 ?

Stacktm=0
interpreting the operator WHILE (j<n)
WHILE
<
jn

Stackid i=4

Stackid i=4id i=4

Stackid i=4id i=4const=1
interpreting the operator (i+1)
+
i1

5 = 4 + 1

Stackid i=4tm=5
interpreting the operator i:=(i+1)
:=
i+
i1

i:=5

Stack
interpreting the operator PLOKK
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1

Stack
interpreting the operator WHILE (i<n) DO PLOKK
LOOP
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1
WRITE
alg

Stackid i=5

Stackid i=5id n=5
interpreting the operator (i<n)
<
in

5 < 5 ?

Stacktm=0
interpreting the operator WHILE (i<n)
WHILE
<
in
PLOKK
:=
ji
LOOP
PLOKK
:=
j+
ji
IF
=
jn
PLOKK
:=
alg0
GOTO
label
l6pp
WHILE
<
jn
:=
i+
i1
l6pp:
Stackid alg=1
interpreting the operator WRITE alg
WRITE
alg
Output alg=1

Stack
program algarv.tri is completed

THE VARIABLES:

n=5
alg=1
i=5
j=8

Interpreter ended at Wed May 03 16:01:43 2006