changed tabs with spaces

This commit is contained in:
antranigv 2017-06-09 13:10:12 +04:00
parent e49b38df73
commit d110fb0ac8
No known key found for this signature in database
GPG key ID: 60686B14DAB81456
12 changed files with 132 additions and 119 deletions

View file

@ -3,40 +3,40 @@ MODULE arrays;
IMPORT Out; IMPORT Out;
VAR VAR
tmp : INTEGER; tmp : INTEGER;
matrix : ARRAY 3 OF ARRAY 3 OF INTEGER; matrix : ARRAY 3 OF ARRAY 3 OF INTEGER;
i, v, k : INTEGER; i, v, k : INTEGER;
BEGIN BEGIN
v := 1; v := 1;
FOR i := 0 TO LEN(matrix) - 1 DO FOR i := 0 TO LEN(matrix) - 1 DO
FOR k := 0 TO LEN(matrix[i]) - 1 DO FOR k := 0 TO LEN(matrix[i]) - 1 DO
matrix[i][k] := v; matrix[i][k] := v;
INC(v); INC(v);
END; END;
END; END;
FOR i := 0 TO LEN(matrix) - 1 DO FOR i := 0 TO LEN(matrix) - 1 DO
FOR k := 0 TO LEN(matrix[i]) - 1 DO FOR k := 0 TO LEN(matrix[i]) - 1 DO
Out.Int(matrix[i][k], 0); Out.String(" "); Out.Int(matrix[i][k], 0); Out.String(" ");
END; END;
Out.Ln; Out.Ln;
END; END;
FOR i := 0 TO LEN(matrix) - 1 DO FOR i := 0 TO LEN(matrix) - 1 DO
FOR k := i + 1 TO LEN(matrix[i]) - 1 DO FOR k := i + 1 TO LEN(matrix[i]) - 1 DO
tmp := matrix[i][k]; tmp := matrix[i][k];
matrix[i][k] := matrix[k][i]; matrix[i][k] := matrix[k][i];
matrix[k][i] := tmp; matrix[k][i] := tmp;
END; END;
END; END;
Out.Ln; Out.Ln; Out.Ln; Out.Ln;
FOR i := 0 TO LEN(matrix) - 1 DO FOR i := 0 TO LEN(matrix) - 1 DO
FOR k := 0 TO LEN(matrix[i]) - 1 DO FOR k := 0 TO LEN(matrix[i]) - 1 DO
Out.Int(matrix[i][k], 0); Out.String(" "); Out.Int(matrix[i][k], 0); Out.String(" ");
END; END;
Out.Ln; Out.Ln;
END; END;
END arrays. END arrays.

View file

@ -5,10 +5,10 @@ IMPORT Out, Modules;
BEGIN BEGIN
CASE Modules.ArgCount - 1 OF CASE Modules.ArgCount - 1 OF
0 : Out.String("There are no arguments"); 0 : Out.String("There are no arguments");
| 1 : Out.String("There is one argument"); | 1 : Out.String("There is one argument");
| 2 : Out.String("There are two arguments"); | 2 : Out.String("There are two arguments");
ELSE Out.String("There are more than two arguments") END; ELSE Out.String("There are more than two arguments") END;
Out.Ln; Out.Ln;
END case. END case.

View file

@ -3,12 +3,12 @@ MODULE constants;
IMPORT Out; IMPORT Out;
CONST CONST
s = "if it moves, compile it!"; s = "if it moves, compile it!";
n = 42; n = 42;
m = n * 2; m = n * 2;
BEGIN BEGIN
Out.String(s); Out.Ln; Out.String(s); Out.Ln;
Out.Int(n, 0); Out.Ln; Out.Int(n, 0); Out.Ln;
Out.Int(m, 0); Out.Ln; Out.Int(m, 0); Out.Ln;
END constants. END constants.

View file

@ -3,17 +3,17 @@ MODULE for;
IMPORT Out; IMPORT Out;
VAR VAR
i : INTEGER; i : INTEGER;
BEGIN BEGIN
Out.String("i is "); Out.Int(i, 0); Out.Ln; Out.String("i is "); Out.Int(i, 0); Out.Ln;
Out.String("For loop started"); Out.Ln; Out.String("For loop started"); Out.Ln;
FOR i := 0 TO 10 DO FOR i := 0 TO 10 DO
Out.String("i : "); Out.Int(i, 0); Out.Ln; Out.String("i : "); Out.Int(i, 0); Out.Ln;
END; END;
Out.String("For-By loop started"); Out.Ln; Out.String("For-By loop started"); Out.Ln;
FOR i := 0 TO 10 BY 2 DO FOR i := 0 TO 10 BY 2 DO
Out.String("i : "); Out.Int(i, 0); Out.Ln; Out.String("i : "); Out.Int(i, 0); Out.Ln;
END; END;
END for. END for.

View file

@ -5,6 +5,6 @@ IMPORT Console;
BEGIN BEGIN
Console.String("Hello World!"); Console.String("Hello World!");
Console.Ln Console.Ln
END hello. END hello.

View file

@ -5,5 +5,5 @@ IMPORT Out;
BEGIN BEGIN
Out.String("Hello, World"); Out.Ln Out.String("Hello, World"); Out.Ln
END hello. END hello.

View file

@ -7,36 +7,43 @@ VAR n, m : INTEGER;
BEGIN BEGIN
n := 8; m := 4; n := 8; m := 4;
IF n MOD m = 0 THEN IF n MOD m = 0 THEN
Out.Int(n,0); Out.String(" is divisible by "); Out.Int(m,0); Out.Ln; Out.Int(n,0); Out.String(" is divisible by "); Out.Int(m,0); Out.Ln;
END; END;
n := 7; m := 6; n := 7; m := 6;
IF n * m = 42 THEN IF n * m = 42 THEN
Out.Int(n,0); Out.String(" times "); Out.Int(m,0); Out.String(" equals 42"); Out.Ln; Out.Int(n,0); Out.String(" times "); Out.Int(m,0); Out.String(" equals 42"); Out.Ln;
END; END;
IF n # m THEN Out.Int(n,0); Out.String(" does not equal "); Out.Int(m,0); Out.Ln; END; IF n # m THEN Out.Int(n,0); Out.String(" does not equal "); Out.Int(m,0); Out.Ln; END;
IF ODD(n) IF ODD(n)
THEN THEN
Out.Int(n,0); Out.String(" is odd"); Out.Ln; Out.Int(n,0); Out.String(" is odd"); Out.Ln;
ELSE ELSE
Out.Int(n,0); Out.String(" is even"); Out.Ln; Out.Int(n,0); Out.String(" is even"); Out.Ln;
END; END;
n := 9; IF ~ODD(m)
THEN
Out.Int(m,0); Out.String(" is even"); Out.Ln;
ELSE
Out.Int(m,0); Out.String(" is odd"); Out.Ln;
END;
IF n < 0 n := 9;
THEN
Out.Int(n, 0); Out.String(" is negative"); Out.Ln; IF n < 0
ELSIF n < 10 THEN
THEN Out.Int(n, 0); Out.String(" is negative"); Out.Ln;
Out.Int(n, 0); Out.String(" has 1 digit"); Out.Ln; ELSIF n < 10
ELSE THEN
Out.Int(n, 0); Out.String(" has multiple digits"); Out.Ln; Out.Int(n, 0); Out.String(" has 1 digit"); Out.Ln;
END; ELSE
Out.Int(n, 0); Out.String(" has multiple digits"); Out.Ln;
END;
END ifelse. END ifelse.

View file

@ -3,15 +3,18 @@ MODULE square;
IMPORT Out; IMPORT Out;
VAR s : INTEGER; VAR s : INTEGER;
PROCEDURE squared(x : INTEGER): INTEGER; PROCEDURE squared(x : INTEGER): INTEGER;
BEGIN BEGIN
RETURN x * x RETURN x * x
END squared; END squared;
BEGIN BEGIN
s := squared(7); s := squared(7);
Out.Int(s, 0); Out.Ln; Out.Int(s, 0); Out.Ln;
Out.Int(squared(8), 0); Out.Ln; Out.Int(squared(8), 0); Out.Ln;
END square. END square.

View file

@ -3,12 +3,13 @@ MODULE proc;
IMPORT Out; IMPORT Out;
PROCEDURE printSum(a, b : INTEGER); PROCEDURE printSum(a, b : INTEGER);
BEGIN BEGIN
Out.Int(a + b, 0); Out.Ln Out.Int(a + b, 0); Out.Ln
END printSum; END printSum;
BEGIN BEGIN
printSum(6, 9) printSum(6, 9)
END proc. END proc.

View file

@ -1,22 +1,24 @@
MODULE varparam; MODULE varparam;
IMPORT Out; IMPORT Out;
VAR
a, b : INTEGER; VAR a, b : INTEGER;
PROCEDURE swapVals(VAR x, y : INTEGER); PROCEDURE swapVals(VAR x, y : INTEGER);
VAR tmp : INTEGER; VAR tmp : INTEGER;
BEGIN BEGIN
tmp := x; x := y; y := tmp; tmp := x; x := y; y := tmp;
END swapVals; END swapVals;
BEGIN BEGIN
a := 6; b := 9; a := 6; b := 9;
Out.String("initial "); Out.Ln; Out.String("initial "); Out.Ln;
Out.String("a : "); Out.Int(a, 0); Out.String("; b : "); Out.Int(b, 0); Out.Ln; Out.String("a : "); Out.Int(a, 0); Out.String("; b : "); Out.Int(b, 0); Out.Ln;
swapVals(a, b); swapVals(a, b);
Out.String("after swap"); Out.Ln; Out.String("after swap"); Out.Ln;
Out.String("a : "); Out.Int(a, 0); Out.String("; b : "); Out.Int(b, 0); Out.Ln; Out.String("a : "); Out.Int(a, 0); Out.String("; b : "); Out.Int(b, 0); Out.Ln;
END varparam. END varparam.

View file

@ -5,8 +5,8 @@ IMPORT Out;
BEGIN BEGIN
Out.String("Oberon has types, for example, I am a string type (ARRAY OF CHAR);"); Out.Ln; Out.String("Oberon has types, for example, I am a string type (ARRAY OF CHAR);"); Out.Ln;
Out.String("There are also other types, e.g. INTEGERs and BOOLEANs"); Out.Ln; Out.String("There are also other types, e.g. INTEGERs and BOOLEANs"); Out.Ln;
Out.Int(42, 0); Out.Int(42, 0);
Out.Ln Out.Ln
END values. END values.

View file

@ -4,28 +4,28 @@ IMPORT Out;
VAR VAR
s : ARRAY 32 OF CHAR; s : ARRAY 32 OF CHAR;
i : REAL; i : REAL;
n, m : INTEGER; n, m : INTEGER;
BEGIN BEGIN
s := "Initial"; s := "Initial";
Out.String(s); Out.Ln; Out.String(s); Out.Ln;
i := 3.14; i := 3.14;
n := 64; n := 64;
m := 42; m := 42;
Out.Int(m, 0); Out.Ln; Out.Int(m, 0); Out.Ln;
Out.Int(n, 0); Out.Ln; Out.Int(n, 0); Out.Ln;
Out.Real(i, 0); Out.Ln; Out.Real(i, 0); Out.Ln;
s := "assigning new values"; s := "assigning new values";
Out.String(s); Out.Ln; Out.String(s); Out.Ln;
i := 2.71; i := 2.71;
n := 128; n := 128;
m := 84; m := 84;
Out.Int(m, 0); Out.Ln; Out.Int(m, 0); Out.Ln;
Out.Int(n, 0); Out.Ln; Out.Int(n, 0); Out.Ln;
Out.Real(i, 0); Out.Real(i, 0);
Out.Ln Out.Ln
END variables. END variables.