added what can be typed

This commit is contained in:
ahmad 2024-05-09 21:19:58 +02:00
parent 5a5b467407
commit a38ea3ad02
2 changed files with 13 additions and 25 deletions

View File

@ -14,7 +14,7 @@ import java.io.IOException;
* Decaf language Compiler * Decaf language Compiler
*/ */
public class Compiler { public class Compiler {
/*
public static void main(String[] args) { public static void main(String[] args) {
generateAST(""" generateAST("""
public class ClassWithConstructorWithParameters { public class ClassWithConstructorWithParameters {
@ -33,7 +33,7 @@ public class Compiler {
} }
} }
"""); """);
} } */
public static Class generateAST(String fromSource) { public static Class generateAST(String fromSource) {
CharStream input = CharStreams.fromString(fromSource); CharStream input = CharStreams.fromString(fromSource);
@ -83,7 +83,7 @@ public class Compiler {
CodeGenUtils.writeClassfile(bytes, classname); CodeGenUtils.writeClassfile(bytes, classname);
} }
// public static void main(String[] args) { public static void main(String[] args) {
// generateByteCodeFileFromFile("src/main/resources/JavaTestfiles/ClassWithConstructor.java", "ClassWithConstructor"); generateByteCodeFileFromFile("src/main/resources/JavaTestfiles/ClassCanBeTyped.java", "ClassCanBeTyped");
// } }
} }

View File

@ -6,46 +6,34 @@ public class ClassCanBeTyped {
public ClassCanBeTyped() { public ClassCanBeTyped() {
this.x = 10; this.x = 10;
int i; int i;
for (i = 0; i < (x+1); i = i + 1) { for (i = 0; i < (x + 1); i = i + 1) {
int j; int j;
for (j = 0; j < this.x; j += 1) { for (j = 0; j < this.x; j += 1) {
this.x = this.x * this.x; this.x = this.x * this.x;
break; break;
} }
} }
do{ do {
this.y = this.y + 1; this.y = this.y + 1;
}while (this.y < 10) } while (this.y < 10)
if(this.x > 10) {
this.x = 10;
} else {
this.x = 20;
}
int k; int k;
k = 0; k = 0;
for ( k = 0; k < 10; k = k+1) { for (k = 0; k < 10; k = k + 1) {
if(k == 5) { if (k == 5) {
return; return;
} }
} }
} }
public ClassCanBeTyped(int x, int y, char z) { public ClassCanBeTyped(int x, int y, char z) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z;
}
public int getY() {
return this.y;
}
public int getX() {
return this.x;
} }
public char getZ() { public int getX(char z) {
return this.z; return x;
} }