SAN474: Algol60 compiler


Fail Case: 1 Phase: 2a Assign real to integer variable.
begin
integer a;
a := 5.5;
end
ERROR: line 3: attempt to assign real expression '5.500000' to integer variable 'a'.
Fail Case: 2 Phase: 1a Double declaration of differing types.
begin
integer i;
real i;
print 5;
end
ERROR: line 3: attempt to declare already used integer 'i' as real
Fail Case: 3 Phase: 1a Using undeclared variable.
begin
a := 5;
end

ERROR: line 2: cannot assign to undeclared variable 'a'
Fail Case: 4 Phase: 1a Assignment to a number.
begin
integer a;
integer b;
a := 5 := b;
end
ERROR: line 4: cannot assign to the number '5'.
Fail Case: 5 Phase: 2a integer mod real
begin
integer a;
a := 5 % 2.5;
end
ERROR: line 3: cannot modulus reals
Fail Case: 6 Phase: 2a real mod real
begin
real a;
a := 9.0 % 3.0;
end

ERROR: line 3: cannot modulus reals
Fail Case: 7 Phase: 2a Pass test #7 with missing semi-colon before 'end'
begin
integer a;
real b;
a := 5 * 4 + 1 - 20 * 3;
b := a / 4.0 + 3 * 20.2 + a
end
ERROR: line 6: syntax error
Fail Case: 8 Phase: 1a Statements after end of program
begin
integer a;
end
a := 5;
ERROR: line 4: syntax error
Fail Case: 9 Phase: 1a Missing comma in variable declare.
begin
integer a := 5 b := 6;
end

ERROR: line 2: syntax error
Fail Case: 10 Phase: 1a Empty parenthesis.
begin
integer a := 5 + ( ) - 2;
print a;
end
ERROR: line 2: empty expression
Fail Case: 11 Phase: 2a Exponentiation by a real.
begin
print 5 ** 3.5;
end
ERROR: line 2: Exponentiation by a real number is not supported.
Fail Case: 12 Phase: 2a Exponentiation by a variable.
begin
real b := 6.0;
print 5 ** b;
end
ERROR: line 3: Exponentiation by a real number is not supported.
Fail Case: 13 Phase: 1a Double declaration of same type.
begin
integer i;
integer a;
integer i;
print 4;
end
ERROR: line 4: attempt to declare already used integer 'i' as integer
Fail Case: 14 Phase: 3a Missing 'then' in 'if' line.
begin
if 5 > 3 begin
  integer a;
  print a;
  end
end
ERROR: line 2: syntax error
Proposed Fail Case: 15 Phase: 3a Missing 'do' in 'for' line.
begin
integer a;
integer b;
for a := 5 step 1 until 10 begin
  b := b + a;
  end
end
ERROR: line 6: missing 'do' keyword in 'for..step..until'
Proposed Fail Case: 16 Phase: 3a Missing 'step' in 'for..step..until'
begin
  integer a;
  integer b := 0;

  for a := 1 1 until 5 do
  begin
    b := b + a;
  end

  print b;
end
ERROR: line 5: missing 'step' keyword in 'for..step..until'
Proposed Fail Case: 17 Phase: 3a Missing 'until' in 'for..step..until'
begin
  integer a;
  integer b := 0;

  for a := 1 step 1 5 do
  begin
    b := b + a;
  end

  print b;
end
ERROR: line 5: missing 'until' keyword in 'for..step..until'
Fail Case: 18 Phase: 3a Missing 'while' in 'for..while'
begin
  integer a;
  integer b := 0;

  comment
    This should use YACC's 'error' to give
    a decent diagnostic.
  ;
  for a := 20 a > 0 do
  begin
    b := b + 1;
    a := a - 1;
  end

  print b;
end
ERROR: line 17: syntax error
Fail Case: 19 Phase: 4a Procedure in expression context without ().
procedure a()
begin
  integer i := 1;
  print i;
  print a;
end

procedure b()
begin
  real r := 2.0;
  print r;
end

begin
  integer i;
  real r;
  a();
  b();
  print(3);
end

ERROR: line 5: attempt to use procedure 'a' as a variable, use 'a()'.
Fail Case: 20 Phase: 4a Multiple procedure declaration.
procedure a()
begin
  integer i := 1;
  print i;
end

procedure a()
begin
  real r := 2.0;
  print r;
end

begin
  a();
end

ERROR: line 7: attempt to redefine function 'a'.
Fail Case: 21 Phase: 5a Attempt to use non-typed function in expression.
procedure foo()
begin
  print 5;
end

begin
  print foo();
end

ERROR: line 7: attempt to use non-typed function 'foo' in expression
Fail Case: 22 Phase: 5a Testing return type coherence.
procedure real foo()
begin
  foo := 5.5;
end

begin
  integer ret := foo();
end
ERROR: line 7: attempt to assign real value 'foo' to integer variable.
Fail Case: 23 Phase: 5a Passing not enough parameters.
procedure integer bar(integer a, real b)
begin
  print a;
  print b;
end

begin
  print bar(5);
end

ERROR: line 8: too few parameters being passed to 'bar'
Fail Case: 24 Phase: 5a Passing the wrong type of parameters.
procedure real qux(integer a, real b)
begin
  print a;
  print b;
end

begin
  print qux(5.5, 5);
end
ERROR: line 8: param 1 of 'qux' of type 'integer' being passed as 'real'
Fail Case: 25 Phase: 5a Passing too many parameters.
procedure zxc(integer a)
begin
  print a;
end

begin
  zxc(5, 1, 3);
end
ERROR: line 7: too many arguments to function 'zxc'
Pass Case: 1 Phase: 1a Integer assignment to declared variable.
begin
integer a;
a := 5;
print a;
end
declare a&1,integer
store 0,a&1
store 5,a&1
write a&1
halt
Pass Case: 2 Phase: 1a Nested assignment on variable declaration.
begin
integer a;
integer b;
a := 5;
b := 6;
integer c := b := a;
print a;
print b;
print c;
end
declare a&1,integer
store 0,a&1
declare b&1,integer
store 0,b&1
store 5,a&1
store 6,b&1
store a&1,b&1
declare c&1,integer
store b&1,c&1
write a&1
write b&1
write c&1
halt
Pass Case: 3 Phase: 1a Assignment on declaration and nested assignment.
begin
integer a := 5;
integer b := 10;
integer c;
print a;
print b;
print c;
c := a := 15;
print a;
print b;
print c;
end
declare a&1,integer
store 5,a&1
declare b&1,integer
store 10,b&1
declare c&1,integer
store 0,c&1
write a&1
write b&1
write c&1
store 15,a&1
store a&1,c&1
write a&1
write b&1
write c&1
halt
Pass Case: 4 Phase: 1a All integer numerical operations.
begin
integer a := 4;
integer b := 5;
print a;
print b;
a := b + 5 + b - 4 * 2 + b / 3;
print a;
print b;
end
declare a&1,integer
store 4,a&1
declare b&1,integer
store 5,b&1
write a&1
write b&1
declare T&&0,integer
iadd b&1,5,T&&0
declare T&&1,integer
iadd T&&0,b&1,T&&1
declare T&&2,integer
imult 4,2,T&&2
declare T&&3,integer
isub T&&1,T&&2,T&&3
declare T&&4,integer
idiv b&1,3,T&&4
declare T&&5,integer
iadd T&&3,T&&4,T&&5
store T&&5,a&1
write a&1
write b&1
halt
Pass Case: 5 Phase: 1a All real numerical operations.
begin
integer a;
a := 5 * 1 + 4 / 8 - 4 + 20 % 3;
print a;
end
declare a&1,integer
store 0,a&1
declare T&&0,integer
imult 5,1,T&&0
declare T&&1,integer
idiv 4,8,T&&1
declare T&&2,integer
iadd T&&0,T&&1,T&&2
declare T&&3,integer
isub T&&2,4,T&&3
declare T&&4,integer
imod 20,3,T&&4
declare T&&5,integer
iadd T&&3,T&&4,T&&5
store T&&5,a&1
write a&1
halt
Pass Case: 6 Phase: 2a Mixed mode expressions with all operations.
begin
real a;
a := 5.3 * 1.9 + 4.2 /
     8.5 - 4.1 + 20.0;
print a;
end
declare a&1,real
store 0.000000,a&1
declare T&&0,real
rmult 5.300000,1.900000,T&&0
declare T&&1,real
rdiv 4.200000,8.500000,T&&1
declare T&&2,real
radd T&&0,T&&1,T&&2
declare T&&3,real
rsub T&&2,4.100000,T&&3
declare T&&4,real
radd T&&3,20.000000,T&&4
store T&&4,a&1
write a&1
halt
Pass Case: 7 Phase: 2a Mixed mode expressions with two variables and various constant types.
begin
integer a;
real b;
a := 5 * 4 + 1 - 20 * 3;
print a;
b := a / 4.0 + 3 * 20.2 + a;
print b;
end
declare a&1,integer
store 0,a&1
declare b&1,real
store 0.000000,b&1
declare T&&0,integer
imult 5,4,T&&0
declare T&&1,integer
iadd T&&0,1,T&&1
declare T&&2,integer
imult 20,3,T&&2
declare T&&3,integer
isub T&&1,T&&2,T&&3
store T&&3,a&1
write a&1
declare T&&4,real
itor a&1,T&&4
declare T&&5,real
rdiv T&&4,4.000000,T&&5
declare T&&6,real
itor 3,T&&6
declare T&&7,real
rmult T&&6,20.200001,T&&7
declare T&&8,real
radd T&&5,T&&7,T&&8
declare T&&9,real
itor a&1,T&&9
declare T&&10,real
radd T&&8,T&&9,T&&10
store T&&10,b&1
write b&1
halt
Pass Case: 8 Phase: 1a Assigning variables when they're in the expression.
begin
integer a := 20;
integer b := 5;
print a;
print b;
b := a + b - 2 * a;
a := a + 2 * b - 2;
print a;
print b;
end
declare a&1,integer
store 20,a&1
declare b&1,integer
store 5,b&1
write a&1
write b&1
declare T&&0,integer
iadd a&1,b&1,T&&0
declare T&&1,integer
imult 2,a&1,T&&1
declare T&&2,integer
isub T&&0,T&&1,T&&2
store T&&2,b&1
declare T&&3,integer
imult 2,b&1,T&&3
declare T&&4,integer
iadd a&1,T&&3,T&&4
declare T&&5,integer
isub T&&4,2,T&&5
store T&&5,a&1
write a&1
write b&1
halt
Pass Case: 9 Phase: 1a Multiple variable declaration.
begin
integer a, b, c, d, e, f;
end

declare f&1,integer
store 0,f&1
declare e&1,integer
store 0,e&1
declare d&1,integer
store 0,d&1
declare c&1,integer
store 0,c&1
declare b&1,integer
store 0,b&1
declare a&1,integer
store 0,a&1
halt
Pass Case: 10 Phase: 1a Multiple variable declaration and initialization.
begin
integer a := 5, b,
        c := -1, d := 5334, e;
print a;
print b;
print c;
print d;
print e;
end
declare e&1,integer
store 0,e&1
declare d&1,integer
store 5334,d&1
declare c&1,integer
store -1,c&1
declare b&1,integer
store 0,b&1
declare a&1,integer
store 5,a&1
write a&1
write b&1
write c&1
write d&1
write e&1
halt
Pass Case: 11 Phase: 1a Parenthesis precendence.
begin
integer a := 5 * (2 + 2) /
             (10 % 3) *
	     (2 - -3 * -4);
print a;
end
declare T&&0,integer
iadd 2,2,T&&0
declare T&&1,integer
imult 5,T&&0,T&&1
declare T&&2,integer
imod 10,3,T&&2
declare T&&3,integer
idiv T&&1,T&&2,T&&3
declare T&&4,integer
imult -3,-4,T&&4
declare T&&5,integer
isub 2,T&&4,T&&5
declare T&&6,integer
imult T&&3,T&&5,T&&6
declare a&1,integer
store T&&6,a&1
write a&1
halt
Pass Case: 12 Phase: 1a Single-line comments.
# new program
/* declare some variables */ begin
real /* embedded comment */
     j;  // It's j
real r; /* another generic real */
r := j := 4.0; # make them both 4
end // end the program
declare j&1,real
store 0.000000,j&1
declare r&1,real
store 0.000000,r&1
store 4.000000,j&1
store j&1,r&1
halt
Pass Case: 13 Phase: 2a Exponentiation of integers.
begin
integer a;
a := 5 ** 6;
print a;
a := 2 ** 2;
print a;
end

declare a&1,integer
store 0,a&1
declare T&&0,integer
store 1,T&&0
declare T&&1,integer
equ 6,0,T&&1
jt T&&1,:expoutT&&0
store 5,T&&0
declare T&&2,integer
equ 6,1,T&&2
jt T&&2,:expoutT&&0
declare T&&3,integer
store 6,T&&3
:expT&&0
declare T&&4,integer
imult T&&0,5,T&&4
store T&&4,T&&0
declare T&&5,integer
isub T&&3,1,T&&5
store T&&5,T&&3
declare T&&6,integer
equ T&&3,1,T&&6
jf T&&6,:expT&&0
:expoutT&&0
store T&&0,a&1
write a&1
declare T&&7,integer
store 1,T&&7
declare T&&8,integer
equ 2,0,T&&8
jt T&&8,:expoutT&&7
store 2,T&&7
declare T&&9,integer
equ 2,1,T&&9
jt T&&9,:expoutT&&7
declare T&&10,integer
store 2,T&&10
:expT&&7
declare T&&11,integer
imult T&&7,2,T&&11
store T&&11,T&&7
declare T&&12,integer
isub T&&10,1,T&&12
store T&&12,T&&10
declare T&&13,integer
equ T&&10,1,T&&13
jf T&&13,:expT&&7
:expoutT&&7
store T&&7,a&1
write a&1
halt
Pass Case: 14 Phase: 2a Exponentiation of reals.
begin
real b;
b := 3.5 ** 5;
print b;
b := 8.3 ** 6;
print b;
end
declare b&1,real
store 0.000000,b&1
declare T&&0,real
declare T&&1,real
itor 1,T&&1
store T&&1,T&&0
declare T&&2,integer
equ 5,0,T&&2
jt T&&2,:expoutT&&0
store 3.500000,T&&0
declare T&&3,integer
equ 5,1,T&&3
jt T&&3,:expoutT&&0
declare T&&4,integer
store 5,T&&4
:expT&&0
declare T&&5,real
rmult T&&0,3.500000,T&&5
store T&&5,T&&0
declare T&&6,integer
isub T&&4,1,T&&6
store T&&6,T&&4
declare T&&7,integer
equ T&&4,1,T&&7
jf T&&7,:expT&&0
:expoutT&&0
store T&&0,b&1
write b&1
declare T&&8,real
declare T&&9,real
itor 1,T&&9
store T&&9,T&&8
declare T&&10,integer
equ 6,0,T&&10
jt T&&10,:expoutT&&8
store 8.300000,T&&8
declare T&&11,integer
equ 6,1,T&&11
jt T&&11,:expoutT&&8
declare T&&12,integer
store 6,T&&12
:expT&&8
declare T&&13,real
rmult T&&8,8.300000,T&&13
store T&&13,T&&8
declare T&&14,integer
isub T&&12,1,T&&14
store T&&14,T&&12
declare T&&15,integer
equ T&&12,1,T&&15
jf T&&15,:expT&&8
:expoutT&&8
store T&&8,b&1
write b&1
halt
Pass Case: 15 Phase: 2a Exponentiation in complex expression.
begin
print 5 ** 2 + 6 ** 2 + 7 ** 2;
end
declare T&&0,integer
store 1,T&&0
declare T&&1,integer
equ 2,0,T&&1
jt T&&1,:expoutT&&0
store 5,T&&0
declare T&&2,integer
equ 2,1,T&&2
jt T&&2,:expoutT&&0
declare T&&3,integer
store 2,T&&3
:expT&&0
declare T&&4,integer
imult T&&0,5,T&&4
store T&&4,T&&0
declare T&&5,integer
isub T&&3,1,T&&5
store T&&5,T&&3
declare T&&6,integer
equ T&&3,1,T&&6
jf T&&6,:expT&&0
:expoutT&&0
declare T&&7,integer
store 1,T&&7
declare T&&8,integer
equ 2,0,T&&8
jt T&&8,:expoutT&&7
store 6,T&&7
declare T&&9,integer
equ 2,1,T&&9
jt T&&9,:expoutT&&7
declare T&&10,integer
store 2,T&&10
:expT&&7
declare T&&11,integer
imult T&&7,6,T&&11
store T&&11,T&&7
declare T&&12,integer
isub T&&10,1,T&&12
store T&&12,T&&10
declare T&&13,integer
equ T&&10,1,T&&13
jf T&&13,:expT&&7
:expoutT&&7
declare T&&14,integer
iadd T&&0,T&&7,T&&14
declare T&&15,integer
store 1,T&&15
declare T&&16,integer
equ 2,0,T&&16
jt T&&16,:expoutT&&15
store 7,T&&15
declare T&&17,integer
equ 2,1,T&&17
jt T&&17,:expoutT&&15
declare T&&18,integer
store 2,T&&18
:expT&&15
declare T&&19,integer
imult T&&15,7,T&&19
store T&&19,T&&15
declare T&&20,integer
isub T&&18,1,T&&20
store T&&20,T&&18
declare T&&21,integer
equ T&&18,1,T&&21
jf T&&21,:expT&&15
:expoutT&&15
declare T&&22,integer
iadd T&&14,T&&15,T&&22
write T&&22
halt
Pass Case: 16 Phase: 1a Block commented out program.
/*
begin
integer a := 5, b,
        c := -1, d := 5334, e;
print a;
print b;
print c;
print d;
print e;
end
*/
begin
print 5;
end

write 5
halt
Pass Case: 17 Phase: 2a Assignment of integer values to real variables.
begin
integer i:=5;
real r:=i;
print r;
real d:=5;
print d;
end
declare i&1,integer
store 5,i&1
declare T&&0,real
itor i&1,T&&0
declare r&1,real
store T&&0,r&1
write r&1
declare T&&1,real
itor 5,T&&1
declare d&1,real
store T&&1,d&1
write d&1
halt
Pass Case: 18 Phase: 2a Logical operations (and, or, not).
begin
integer i;
i:= 1 and 2;
i:= 2 or 3;
i:= not 1;
end
declare i&1,integer
store 0,i&1
declare T&&0,integer
and 1,2,T&&0
store T&&0,i&1
declare T&&1,integer
or 2,3,T&&1
store T&&1,i&1
declare T&&2,integer
not 1,T&&2
store T&&2,i&1
halt
Pass Case: 19 Phase: 3a tests for less than or equal to
begin
print 5 <= 3;
print 3 <= 5;
print 10 <= 10;
print -5 <= 4;
print 0 <= -0;
print 25 <= 23;
end
declare T&&0,integer
low 5,3,T&&0
declare T&&1,integer
equ 5,3,T&&1
declare T&&2,integer
or T&&0,T&&1,T&&2
write T&&2
declare T&&3,integer
low 3,5,T&&3
declare T&&4,integer
equ 3,5,T&&4
declare T&&5,integer
or T&&3,T&&4,T&&5
write T&&5
declare T&&6,integer
low 10,10,T&&6
declare T&&7,integer
equ 10,10,T&&7
declare T&&8,integer
or T&&6,T&&7,T&&8
write T&&8
declare T&&9,integer
low -5,4,T&&9
declare T&&10,integer
equ -5,4,T&&10
declare T&&11,integer
or T&&9,T&&10,T&&11
write T&&11
declare T&&12,integer
low 0,0,T&&12
declare T&&13,integer
equ 0,0,T&&13
declare T&&14,integer
or T&&12,T&&13,T&&14
write T&&14
declare T&&15,integer
low 25,23,T&&15
declare T&&16,integer
equ 25,23,T&&16
declare T&&17,integer
or T&&15,T&&16,T&&17
write T&&17
halt
Pass Case: 20 Phase: 3a test for less than
begin
print 5 < 3;
print 3 < 5;
print 10 < 10;
print -5 < 4;
print 0 < -0;
print 25 < 23;
end
declare T&&0,integer
low 5,3,T&&0
write T&&0
declare T&&1,integer
low 3,5,T&&1
write T&&1
declare T&&2,integer
low 10,10,T&&2
write T&&2
declare T&&3,integer
low -5,4,T&&3
write T&&3
declare T&&4,integer
low 0,0,T&&4
write T&&4
declare T&&5,integer
low 25,23,T&&5
write T&&5
halt
Pass Case: 21 Phase: 3a tests for equal comparison
begin
print 5 == 3;
print 3 == 5;
print 10 == 10;
print -5 == 4;
print 0 == -0;
print 25 == 23;
end
declare T&&0,integer
equ 5,3,T&&0
write T&&0
declare T&&1,integer
equ 3,5,T&&1
write T&&1
declare T&&2,integer
equ 10,10,T&&2
write T&&2
declare T&&3,integer
equ -5,4,T&&3
write T&&3
declare T&&4,integer
equ 0,0,T&&4
write T&&4
declare T&&5,integer
equ 25,23,T&&5
write T&&5
halt
Pass Case: 22 Phase: 3a tests for not equal comparison
begin
print 5 != 3;
print 3 != 5;
print 10 != 10;
print -5 != 4;
print 0 != -0;
print 25 != 23;
end
declare T&&0,integer
equ 5,3,T&&0
declare T&&1,integer
not T&&0,T&&1
write T&&1
declare T&&2,integer
equ 3,5,T&&2
declare T&&3,integer
not T&&2,T&&3
write T&&3
declare T&&4,integer
equ 10,10,T&&4
declare T&&5,integer
not T&&4,T&&5
write T&&5
declare T&&6,integer
equ -5,4,T&&6
declare T&&7,integer
not T&&6,T&&7
write T&&7
declare T&&8,integer
equ 0,0,T&&8
declare T&&9,integer
not T&&8,T&&9
write T&&9
declare T&&10,integer
equ 25,23,T&&10
declare T&&11,integer
not T&&10,T&&11
write T&&11
halt
Pass Case: 23 Phase: 3a test for greater than
begin
print 5 > 3;
print 3 > 5;
print 10 > 10;
print -5 > 4;
print 0 > -0;
print 25 > 23;
end
declare T&&0,integer
high 5,3,T&&0
write T&&0
declare T&&1,integer
high 3,5,T&&1
write T&&1
declare T&&2,integer
high 10,10,T&&2
write T&&2
declare T&&3,integer
high -5,4,T&&3
write T&&3
declare T&&4,integer
high 0,0,T&&4
write T&&4
declare T&&5,integer
high 25,23,T&&5
write T&&5
halt
Pass Case: 24 Phase: 3a test for greater than or equal to
begin
print 5 >= 3;
print 3 >= 5;
print 10 >= 10;
print -5 >= 4;
print 0 >= -0;
print 25 >= 23;
end
declare T&&0,integer
high 5,3,T&&0
declare T&&1,integer
equ 5,3,T&&1
declare T&&2,integer
or T&&0,T&&1,T&&2
write T&&2
declare T&&3,integer
high 3,5,T&&3
declare T&&4,integer
equ 3,5,T&&4
declare T&&5,integer
or T&&3,T&&4,T&&5
write T&&5
declare T&&6,integer
high 10,10,T&&6
declare T&&7,integer
equ 10,10,T&&7
declare T&&8,integer
or T&&6,T&&7,T&&8
write T&&8
declare T&&9,integer
high -5,4,T&&9
declare T&&10,integer
equ -5,4,T&&10
declare T&&11,integer
or T&&9,T&&10,T&&11
write T&&11
declare T&&12,integer
high 0,0,T&&12
declare T&&13,integer
equ 0,0,T&&13
declare T&&14,integer
or T&&12,T&&13,T&&14
write T&&14
declare T&&15,integer
high 25,23,T&&15
declare T&&16,integer
equ 25,23,T&&16
declare T&&17,integer
or T&&15,T&&16,T&&17
write T&&17
halt
Pass Case: 25 Phase: 3a 'for' with positive 'step' and 'until'.
begin
  integer a;
  integer b := 0;

  for a := 1 step 1 until a == 5 do
  begin
    b := b + a;
  end

  print b;
end
declare a&1,integer
store 0,a&1
declare b&1,integer
store 0,b&1
store 1,a&1
:label&&0
declare T&&0,integer
equ a&1,5,T&&0
jt T&&0,:label&&1
declare T&&1,integer
iadd b&1,a&1,T&&1
store T&&1,b&1
declare T&&2,integer
iadd 1,a&1,T&&2
store T&&2,a&1
jmp :label&&0
:label&&1
write b&1
halt
Pass Case: 26 Phase: 3a 'for' with 'while'.
begin
  integer a;
  integer b := 0;

  for a := 20 while a > 0 do
  begin
    b := b + 1;
    a := a - 1;
  end

  print b;
end
declare a&1,integer
store 0,a&1
declare b&1,integer
store 0,b&1
store 20,a&1
:label&&0
declare T&&0,integer
high a&1,0,T&&0
jf T&&0,:label&&1
declare T&&1,integer
iadd b&1,1,T&&1
store T&&1,b&1
declare T&&2,integer
isub a&1,1,T&&2
store T&&2,a&1
jmp :label&&0
:label&&1
write b&1
halt
Pass Case: 27 Phase: 3a 'for' with just arithmetic expression.
begin
  integer a;

  for a := 5 do
  begin
    print a;
  end
end
declare a&1,integer
store 0,a&1
store 5,a&1
write a&1
halt
Pass Case: 28 Phase: 3a 'for' with negative 'step' and 'until'.
begin
  integer a;
  integer b := 0;

  for a := 5 step -1 until a == 0 do
  begin
    b := b + a;
  end

  print b;
end
declare a&1,integer
store 0,a&1
declare b&1,integer
store 0,b&1
store 5,a&1
:label&&0
declare T&&0,integer
equ a&1,0,T&&0
jt T&&0,:label&&1
declare T&&1,integer
iadd b&1,a&1,T&&1
store T&&1,b&1
declare T&&2,integer
iadd -1,a&1,T&&2
store T&&2,a&1
jmp :label&&0
:label&&1
write b&1
halt
Pass Case: 29 Phase: 3a 'if' statement
begin
  integer i:=5;

  if i<6 then
  begin
    print i;
  end
end

declare i&1,integer
store 5,i&1
declare T&&0,integer
low i&1,6,T&&0
jf T&&0, :label&&0
write i&1
:label&&0
halt
Pass Case: 30 Phase: 3a 'if'..'else' statment
// should output 1 and 2
begin
  // 'if'..'else' using then block
  if 1 > 0 then
  begin
    print 1;
  end
  else
  begin
    print 2;
  end

  // 'if'..'else' using else block
  if 0 > 1 then
  begin
    print 1;
  end
  else
  begin
    print 2;
  end
end
declare T&&0,integer
high 1,0,T&&0
jf T&&0, :label&&0
write 1
jmp :label&&1
:label&&0
write 2
:label&&1
declare T&&1,integer
high 0,1,T&&1
jf T&&1, :label&&2
write 1
jmp :label&&3
:label&&2
write 2
:label&&3
halt
Pass Case: 31 Phase: 3a 'if' with nested 'if'
begin
  integer i:=3;
  integer j:=4;
 
  if i > 2 then
  begin
    if j < 5 then
    begin
      print 1;
    end
  end
end
declare i&1,integer
store 3,i&1
declare j&1,integer
store 4,j&1
declare T&&0,integer
high i&1,2,T&&0
jf T&&0, :label&&0
declare T&&1,integer
low j&1,5,T&&1
jf T&&1, :label&&1
write 1
:label&&1
:label&&0
halt
Pass Case: 32 Phase: 3a 'if'..'else' with nested 'if'
begin
  if 1 > 0 then
  begin
    print 1;
    if 0 < 1 then
    begin
      print 2;
    end
  end
  else 
  begin
    print -1;
  end

  if 0 > 1 then
  begin
    print -1;
  end
  else
  begin
    print 1;
    if 0 < 1 then
    begin
      print 2;
    end
  end
end
declare T&&0,integer
high 1,0,T&&0
jf T&&0, :label&&0
write 1
declare T&&1,integer
low 0,1,T&&1
jf T&&1, :label&&1
write 2
:label&&1
jmp :label&&2
:label&&0
write -1
:label&&2
declare T&&2,integer
high 0,1,T&&2
jf T&&2, :label&&3
write -1
jmp :label&&4
:label&&3
write 1
declare T&&3,integer
low 0,1,T&&3
jf T&&3, :label&&5
write 2
:label&&5
:label&&4
halt
Pass Case: 33 Phase: 3a 'if'..'else' with nested 'if'..'else'
begin
  if 1 > 0 then
  begin
    print 1;

    if 0 > 1 then
    begin
      print 2;
    end
    else
    begin
      print 3;
    end
  end
  else 
  begin
    print -1;
  end

  if 0 > 1 then
  begin
    print -1;
  end
  else
  begin
    print 1;

    if 0 > 1 then
    begin
      print 2;
    end
    else
    begin
      print 3;
    end
  end
end
declare T&&0,integer
high 1,0,T&&0
jf T&&0, :label&&0
write 1
declare T&&1,integer
high 0,1,T&&1
jf T&&1, :label&&1
write 2
jmp :label&&2
:label&&1
write 3
:label&&2
jmp :label&&3
:label&&0
write -1
:label&&3
declare T&&2,integer
high 0,1,T&&2
jf T&&2, :label&&4
write -1
jmp :label&&5
:label&&4
write 1
declare T&&3,integer
high 0,1,T&&3
jf T&&3, :label&&6
write 2
jmp :label&&7
:label&&6
write 3
:label&&7
:label&&5
halt
Pass Case: 34 Phase: 4a Procedure with a 'for' loop.
procedure abcd()
begin
  integer a;
  for a := 5 while a >= 0 do
  begin
    a := a - 1;
  end
  print a;
end

begin
  real a;
  a := 5.5;
  print a;
  abcd();
end
jmp :start&
:abcd&0
declare a&1,integer
store 0,a&1
store 5,a&1
:label&&0
declare T&&0,integer
high a&1,0,T&&0
declare T&&1,integer
equ a&1,0,T&&1
declare T&&2,integer
or T&&0,T&&1,T&&2
jf T&&2,:label&&1
declare T&&3,integer
isub a&1,1,T&&3
store T&&3,a&1
jmp :label&&0
:label&&1
write a&1
return
:start&
declare a&3,real
store 0.000000,a&3
store 5.500000,a&3
write a&3
call :abcd&0
halt
Pass Case: 35 Phase: 4a Procedure with a variable and print.
procedure p()
begin
  integer i := 10;
  print i;
end
begin
 p();
end
jmp :start&
:p&0
declare i&1,integer
store 10,i&1
write i&1
return
:start&
call :p&0
halt
Pass Case: 36 Phase: 4a Multiple procedures with a 'for' loop.
/* test multiple procedures,
   blocks within procedures,
   and localization of
   variables
*/

procedure a()
begin
  integer i := 1;
  print i;
end

procedure b()
begin
  real r := 2.0;
  print r;
end

procedure c()
begin
  integer i;
  for i := 3 step 1 until i == 10 do
  begin
    integer tmp := i;
    integer i := 0;
    print tmp;
  end
end

begin
  integer i;
  real r;
  a();
  b();
  c();
  print 10;
end
jmp :start&
:a&0
declare i&1,integer
store 1,i&1
write i&1
return
:b&0
declare r&2,real
store 2.000000,r&2
write r&2
return
:c&0
declare i&3,integer
store 0,i&3
store 3,i&3
:label&&0
declare T&&0,integer
equ i&3,10,T&&0
jt T&&0,:label&&1
declare tmp&4,integer
store i&3,tmp&4
declare i&4,integer
store 0,i&4
write tmp&4
declare T&&1,integer
iadd 1,i&3,T&&1
store T&&1,i&3
jmp :label&&0
:label&&1
return
:start&
declare i&5,integer
store 0,i&5
declare r&5,real
store 0.000000,r&5
call :a&0
call :b&0
call :c&0
write 10
halt
Pass Case: 37 Phase: 4a Variable shadowing in procedures.
/* localization of variables */

procedure a()
begin
  integer i;
  for i := 0 step 1 until i == 10 do
  begin
    integer tmp := i;
    integer i := 0;
    print tmp;
  end
end

begin
  integer i;
  real r;
  a();
  print 10;
end

jmp :start&
:a&0
declare i&1,integer
store 0,i&1
store 0,i&1
:label&&0
declare T&&0,integer
equ i&1,10,T&&0
jt T&&0,:label&&1
declare tmp&2,integer
store i&1,tmp&2
declare i&2,integer
store 0,i&2
write tmp&2
declare T&&1,integer
iadd 1,i&1,T&&1
store T&&1,i&1
jmp :label&&0
:label&&1
return
:start&
declare i&3,integer
store 0,i&3
declare r&3,real
store 0.000000,r&3
call :a&0
write 10
halt
Pass Case: 38 Phase: 5a Return value from procedure
procedure integer a()
begin
  a := 5;
end

begin
  print a();
end

jmp :start&
:a&0
store 5,a&0_0
return
:start&
declare a&0_0,integer
call :a&0
write a&0_0
halt
Pass Case: 39 Phase: 3a Massive Exponentiation
begin
  print 2**32;
  print 2**30;
  print 2**31;
  print 2**29;
  print 1**100000;
  print 0**50;
  print 50**2;
  print 12345**1;
  print 93839**0;
end
declare T&&0,integer
store 1,T&&0
declare T&&1,integer
equ 32,0,T&&1
jt T&&1,:expoutT&&0
store 2,T&&0
declare T&&2,integer
equ 32,1,T&&2
jt T&&2,:expoutT&&0
declare T&&3,integer
store 32,T&&3
:expT&&0
declare T&&4,integer
imult T&&0,2,T&&4
store T&&4,T&&0
declare T&&5,integer
isub T&&3,1,T&&5
store T&&5,T&&3
declare T&&6,integer
equ T&&3,1,T&&6
jf T&&6,:expT&&0
:expoutT&&0
write T&&0
declare T&&7,integer
store 1,T&&7
declare T&&8,integer
equ 30,0,T&&8
jt T&&8,:expoutT&&7
store 2,T&&7
declare T&&9,integer
equ 30,1,T&&9
jt T&&9,:expoutT&&7
declare T&&10,integer
store 30,T&&10
:expT&&7
declare T&&11,integer
imult T&&7,2,T&&11
store T&&11,T&&7
declare T&&12,integer
isub T&&10,1,T&&12
store T&&12,T&&10
declare T&&13,integer
equ T&&10,1,T&&13
jf T&&13,:expT&&7
:expoutT&&7
write T&&7
declare T&&14,integer
store 1,T&&14
declare T&&15,integer
equ 31,0,T&&15
jt T&&15,:expoutT&&14
store 2,T&&14
declare T&&16,integer
equ 31,1,T&&16
jt T&&16,:expoutT&&14
declare T&&17,integer
store 31,T&&17
:expT&&14
declare T&&18,integer
imult T&&14,2,T&&18
store T&&18,T&&14
declare T&&19,integer
isub T&&17,1,T&&19
store T&&19,T&&17
declare T&&20,integer
equ T&&17,1,T&&20
jf T&&20,:expT&&14
:expoutT&&14
write T&&14
declare T&&21,integer
store 1,T&&21
declare T&&22,integer
equ 29,0,T&&22
jt T&&22,:expoutT&&21
store 2,T&&21
declare T&&23,integer
equ 29,1,T&&23
jt T&&23,:expoutT&&21
declare T&&24,integer
store 29,T&&24
:expT&&21
declare T&&25,integer
imult T&&21,2,T&&25
store T&&25,T&&21
declare T&&26,integer
isub T&&24,1,T&&26
store T&&26,T&&24
declare T&&27,integer
equ T&&24,1,T&&27
jf T&&27,:expT&&21
:expoutT&&21
write T&&21
declare T&&28,integer
store 1,T&&28
declare T&&29,integer
equ 100000,0,T&&29
jt T&&29,:expoutT&&28
store 1,T&&28
declare T&&30,integer
equ 100000,1,T&&30
jt T&&30,:expoutT&&28
declare T&&31,integer
store 100000,T&&31
:expT&&28
declare T&&32,integer
imult T&&28,1,T&&32
store T&&32,T&&28
declare T&&33,integer
isub T&&31,1,T&&33
store T&&33,T&&31
declare T&&34,integer
equ T&&31,1,T&&34
jf T&&34,:expT&&28
:expoutT&&28
write T&&28
declare T&&35,integer
store 1,T&&35
declare T&&36,integer
equ 50,0,T&&36
jt T&&36,:expoutT&&35
store 0,T&&35
declare T&&37,integer
equ 50,1,T&&37
jt T&&37,:expoutT&&35
declare T&&38,integer
store 50,T&&38
:expT&&35
declare T&&39,integer
imult T&&35,0,T&&39
store T&&39,T&&35
declare T&&40,integer
isub T&&38,1,T&&40
store T&&40,T&&38
declare T&&41,integer
equ T&&38,1,T&&41
jf T&&41,:expT&&35
:expoutT&&35
write T&&35
declare T&&42,integer
store 1,T&&42
declare T&&43,integer
equ 2,0,T&&43
jt T&&43,:expoutT&&42
store 50,T&&42
declare T&&44,integer
equ 2,1,T&&44
jt T&&44,:expoutT&&42
declare T&&45,integer
store 2,T&&45
:expT&&42
declare T&&46,integer
imult T&&42,50,T&&46
store T&&46,T&&42
declare T&&47,integer
isub T&&45,1,T&&47
store T&&47,T&&45
declare T&&48,integer
equ T&&45,1,T&&48
jf T&&48,:expT&&42
:expoutT&&42
write T&&42
write 12345
write 1
halt
Pass Case: 40 Phase: 5a Reference parameters
procedure wr(integer i byref, real r byref,
             integer noref byval)
begin
  i := i + 1;
  r := r + 1.0;
  noref := noref + 1;
end

begin
  integer i;
  real r;
  integer noref;

  print i; 
  print r;
  print noref;
  
  wr(i, r, noref);
  
  print i;
  print r;
  print noref;
end
jmp :start&
:wr&0
declare i&0,integer
store wr&0_1,i&0
declare r&0,real
store wr&0_2,r&0
declare noref&0,integer
store wr&0_3,noref&0
declare T&&0,integer
iadd i&0,1,T&&0
store T&&0,i&0
declare T&&1,real
radd r&0,1.000000,T&&1
store T&&1,r&0
declare T&&2,integer
iadd noref&0,1,T&&2
store T&&2,noref&0
store i&0,wr&0_1
store r&0,wr&0_2
return
:start&
declare wr&0_1,integer
declare wr&0_2,real
declare wr&0_3,integer
declare i&2,integer
store 0,i&2
declare r&2,real
store 0.000000,r&2
declare noref&2,integer
store 0,noref&2
write i&2
write r&2
write noref&2
store i&2,wr&0_1
store r&2,wr&0_2
store noref&2,wr&0_3
call :wr&0
store wr&0_1,i&2
store wr&0_2,r&2
write i&2
write r&2
write noref&2
halt