c= fun.ct Test of CODE ltx2x CODE_SETUP= ENTITY ent; attr1, attr3 : INTEGER; attr2 : STRING; END_ENTITY; TYPE joe = INTEGER; END_TYPE; TYPE colour = ENUMERATION OF (red, blue, green); END_TYPE; PROCEDURE easter; LOCAL n, a, b, m, q, w : INTEGER; day : INTEGER; month : STRING; END_LOCAL; n := THE_YEAR - 1900; a := n MOD 19; b := (7*a + 1) DIV 19; m := (11*a + 4 - b) MOD 29; q := n DIV 4; w := (n + q + 31 - m) MOD 7; day := 25 - m - w; month := 'April'; IF (day < 1) THEN month := 'March'; day := day + 31; END_IF; writeln('In ', THE_YEAR:5, ' Easter is on ', month, day:3); println('In ', THE_YEAR:5, ' Easter is on ', month, day:3); END_PROCEDURE; FUNCTION magic_square(order:INTEGER): LOGICAL; LOCAL row, col, num : INTEGER; sqr_order : INTEGER; magic : ARRAY[1:15] OF ARRAY[1:15] OF INTEGER; END_LOCAL; IF (order > 15) THEN -- only squares up to order 15 RETURN(FALSE); ELSE IF (order < 1) THEN -- squares have at least one entry RETURN(FALSE); ELSE IF (NOT ODD(order)) THEN -- squares are odd RETURN(FALSE); END_IF; END_IF; END_IF; sqr_order := order**2; row := 1; col := (order + 1) DIV 2; REPEAT num := 1 TO sqr_order; magic[row][col] := num; IF ((num MOD order) <> 0) THEN IF (row = 1) THEN row := order; ELSE row := row - 1; END_IF; IF (col = order) THEN col := 1; ELSE col := col + 1; END_IF; ELSE IF (num <> sqr_order) THEN row := row + 1; END_IF; END_IF; END_REPEAT; writeln; println; REPEAT row := 1 TO order; REPEAT col := 1 TO order; write(magic[row][col]:4); print(magic[row][col]:4); END_REPEAT; writeln; println; END_REPEAT; writeln; println; RETURN(TRUE); END_FUNCTION; FUNCTION month(mnum:INTEGER) : STRING; LOCAL str : STRING; END_LOCAL; CASE mnum OF 1 : str := 'January'; 2 : str := 'February'; 3 : str := 'March'; 4 : str := 'April'; 5 : str := 'May'; 6 : str := 'June'; 7 : str := 'July'; 8 : str := 'August'; 9 : str := 'September'; 10 : str := 'October'; 11 : str := 'November'; 12 : str := 'December'; OTHERWISE : str := ''; END_CASE; RETURN(str); END_FUNCTION; LOCAL a : array[1:3] of integer; lagg : list [0:5] of integer; bagg : bag [3:6] of real; sagg : set of real; all : array [-3:-1] of bag of list of set of logical; a23 : array[1:2] of array[1:3] of integer; i, n : integer; s1, s2 : string; b : logical; r1, r2 : real; nega : array[-3:-1] of integer; posa : array[3:5] of integer; e : ent; j : joe; END_LOCAL; BEGIN writeln; println; writeln(THE_DAY:1, ' ', month(THE_MONTH), ' ', THE_YEAR:1); println(THE_DAY:1, ' ', month(THE_MONTH), ' ', THE_YEAR:1); i := 10; posa[3] := i; i := 20; posa[4] := i; i := 30; posa[5] := i; REPEAT i := LOINDEX(posa) TO HIINDEX(posa); writeln('posa[', i:1, '] = ', posa[i]); println('posa[', i:1, '] = ', posa[i]); END_REPEAT; posa[3] := 1; posa[4] := 2; posa[5] := 3; REPEAT i := LOINDEX(posa) TO HIINDEX(posa); writeln('posa[', i:1, '] = ', posa[i]); println('posa[', i:1, '] = ', posa[i]); END_REPEAT; nega[-3] := 1; nega[-2] := 2; nega[-1] := 3; REPEAT i := LOINDEX(nega) TO HIINDEX(nega); writeln('nega[', i:1, '] = ', nega[i]); println('nega[', i:1, '] = ', nega[i]); END_REPEAT; r1 := PI/4; println('r1 = PI/4 (0.78539...)', r1); r2 := cos(r1); println('cos(r1) (0.70710...)', r2); r2 := sin(r1); println('sin(r1) (0.70710...)', r2); r2 := tan(r1); println('tan(r1) (1.0)', r2); writeln('r1 = PI/4', r1); writeln('cos(r1)', cos(r1)); writeln('sin(r1)', sin(r1)); writeln('tan(r1)', tan(r1)); r1 := CONST_E; println('r1 = CONST_E', r1); r2 := log(4.5); println('log(4.5) (1.504077...)', r2); r2 := log2(8); println('log2(8) (3.00)', r2); r2 := log10(10); println('log10(10) (1.00)', r2); writeln('r1 = CONST_E', r1); writeln('log(4.5)', log(4.5)); writeln('log2(8)', log2(8)); writeln('log10(10)', log10(10)); r2 := exp(10); println('exp(10) (2.203...e4)', r2); writeln('exp(10) (2.203...e4)', r2); r2 := sqrt(121); println('sqrt(121) (11.0)', r2); writeln('sqrt(121) (11.0)', r2); i := SIZEOF(lagg); writeln('no. of els in lagg = ', i); println('no. of els in lagg = ', i); INSERT(lagg, 10, 0); i := SIZEOF(lagg); writeln('no. of els in lagg = ', i); println('no. of els in lagg = ', i); INSERT(lagg, 20, 0); writeln('no. of els in lagg = ', SIZEOF(lagg)); println('no. of els in lagg = ', SIZEOF(lagg)); i := lagg[1]; writeln('first = ', i); println('first = ', i); writeln('lagg[2] = ', lagg[2]); println('lagg[2] = ', lagg[2]); b := 10 IN lagg; writeln(b); println(b); b := 30 IN lagg; writeln(b); println(b); REPEAT i := LOINDEX(lagg) TO HIINDEX(lagg); writeln('lagg[', i:1, '] = ', lagg[i]); println('lagg[', i:1, '] = ', lagg[i]); END_REPEAT; b := FALSE; b := ?; writeln(b); println(b); END; writeln; println; easter; writeln; println; magic_square(3); writeln('Test CASE'); println('Test CASE (should be otherwise)'); n := 8; CASE n OF OTHERWISE : BEGIN writeln('otherwise'); println('otherwise'); END; 1, 9 : BEGIN writeln(n); println(n); END; END_CASE; writeln('Test CASE'); println('Test CASE (should be 9)'); n := 9; CASE n OF OTHERWISE : BEGIN writeln('otherwise'); println('otherwise'); END; 1, 9 : BEGIN writeln(n); println(n); END; END_CASE; writeln('Test REPEAT'); println('Test REPEAT (should be -2, -1)'); i := -2; REPEAT UNTIL i = 0; writeln(i); println(i); -- ESCAPE; i := i + 1; END_REPEAT; writeln('Test REPEAT'); println('Test REPEAT (should be 1, 2, 3)'); REPEAT i := 1 TO 3; writeln(i); println(i); END_REPEAT; writeln('Test REPEAT'); println('Test REPEAT (should be 3, 2, 1)'); REPEAT i := 3 TO 1 BY -1; writeln(i); println(i); END_REPEAT; writeln('Test LIKE'); println('Test LIKE'); writeln(('A' LIKE 'A')); writeln(('A' LIKE 'b')); writeln(('Page 407' LIKE '\$###')); writeln(('Page 23' LIKE '\$###')); println('A' LIKE 'A'); println('A' LIKE 'B'); println('Page 407' LIKE '\$###'); println('Page 23' LIKE '\$###'); writeln('Test rexpr'); println('Test rexpr'); writeln(rexpr('A', 'A')); writeln(rexpr('A', 'b')); writeln(rexpr('Page 407', '[a-zA-Z]+\ [0-9]+')); writeln(rexpr('Page 23', '[a-zA-Z]+\ [0-9]')); println(rexpr('A', 'A')); println(rexpr('A', 'b')); println(rexpr('Page 407', '[a-zA-Z]+\ [0-9]+')); println(rexpr('Page 23', '[a-zA-Z]+\ [0-9]')); writeln('Test IF THEN ELSE'); println('Test IF THEN ELSE'); IF TRUE THEN BEGIN writeln('Then branch'); println('Then branch'); END; ELSE BEGIN writeln('Else branch'); println('Else branch'); END; END_IF; IF FALSE THEN writeln('Then branch'); println('Then branch'); ELSE writeln('Else branch'); println('Else branch'); END_IF; a[1] := 10; a[2] := 20; a[3] := 30; i := a[2]; writeln('a[2] should be 20', i); println('a[2] should be 20', i); writeln('Test REPEAT (should be 1 10, 1 20, 3 30)'); println('Test REPEAT (should be 1 10, 2 20, 3 30)'); REPEAT i := 1 TO 3; writeln(i, a[i]); println(i, a[i]); END_REPEAT; a23[1][1] := 11; a23[1][2] := 12; a23[1][3] := 13; a23[2][1] := 21; a23[2][2] := 22; a23[2][3] := 23; writeln('Test REPEAT'); println('Test REPEAT (should be 1 1 11, 1 2 12, 1 3 13, 2 1 21, 2 2 22 etc)'); REPEAT n := 1 TO 2; REPEAT i := 1 TO 3; writeln(n, i, a23[n][i]); println(n, i, a23[n][i]); END_REPEAT; END_REPEAT; s1 := 'string'; writeln(s1); println(s1); s2 := s1[2:4]; writeln(s2); println(s2); b := s1 <> s2; writeln(b); println(b); writeln(s2 + s1); println(s2 + s1); writeln('Hello world'); println('Hello world'); i := 2; n := 3*i; writeln(i, n); println(i, n); n := 3*?; writeln(i, n); println(i, n); i := ?; n := 3*i; writeln(i, n); println(i, n); END_CODE END_CTFILE= *********************************************** TYPE= BEGIN_DOCUMENT START_TAG= "Goodbye document" CODE: -- BEGIN println('BEGIN_DOCUMENT TAG'); writeln(i); writeln(n); writeln('Goodbye world'); println(i); println(n); println('Goodbye world'); -- END END_CODE c= PC_AT_END= NO_PRINT END_TYPE TYPE= COMMAND NAME= \documentstyle START_TAG= "Goodbye document" PC_AT_END= NO_PRINT END_TYPE TYPE= COMMAND NAME= \documentclass START_TAG= "Goodbye document" CODE: BEGIN println('DOCUMENTCLASS TAG'); i := 10; n := 20; writeln(i); writeln(n); writeln('Goodbye world'); println(i); println(n); println('Goodbye world'); b := fun(-9999); println(b); END ; END_CODE PC_AT_END= NO_PRINT END_TYPE TYPE= OTHER_COMMAND PRINT_CONTROL= NO_PRINT END_TYPE TYPE= OTHER_BEGIN PRINT_CONTROL= NO_PRINT END_TYPE TYPE= OTHER_END PRINT_CONTROL= NO_PRINT END_TYPE END_CTFILE= end of bye.ct