forked from SarthakShah001/Compiler2K23
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht4.txt
More file actions
99 lines (92 loc) · 3.16 KB
/
t4.txt
File metadata and controls
99 lines (92 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
** Test case 4: Testing symbol table creation for variable declaration and redeclaration checks**
** Multiple level nesting using static array data type**
**Variant of test case 2**
<<module var_demo_array>>
takes input [x:integer, m:array [2..20] of integer, p:real];
returns [ n:integer, k: boolean];
start
declare a,b:integer;
get_value(b);
declare p: array[2..20] of integer; **Not an error as local variable can shadow the definition of input parameter**
a:= m[5]+3;
p:= m; ** not an error**
k:=true;
p[10]:= a*b-20*h; **ERROR: variable h is not declared**
while(k AND x<=m[11] OR false)
start
declare p:integer;
declare b: array[2..20] of integer;
b:= m;
b[2]:= u+m[6]; **ERROR: variable u is not declared**
p:= b[18]*18;
end ** None of while loop variable is assigned **
n:= a - b;
declare b:real; **ERROR: variable b is re-declared**
b:= b+3;
k:= a>b OR b>100;
print(k);
end
<<module f1>>
takes input[a: array[10..30] of integer, b:array[10..30] of integer, c:real];
returns [m:boolean, n:integer];
start
declare x,y: real;
declare k: integer;
get_value(y);
get_value(x);
declare A,B: array[4..10] of integer;
get_value(B);
declare C: array[10..30] of integer;
A:=B;
C:=a;
D:=C; **ERROR: variable D is not declared**
for (k in -15..40)
start
x:=x+y;
declare u, v:real;
u := y+c*34.2;
v:= u-c*p-20.5E+2; **ERROR: variable p is not declared**
switch(k)
start
case 10: declare A:real;
declare B: array[10..30] of integer;
declare E: array[4..10] of integer;
B[15]:= k*20; **No error as index is within bounds computed statically**
B:=C; **No error as C is available with static ancestor**
E:= Q; **ERROR: variable Q is not declared**
break;
case 20: declare B, A: array[-11..10] of real; **Not an error: variables A, B are declared in the scope of this different case**
A[3]:= 12.90 + u*y - c; **Not an error as u, y and c are avialble in the scopes of static ancestors**
declare B: real; **ERROR: variable B is re-declared**
declare Q: integer;
get_value(Q);
u:= k+12 - Q*10; ** TYPE MISMATCH ERROR ** **not an error**
break;
default: C[9]:= A[15]+Q; ** ARRAY ELEMENT A[15] IS OUT OF BOUND , VARIABLE Q NOT DECLARED ** ** C[9] is out of bound **
break;
end
x:=x+u*v;
k:= 23; **ERROR: variable k is assigned a value erroniously as it is the variable in for loop**
end
x:=c+y;
C[18]:= a[18]+ b[18];
A[5]:= B[6]- 10;
declare A: array[10..70] of integer; **ERROR: variable A is re-declared**
m:= A[5]< C[18];
m:= c>=x AND E[10]>=y; **ERROR: variable E is not declared**
n:= 20*8-5;
end
<<<driver program>>>
start
declare v_1_2_3, A:integer;
declare u1:boolean;
A:=12;
declare p: real;
p:= 23.56;
get_value(v_1_2_43); **ERROR: variable v_1_2_43 is not declared**
declare B, C: array [2..20] of integer;
[ v_1_2_3, u1]:=use module var_demo_array with parameters A,B,p;
[ v_1_2_3, k]:=use module var_demo_array with parameters A,B,p; **ERROR: variable k is not declared**
B:= C;
declare B: real; **ERROR: variable B is re-declared**
end