From 4f66397e285f7742bdf5bfd9f723e10104486ce2 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Wed, 25 Sep 2019 19:49:47 -0400 Subject: Squashed commit of the following: commit 5feabbc13a2edc8c5088f8a6163c729921f4119b Author: Tucker Evans Date: Wed Sep 25 19:48:52 2019 -0400 Update Semantic Check List after initial testing w/ Tino's tests commit d86de7957451e485c90e2354042e7e6bfb04a13f Author: Tucker Evans Date: Wed Sep 25 19:48:27 2019 -0400 Add variations to Tino's tests commit df5b9a51ce309b76e046aecfedd0960e7fa9984f Author: Tucker Evans Date: Wed Sep 25 19:12:50 2019 -0400 Add Tino's test files Files correspond to semantic check list entries --- Testing/Semantic/test-semantic.p | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Testing/Semantic/test-semantic.p (limited to 'Testing/Semantic/test-semantic.p') diff --git a/Testing/Semantic/test-semantic.p b/Testing/Semantic/test-semantic.p new file mode 100644 index 0000000..2cb9b8a --- /dev/null +++ b/Testing/Semantic/test-semantic.p @@ -0,0 +1,70 @@ + +program main( input, output ); + + (* local variables *) + var x, y: integer; + var a, b: real; + var c: array[ 1..10 ] of integer; + var d: array[ 11..20 ] of real; + + (* local function: mixed argument types *) + function foo( a: integer; x: real; z: integer ): integer; + procedure boo( a: real ); + begin + (* scope check on boo's a, main's b, d[] and y; and foo's z*) + boo( a * b + d[y + z] ) + end; + begin + (* boo is visible; so is main's b *) + boo( b ); + + (* function return statement; scope and type check on foo's a and main's y *) + foo := a + y + end; + + (* local procedure *) + procedure bar( c: integer ); + begin + (* nonlocal update *) + d[ c[foo(x,a,y)] ] := b + end; + + (* location function: recursive *) + function moo( d: integer ): integer; + begin + if ( d = 0 ) then + moo := 1 + else + moo := d * moo( d - 1 ) + end; + +begin + + (* FUNCTION call check: recursive and correct arguments *) + y := foo( x + foo( y, 0.001, a ) * 1, 2.3, b ); + + (* ARRAY access check: recursive, correct arguments *) + y := c[ x + c[y] * 45 ]; + + (* FUNCTION call and ARRAY access *) + y := foo( x + c[y + foo(c[1], d[2], a)] * 1, 2.3 + d[c[foo(c[3],b,d[y])]] ); + + (* IF-THEN check *) + if ( c[x] * 6 < 7 + moo( y ) and a > d[c[x]] ) then + begin + c[moo(foo(8,9.10,11.0)) + c[12]] := moo( c[y - 1] ) + end; + + (* PROCEDURE call: correct arguments, not used as expression *) + bar( c[x] ); + + (* FOR check *) + b := 10.0; + for a := 1.0 to 2.0 * b do + begin + bar( c[x + moo( c[x + moo( c[x + moo(1)] )] )] ); + a := a + 0.0000001 + end + +end. + -- cgit v1.1