diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-09-29 21:30:48 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-09-29 21:35:19 -0400 |
commit | d6b038578577f7c0f4eeb95e35e6a2113e6d9732 (patch) | |
tree | 68609b4f92b701a0d1363c4905d0929018d3923b /Testing/Semantic/test-semantic.p | |
parent | 82dc3cf8d980b010a1cf2e3ac1c438c1412a21f8 (diff) | |
parent | 4f66397e285f7742bdf5bfd9f723e10104486ce2 (diff) |
Merge branch 'master' of git.tuckerevans.com:/srv/git/private/pascal_compiler
Fix white space at end of lines in Testing files
Diffstat (limited to 'Testing/Semantic/test-semantic.p')
-rw-r--r-- | Testing/Semantic/test-semantic.p | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/Testing/Semantic/test-semantic.p b/Testing/Semantic/test-semantic.p new file mode 100644 index 0000000..616b6b9 --- /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. + |