Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a test suite, adapted from PL/0 Tools
- Loading branch information
1 parent
7ab3d11
commit cf140fc
Showing
10 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(* http://ooc.sourceforge.net/OOCref/OOCref_7.html#SEC72 *) | ||
MODULE T00Output; | ||
IMPORT Out; | ||
|
||
BEGIN | ||
Out.String( "Hello World" ); | ||
Out.Ln; | ||
Out.Int( -1, 0 ); | ||
Out.Ln; | ||
Out.Int( 0, 0 ); | ||
Out.Ln; | ||
Out.Int( 1, 0 ); | ||
Out.Ln | ||
END T00Output. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
MODULE T01Arithmetic; | ||
IMPORT Out; | ||
|
||
BEGIN | ||
Out.Int( 2 + 3, 0 ); Out.Ln; | ||
Out.Int( 2 - 3, 0 ); Out.Ln; | ||
Out.Int( 2 * 3, 0 ); Out.Ln; | ||
Out.Int( 2 DIV 3, 0 ); Out.Ln; | ||
Out.Int( 2 MOD 3, 0 ); Out.Ln; | ||
|
||
Out.Int( 3 + 2, 0 ); Out.Ln; | ||
Out.Int( 3 - 2, 0 ); Out.Ln; | ||
Out.Int( 3 * 2, 0 ); Out.Ln; | ||
Out.Int( 3 DIV 2, 0 ); Out.Ln; | ||
Out.Int( 3 MOD 2, 0 ); Out.Ln; | ||
|
||
Out.Int( -0 , 0 ); Out.Ln; (* should output 0 of course, without the "-" *) | ||
END T01Arithmetic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
MODULE T02Precedence; | ||
IMPORT Out; | ||
|
||
BEGIN | ||
Out.Int( 1 + 2 * 3, 0 ); Out.Ln; | ||
Out.Int( (1 + 2) * 3, 0 ); Out.Ln; | ||
END T02Precedence. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
MODULE T10Constants; | ||
IMPORT Out; | ||
|
||
CONST x = 123; y = x * 2; abc="abc"; | ||
BEGIN | ||
Out.String( abc ); Out.Ln; | ||
Out.Int( x, 0 ); Out.Ln; | ||
Out.Int( y, 0 ); Out.Ln; | ||
Out.Int( y-x, 0 ); Out.Ln; | ||
END T10Constants. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MODULE T11Variables; | ||
IMPORT Out; | ||
|
||
VAR x : INTEGER: msg : ARRAY 3 OF CHAR; | ||
BEGIN | ||
|
||
x := 0; | ||
Out.Int( x ); Out.Ln; | ||
x := 1; | ||
Out.Int( 1 ); Out.Ln; | ||
|
||
x := 7; | ||
INC( x ); Out.Int( x ); Out.Ln; | ||
DEC( x ); Out.Int( x ); Out.Ln; | ||
|
||
msg := "abc"; | ||
Out.String( msg ); Out.Ln; | ||
msg := "xyz"; | ||
Out.String( msg ); Out.Ln; | ||
|
||
END T11Variables. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
MODULE T20IfThenElse; | ||
IMPORT Out; | ||
|
||
VAR p : BOOLEAN; i : integer; | ||
BEGIN | ||
|
||
p := TRUE; | ||
IF p THEN Out.String( "P" ) ELSE Out.String( "~P" ) END; Out.Ln; | ||
p := ~p; | ||
IF p THEN Out.String( "P" ) ELSE Out.String( "~P" ) END; Out.Ln; | ||
|
||
IF 1 # 2 THEN Out.String( "TRUE" ) ELSE Out.String( "FALSE" ) END; Out.Ln; | ||
IF 1 = 2 THEN Out.String( "TRUE" ) ELSE Out.String( "FALSE" ) END; Out.Ln; | ||
IF 1 > 2 THEN Out.String( "TRUE" ) ELSE Out.String( "FALSE" ) END; Out.Ln; | ||
IF 1 < 2 THEN Out.String( "TRUE" ) ELSE Out.String( "FALSE" ) END; Out.Ln; | ||
IF 1 >= 2 THEN Out.String( "TRUE" ) ELSE Out.String( "FALSE" ) END; Out.Ln; | ||
IF 1 <= 2 THEN Out.String( "TRUE" ) ELSE Out.String( "FALSE" ) END; Out.Ln; | ||
|
||
i := -1; | ||
IF i > 0 THEN Out.String( "+" ) ELSIF i < 0 THEN Out.String( "-" ) ELSE Out.String("0") END; | ||
Out.Ln; | ||
|
||
i := 0; | ||
IF i > 0 THEN Out.String( "+" ) ELSIF i < 0 THEN Out.String( "-" ) ELSE Out.String("0") END; | ||
Out.Ln; | ||
|
||
i := 1; | ||
IF i > 0 THEN Out.String( "+" ) ELSIF i < 0 THEN Out.String( "-" ) ELSE Out.String("0") END; | ||
Out.Ln; | ||
|
||
END T205IfThenElse. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
MODULE T21Loops; | ||
IMPORT Out; | ||
|
||
VAR i : INTEGER; | ||
|
||
BEGIN | ||
i := 0; | ||
|
||
REPEAT INC( i ); Out.Int( i ); Out.Ln | ||
UNTIL i = 10; | ||
|
||
WHILE i > -10 DO | ||
DEC( i, 5 ); Out.Int( i ); Out.Ln | ||
END; | ||
|
||
WHILE i > -10 DO | ||
Out.String("This should not Appear"); | ||
ELSE | ||
|
||
END; | ||
|
||
FOR i := 1 TO 3 BY 1 DO Out.Int( i ); Out.Ln END; | ||
FOR i := 3 TO 1 BY -1 DO Out.Int( i ); Out.Ln END; | ||
FOR i := 8 TO 2 BY -2 DO Out.Int( i ); Out.Ln END; | ||
|
||
END T21Loops. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
MODULE T30Procedures; | ||
IMPORT Out; | ||
|
||
PROCEDURE WriteLn( i : INTEGER ); | ||
BEGIN | ||
Out.Int( i ); | ||
Out.Ln; | ||
END Write; | ||
|
||
PROCEDURE Next( i : INTEGER ) : INTEGER; | ||
BEGIN | ||
RETURN i + 1 | ||
END Next; | ||
|
||
PROCEDURE VarNext( i : INTEGER; VAR j : INTEGER ); | ||
BEGIN | ||
END; | ||
|
||
VAR x : INTEGER; | ||
BEGIN | ||
|
||
x := 0; | ||
WriteLn( x ); (* 0 *) | ||
x := Next( x ); | ||
WriteLn( x ); (* 1 *) | ||
WriteLn( Next( x )); (* 2 *) | ||
VarNext( x, x ); | ||
WriteLn( x ); (* 2 *) | ||
|
||
END T30Procedures. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
PROCEDURE T31Nested; | ||
IMPORT Out; | ||
|
||
PROCEDURE Nested; | ||
PROCEDURE N1; | ||
PROCEDURE N2 | ||
PROCEDURE N3 | ||
BEGIN Out.String( "[ N3 ]" ) | ||
END N3; | ||
BEGIN Out.String( "[ N2 " ); N3; Out.String( "]" ) | ||
END N2; | ||
BEGIN Out.String( "[ N1 " ); N2; Out.String( "]" ) | ||
END N1; | ||
BEGIN Out.String( "[ Nested " ); N1; Out.String( "]" ); Out.Ln | ||
END Nested; | ||
|
||
BEGIN Nested | ||
END T31Nested. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
MODULE T32Recursion; | ||
|
||
|
||
PROCEDURE Binary( number, digits : INTEGER ); | ||
VAR place : INTEGER; | ||
|
||
PROCEDURE Helper; | ||
VAR bit : INTEGER; | ||
BEGIN | ||
IF ODD( number ) THEN bit := 1 ELSE bit := 0 END; | ||
number := number DIV 2; | ||
(* since we want to print the bits from highest to lowest, | ||
but we're starting with the lowest, we need to put the | ||
the recursive call in the middle. *) | ||
IF place > 0 THEN | ||
cursor := cursor - 1; | ||
Helper; | ||
END; | ||
(* the above code recursively printed all the bits to our left, | ||
so now we can print our bit and return: *) | ||
Out.Int( bit ) | ||
END Helper; | ||
|
||
BEGIN | ||
place := digits; | ||
helper; | ||
Out.Ln; | ||
END Binary; | ||
|
||
BEGIN | ||
Binary( 5, 4 ); (* expect: 0101 *) | ||
END T32Recursion. |