Skip to content

Commit d34f0de

Browse files
committed
semantic error recovery [test]
1 parent 8b363e1 commit d34f0de

File tree

2 files changed

+144
-45
lines changed

2 files changed

+144
-45
lines changed

MJCompiler/src/rs/ac/bg/etf/pp1/SemanticAnalyzer.java

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ public void visit(InnerClassBodyDummyStart innerClassBodyDummyStart) {
782782
private boolean checkConstructorNameConstraint(String constructorName, SyntaxNode info) {
783783

784784
if(!constructorName.equals(currentClassName)) {
785-
report_error(constructorName+ " nije istog imena kao klasa " + currentClassName + " u kojoj je definisan!", info);
785+
report_error("Konstruktor " + constructorName + " nije istog imena kao klasa " + currentClassName + " u kojoj je definisan!", info);
786786
return false;
787787
}
788788

@@ -1398,50 +1398,7 @@ public void visit(MulOpFactorList mulOpFactorList) {
13981398
public void visit(Term term) {
13991399
// single factor should only pass its type
14001400
term.struct = term.getFactorList().struct;
1401-
}
1402-
/*
1403-
@Override
1404-
public void visit(SingleTerm singleTerm) {
1405-
// send type (TermType) to the Expr
1406-
singleTerm.struct = singleTerm.getTerm().struct;
1407-
}
1408-
1409-
@Override
1410-
public void visit(AddOpTermList addOpTermList) {
1411-
if(!addOpTermList.getTerm().struct.compatibleWith(addOpTermList.getTermList().struct)) {
1412-
// ! Specification constraint: Expr and Term types have to be compatible
1413-
report_error("Tip svih sabiraka moraju biti kompatibilni (" + structDescription(addOpTermList.getTerm().struct) + "," + structDescription(addOpTermList.getTermList().struct) + ")", addOpTermList);
1414-
addOpTermList.struct = Tab.noType;
1415-
return;
1416-
}
1417-
if(addOpTermList.getTerm().struct != Tab.intType || addOpTermList.getTermList().struct != Tab.intType) {
1418-
// ! Specification constraint: Expr and Term have to be the int type
1419-
report_error("Tip svih sabiraka treba da bude int", addOpTermList);
1420-
addOpTermList.struct = Tab.noType;
1421-
return;
1422-
}
1423-
// send cumulative type (intType) to the Expr
1424-
addOpTermList.struct = Tab.intType;
1425-
}
1426-
1427-
@Override
1428-
public void visit(PositiveExpr positiveExpr) {
1429-
// expression without "-" should only pass its type
1430-
positiveExpr.struct = positiveExpr.getTermList().struct;
1431-
}
1432-
1433-
@Override
1434-
public void visit(NegativeExpr negativeExpr) {
1435-
if(negativeExpr.getTerm().struct != Tab.intType) {
1436-
// ! Specification constraint: Expr has to be the int type
1437-
report_error("Tip negiranog izraza treba da bude int", negativeExpr);
1438-
negativeExpr.struct = Tab.noType;
1439-
return;
1440-
}
1441-
// send cumulative type (intType) to the Expr
1442-
negativeExpr.struct = Tab.intType;
1443-
}
1444-
*/
1401+
}
14451402

14461403
@Override
14471404
public void visit(SinglePositiveTerm singlePositiveTerm) {
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
program SemanticErrorRecovery
2+
3+
Integer x;
4+
5+
const int cinilac1 = 4, cinilac1 = 3, cinilac2 = true;
6+
7+
record T1 {
8+
int a;
9+
}
10+
11+
record T1 {
12+
int b;
13+
}
14+
15+
class A1 {
16+
int a;
17+
}
18+
19+
class A1 {
20+
int b;
21+
}
22+
23+
class A2 extends Integer {
24+
25+
}
26+
27+
class A3 extends T1 {
28+
29+
}
30+
31+
32+
class B1 {
33+
34+
{
35+
B2() {
36+
37+
}
38+
39+
}
40+
}
41+
42+
class B2 {
43+
44+
{
45+
B2() {
46+
return 4;
47+
}
48+
}
49+
50+
}
51+
52+
class C {
53+
{
54+
int foo(int z) int a; {
55+
return a;
56+
}
57+
58+
void bar(int a, int b, int c) {
59+
60+
}
61+
62+
void super_f(int a) {
63+
64+
}
65+
}
66+
}
67+
68+
class C2 extends C{
69+
{
70+
int foo(int z1, int z2) int a; {
71+
return a;
72+
}
73+
void bar(int a, B2 b, int c) {
74+
75+
}
76+
void super_f(int b) {
77+
78+
}
79+
80+
}
81+
}
82+
83+
84+
{
85+
int f(int x) {
86+
return -x;
87+
}
88+
89+
int f() {
90+
91+
}
92+
void g(char c1, char c1) {
93+
return c1;
94+
}
95+
96+
void main()
97+
f function_instance; int a[]; char c; C instC; C arrC[];
98+
{
99+
100+
a = new int['c'];
101+
c = new int;
102+
c = new C2;
103+
104+
a[0] = f(1,2,3);
105+
a[1] = C2(1,2,3);
106+
107+
108+
c.super_f(1, true);
109+
110+
instC.super_f(1, true);
111+
112+
read(instC);
113+
114+
a[1] = 1 + true;
115+
a[1] = false + true;
116+
a[1] = -c;
117+
118+
super();
119+
120+
instC.z = 6;
121+
122+
instC++;
123+
arrC++;
124+
f = f;
125+
126+
break;
127+
continue;
128+
129+
print(arrC);
130+
131+
if(1) {
132+
}
133+
134+
if(arrC <= inscC){
135+
}
136+
137+
if(true > 1) {
138+
139+
}
140+
}
141+
142+
}

0 commit comments

Comments
 (0)