diff options
Diffstat (limited to 'Testing/Semantic')
-rw-r--r-- | Testing/Semantic/t1-1a.p | 7 | ||||
-rw-r--r-- | Testing/Semantic/t1-1b.p | 16 | ||||
-rw-r--r-- | Testing/Semantic/t1-2.p | 12 | ||||
-rw-r--r-- | Testing/Semantic/t1-2a.p | 12 | ||||
-rw-r--r-- | Testing/Semantic/t1-2b.p | 12 | ||||
-rw-r--r-- | Testing/Semantic/t1-3.p | 11 | ||||
-rw-r--r-- | Testing/Semantic/t1-4.p | 13 | ||||
-rw-r--r-- | Testing/Semantic/t1-5.p | 11 | ||||
-rw-r--r-- | Testing/Semantic/t2-1.p | 10 | ||||
-rw-r--r-- | Testing/Semantic/t2-2.p | 6 | ||||
-rw-r--r-- | Testing/Semantic/t2-3.p | 9 | ||||
-rw-r--r-- | Testing/Semantic/t3-2.p | 8 | ||||
-rw-r--r-- | Testing/Semantic/t3-3.p | 13 | ||||
-rw-r--r-- | Testing/Semantic/t3-3a.p | 13 | ||||
-rw-r--r-- | Testing/Semantic/t3-4.p | 9 | ||||
-rw-r--r-- | Testing/Semantic/t4-1.p | 8 | ||||
-rw-r--r-- | Testing/Semantic/t5-2.p | 8 | ||||
-rw-r--r-- | Testing/Semantic/t5-3.p | 18 | ||||
-rw-r--r-- | Testing/Semantic/t5-4.p | 14 | ||||
-rw-r--r-- | Testing/Semantic/t6-1.p | 11 | ||||
-rw-r--r-- | Testing/Semantic/t6-2.p | 13 | ||||
-rw-r--r-- | Testing/Semantic/test-semantic.p | 70 |
22 files changed, 304 insertions, 0 deletions
diff --git a/Testing/Semantic/t1-1a.p b/Testing/Semantic/t1-1a.p new file mode 100644 index 0000000..5a6e773 --- /dev/null +++ b/Testing/Semantic/t1-1a.p @@ -0,0 +1,7 @@ +(* ERROR: variable redeclared *) +program main( input, output ); + var a,b,c: integer; + var x,y,c: real; +begin +end. + diff --git a/Testing/Semantic/t1-1b.p b/Testing/Semantic/t1-1b.p new file mode 100644 index 0000000..5a16e62 --- /dev/null +++ b/Testing/Semantic/t1-1b.p @@ -0,0 +1,16 @@ +(* ERROR: variable redeclared *) +program main( input, output ); + var a: integer; + + procedure boo; + begin + end; + + function boo(b:integer):integer; + begin + boo := 1 + end; + +begin +end. + diff --git a/Testing/Semantic/t1-2.p b/Testing/Semantic/t1-2.p new file mode 100644 index 0000000..a81cad2 --- /dev/null +++ b/Testing/Semantic/t1-2.p @@ -0,0 +1,12 @@ +(* LEGAL: local names should hide non-local names *) +program main( input, output ); + var a,b: integer; + procedure boo(a: integer); + var b: real; + begin + b := 1.23 + end; +begin + boo(b) +end. + diff --git a/Testing/Semantic/t1-2a.p b/Testing/Semantic/t1-2a.p new file mode 100644 index 0000000..a81cad2 --- /dev/null +++ b/Testing/Semantic/t1-2a.p @@ -0,0 +1,12 @@ +(* LEGAL: local names should hide non-local names *) +program main( input, output ); + var a,b: integer; + procedure boo(a: integer); + var b: real; + begin + b := 1.23 + end; +begin + boo(b) +end. + diff --git a/Testing/Semantic/t1-2b.p b/Testing/Semantic/t1-2b.p new file mode 100644 index 0000000..fd32c49 --- /dev/null +++ b/Testing/Semantic/t1-2b.p @@ -0,0 +1,12 @@ +(* LEGAL: local names should hide non-local names *) +program main( input, output ); + var a,b: integer; + procedure boo(a: integer); + var b: real; + begin + b := 1 + end; +begin + boo(b) +end. + diff --git a/Testing/Semantic/t1-3.p b/Testing/Semantic/t1-3.p new file mode 100644 index 0000000..a224b22 --- /dev/null +++ b/Testing/Semantic/t1-3.p @@ -0,0 +1,11 @@ +(* LEGAL: non-local names visible from inner scopes *) +program main( input, output ); + var a: integer; + procedure boo(x: integer); + begin + a := x + end; +begin + boo(a) +end. + diff --git a/Testing/Semantic/t1-4.p b/Testing/Semantic/t1-4.p new file mode 100644 index 0000000..420bdcb --- /dev/null +++ b/Testing/Semantic/t1-4.p @@ -0,0 +1,13 @@ +(* LEGAL: scope of the name of subprograms *) +program main( input, output ); + procedure boo; + procedure foo; + begin + end; + begin + foo + end; +begin + boo +end. + diff --git a/Testing/Semantic/t1-5.p b/Testing/Semantic/t1-5.p new file mode 100644 index 0000000..d2341d7 --- /dev/null +++ b/Testing/Semantic/t1-5.p @@ -0,0 +1,11 @@ +(* ERROR: local objects not defined outside their scopes *) +program main( input, output ); + var a: integer; + procedure boo(a: integer); + var x: integer; + begin + end; +begin + a := x +end. + diff --git a/Testing/Semantic/t2-1.p b/Testing/Semantic/t2-1.p new file mode 100644 index 0000000..295fe4b --- /dev/null +++ b/Testing/Semantic/t2-1.p @@ -0,0 +1,10 @@ +(* expression must return a typed-value *) +program main(input,output); + var a,b,c: integer; + var x,y,z: real; +begin + a := b + c; + x := y + z; + a := x +end. + diff --git a/Testing/Semantic/t2-2.p b/Testing/Semantic/t2-2.p new file mode 100644 index 0000000..efb455b --- /dev/null +++ b/Testing/Semantic/t2-2.p @@ -0,0 +1,6 @@ +(* ERROR: objects must be declared before used in expressions *) +program main( input, output ); +begin + a := 1 +end. + diff --git a/Testing/Semantic/t2-3.p b/Testing/Semantic/t2-3.p new file mode 100644 index 0000000..806c575 --- /dev/null +++ b/Testing/Semantic/t2-3.p @@ -0,0 +1,9 @@ +(* ERROR: objects of different types appear in the same expression *) +program main( input, output ); + var a: integer; + var x: real; +begin + a := a + 1.23; + x := x + 123 +end. + diff --git a/Testing/Semantic/t3-2.p b/Testing/Semantic/t3-2.p new file mode 100644 index 0000000..22f9b47 --- /dev/null +++ b/Testing/Semantic/t3-2.p @@ -0,0 +1,8 @@ +(* ERROR: test expressions in IF/WHILE statements must be Boolean *) +program main( input, output ); + var a: integer; +begin + while a + 123 do + a := a + 1 +end. + diff --git a/Testing/Semantic/t3-3.p b/Testing/Semantic/t3-3.p new file mode 100644 index 0000000..32b5e59 --- /dev/null +++ b/Testing/Semantic/t3-3.p @@ -0,0 +1,13 @@ +(* dangling ELSE binds to closest IF *) +program main( input, output ); + var a: integer; +begin + read(a); + if ( a < 10 ) then + if ( a >= 10 ) then + a := 1 + else + a := 0; + write(a) +end. + diff --git a/Testing/Semantic/t3-3a.p b/Testing/Semantic/t3-3a.p new file mode 100644 index 0000000..45d92f1 --- /dev/null +++ b/Testing/Semantic/t3-3a.p @@ -0,0 +1,13 @@ +(* dangling ELSE binds to closest IF *) +program main( input, output ); + var a: integer; +begin + a := 5; + if ( a < 10 ) then + if ( a >= 10 ) then + a := 1 + else + a := 0; +a:=2 +end. + diff --git a/Testing/Semantic/t3-4.p b/Testing/Semantic/t3-4.p new file mode 100644 index 0000000..73dc520 --- /dev/null +++ b/Testing/Semantic/t3-4.p @@ -0,0 +1,9 @@ +(* ERROR: mismatched type for index variable in FOR loops *) +program main( input, output ); + var a: integer; + var x: real; +begin + for x := 1 to 5 do + a := a + 1 +end. + diff --git a/Testing/Semantic/t4-1.p b/Testing/Semantic/t4-1.p new file mode 100644 index 0000000..2f24e8c --- /dev/null +++ b/Testing/Semantic/t4-1.p @@ -0,0 +1,8 @@ +(* ERROR: non-integer type for array index *) +program main( input, output ); + var a: array[3 .. 7] of real; + var x: real; +begin + a[x] := 1.23 +end. + diff --git a/Testing/Semantic/t5-2.p b/Testing/Semantic/t5-2.p new file mode 100644 index 0000000..2b9cde3 --- /dev/null +++ b/Testing/Semantic/t5-2.p @@ -0,0 +1,8 @@ +(* ERROR: function missing return statement *) +program main( input, output ); + function foo(a: integer): integer; + begin + end; +begin +end. + diff --git a/Testing/Semantic/t5-3.p b/Testing/Semantic/t5-3.p new file mode 100644 index 0000000..6494ae0 --- /dev/null +++ b/Testing/Semantic/t5-3.p @@ -0,0 +1,18 @@ +(* ERROR: function passed wrong number/type of arguments *) +program main( input, output ); + var b: integer; + var y: real; + var a: array[1 .. 13] of integer; + var z: array[1 .. 13] of real; + + function foo(a: integer; x: real): integer; + begin + foo := a + end; +begin + b := foo(y,b) + foo(b,y,10) +end. + + + + diff --git a/Testing/Semantic/t5-4.p b/Testing/Semantic/t5-4.p new file mode 100644 index 0000000..a31211f --- /dev/null +++ b/Testing/Semantic/t5-4.p @@ -0,0 +1,14 @@ +(* ERROR: function updating non-local variable *) +program main( input, output ); + var a: integer; + + function foo(b: integer): integer; + begin + foo := a; + a := b + end; + +begin + +end. + diff --git a/Testing/Semantic/t6-1.p b/Testing/Semantic/t6-1.p new file mode 100644 index 0000000..9669168 --- /dev/null +++ b/Testing/Semantic/t6-1.p @@ -0,0 +1,11 @@ +(* ERROR: procedures don't return values *) +program main( input, output ); + var a: integer; + procedure boo(b: integer); + begin + a := 1 + end; +begin + a := boo(a) +end. + diff --git a/Testing/Semantic/t6-2.p b/Testing/Semantic/t6-2.p new file mode 100644 index 0000000..3eabfac --- /dev/null +++ b/Testing/Semantic/t6-2.p @@ -0,0 +1,13 @@ +(* ERROR: procedure passed wrong number/type of arguments *) +program main( input, output ); + var b: integer; + var y: real; + + procedure boo(a: integer; x: real); + begin + end; +begin + boo(y,10); + boo(b,y,b) +end. + 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. + |