-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBuggySemanticInput.mj
90 lines (83 loc) · 2.21 KB
/
BuggySemanticInput.mj
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
// Test input for checking symbol table handling
//**************************************************
// invoke as: java MJ.Compiler BuggySemanticInput.mj
//**************************************************
program P
final int c1 = 'x';
//----------------| integer constant expected
final char cc = 3;
//----------------| character constant expected
class C {
int f;
}
int i;
char ch;
C c, c2;
char[] a;
ch x;
//---| type expected
ch[] y;
//---| type expected
char i;
//-----| i already declared
{
void foo (int x) {
return 3;
//---------| void method must not return a value
}
int bar (char c) {
if (c > 'x') return; else return c;
//---------------------| return expression expected
//-----------------------------------| return type must match method type
}
int main()
//| must be void
{
i = 1;
int = 3;
//--| type identifier not allowed here
ch = 3;
//--------| incompatible types in assignment
i = 3 * v + 1;
//----------| v not found
x(3, ch);
//--| called object is not a method
read(foo);
//--------| read object must be a variable
read(c);
//-------| can only read int or char variables
print(c);
//--------| can only print int or char variables
foo(3, i);
//----------| more actual than formal parameters
foo();
//-------| fewer actual than formal parameters
foo('x');
//------| parameter type mismatch
if (i == 'a') i = i + ch; else i = i * ch;
//------------| type mismatch
//-------------------------| operands must be of type int
//------------------------------------------| operands must be on type int
if (c > c2) c = - c2;
//------------| invalid compare
//---------------------| integer operand required
i = ch();
//------| called object is not a method
i = new int;
//------------| class type expected
a = new ch[3];
//-----------| type expected
a = new char['3'];
//---------------| array size must be an integer
i = a.f + 3 * c.g;
//------| dereferenced object is not a class
//------------------| g not found
i = foo[2];
//-------| bad method call
i = ch[2];
//--------| indexed object is not an array
i = a['2'];
//-------| indexed object is not an array
//----------| index must be an int
}
}