Skip to content

Commit 20b89df

Browse files
committed
Updated error checking examples
1 parent 64ed940 commit 20b89df

3 files changed

Lines changed: 31 additions & 50 deletions

File tree

samples/NameAnalysis.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

samples/ParseErrors.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,31 @@
11
class Factorial{
22
public static void main(String[] args){
3-
System.out.println.(new Fac().ComputeFac());
3+
System.out.println.(new Fac().ComputeFac()); //Statement Error: Line 3
44
}
55
}
66

77
class Fac{
8-
public int ErrorTime (int){
8+
public int ErrorTime (int){ //Formal Parameter Error: Line 8
99
}
1010
public int ComputeFac (int num){
1111
int y;
12-
int ;
12+
int ; //Variable Declaration Error: line 12
1313
if (num < 1)
1414
num_aux = 1 ;
1515
else
16-
num_aux = num * (this.ComputeFac num-1)) ;
16+
num_aux = num * (this.ComputeFac num-1)) ; //Actual Parameter Error: line 16
1717
return num_aux ;
1818
}
1919
}
2020

21-
Foo{
21+
Foo{ //Class Body Error: Line 21
2222
public int bar(){
2323
return 0;
2424
}
2525
}
2626

2727
class Error{
28-
public Foo (int num){
28+
public Foo (int num){ //Method Body Error: Line 28
2929
return 1 ;
3030
}
31-
}
32-
33-
// Errors:
34-
// Statement - Line 3
35-
// Formal Parameter - Line 8
36-
// Variable Declaration - line 12
37-
// Actual Parameter - line 16
38-
// Class Body - Line 21
39-
// Method Body - Line 28
31+
}

samples/TypeChecking.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
class Factorial{
1+
class TestClass{
22
public static void main(String[] a){
3-
System.out.println(new Fac().ComputeFac(10));
3+
System.out.println(this); //"this" in a static method: line 3
44
}
55
}
66

7-
class Fac {
8-
public int ComputeFac(int num){
7+
class SecondClass {
8+
public int Foo(int num){
99
int num_aux;
10-
if (num + 1)
11-
num_aux = 1 ;
12-
else
13-
num_aux = num * (this.ComputeFac(num-1)) ;
14-
return num_aux ;
10+
int num_aux; //Redefined Variable: line 10
11+
boolean b;
12+
int[] x;
13+
14+
fakevar = 3; //Undefined Variable: line 14
15+
b = SecondClass; //Invalid r-value: line 15
16+
num_aux = this.Foo(); //Wrong number of params: line 16
17+
num_aux = this.Foo(false); //Wrong types of params: line 17
18+
num_aux = 1 + SecondClass; //Invalid operands: line 18
19+
num_aux = 1 + false; //Non-integer operand: line 19
20+
b = 3 && true; //Boolean operator on non-boolean operand: line 20
21+
num_aux = b.length; //.length on non-aarry: Line 21
22+
if(1){ //Non-boolean expr in statement: Line 22
23+
System.out.println(1);
24+
} else {
25+
System.out.println(2);
26+
}
27+
num_aux = false; //Type mismatch: Line 27
28+
return num_aux;
1529
}
16-
}
17-
18-
30+
}

0 commit comments

Comments
 (0)