implemented some more test cases

This commit is contained in:
JonathanFleischmann 2024-06-22 22:09:26 +02:00
parent 59d0c97be3
commit e4f5bbbfa9
22 changed files with 1276 additions and 262 deletions

View File

@ -8,15 +8,9 @@
# Fehlende Tests für Features (positive Tests):
- Mainmethod
- *=
- %=
- /=
- boolean als Datentyp (public boolean test;)
- do while
- break
- recipient mit methode zwischen drinnen (this.methode().a
- &&
- ||
- unaryOp
- Klammern von Expressions
- Multiline Comment
- Klammern von Expressions

View File

@ -1,5 +1,6 @@
import de.maishai.Compiler;
import de.maishai.ast.records.Program;
import de.maishai.typedast.typedclass.TypedProgram;
import org.junit.jupiter.api.Test;
import testResources.AST.ASTFeatures.*;
import testResources.AST.ASTMore.*;
@ -65,6 +66,13 @@ public class ScannerParserTests {
assertEquals(AbstractSyntax_ComplexClass.get(), resultAst);
}
// Feature Tests
@Test
@ -86,6 +94,12 @@ public class ScannerParserTests {
assertEquals(AST_Comment.get(), resultAst);
}
@Test
public void testCompAssign() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/CompAssign.java"));
assertEquals(AST_CompAssign.get(), resultAst);
}
@Test
public void testConstructor() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Constructor.java"));
@ -98,6 +112,12 @@ public class ScannerParserTests {
assertEquals(AST_Continue.get(), resultAst);
}
@Test
public void testDataTypes() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/DataTypes.java"));
assertEquals(AST_DataTypes.get(), resultAst);
}
@Test
public void testField() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Field.java"));
@ -116,18 +136,18 @@ public class ScannerParserTests {
assertEquals(AST_If.get(), resultAst);
}
// @Test
// public void testIncrDecr() {
// Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/IncrDecr.java"));
// assertEquals(AST_IncrDecr.get(), resultAst);
// }
@Test
public void testLogicExpr() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/LogicExpr.java"));
assertEquals(AST_LogicExpr.get(), resultAst);
}
@Test
public void testMain() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Main.java"));
assertEquals(AST_Main.get(), resultAst);
}
@Test
public void testMethod() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Method.java"));
@ -140,7 +160,12 @@ public class ScannerParserTests {
assertEquals(AST_MethodCall.get(), resultAst);
}
//TODO: Multiple Classes test
// @Test
// public void testMultipleClasses() {
// Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/MultipleClasses.java"));
// assertEquals(AST_MultipleClasses.get(), resultAst);
// }
// TODO: Implement
@Test
public void testOperators() {
@ -159,14 +184,12 @@ public class ScannerParserTests {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Print.java"));
assertEquals(AST_Print.get(), resultAst);
}
//TODO: fix
// @Test
// public void testReturn() {
// Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Return.java"));
// assertEquals(AST_Return.get(), resultAst);
// }
//TODO: fix
@Test
public void testReturn() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/test/testFiles/JavaTestfilesFeatures/Return.java"));
assertEquals(AST_Return.get(), resultAst);
}
@Test
public void testVariableDefWithDecl() {

View File

@ -1,5 +1,6 @@
import de.maishai.Compiler;
import de.maishai.typedast.typedclass.TypedProgram;
import jdk.jshell.spi.ExecutionControl;
import org.junit.jupiter.api.Test;
import testResources.TypedAST.TypedASTFeatures.*;
import testResources.AST.ASTFeatures.*;
@ -56,6 +57,12 @@ public class TypingTests {
assertEquals(TypedAST_Comment.get(), resultTypedAst);
}
@Test
public void testCompAssign() {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_CompAssign.get());
assertEquals(TypedAST_CompAssign.get(), resultTypedAst);
}
@Test
public void testConstructor() {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Constructor.get());
@ -68,6 +75,12 @@ public class TypingTests {
assertEquals(TypedAST_Continue.get(), resultTypedAst);
}
@Test
public void testDataTypes() {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_DataTypes.get());
assertEquals(TypedAST_DataTypes.get(), resultTypedAst);
}
@Test
public void testField() {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Field.get());
@ -85,13 +98,6 @@ public class TypingTests {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(testResources.AST.ASTFeatures.AST_If.get());
assertEquals(TypedAST_If.get(), resultTypedAst);
}
//
// @Test
// public void testIncrDecr() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_IncrDecr.get());
// assertEquals(TypedAST_IncrDecr.get(), resultTypedAst);
// }
//TODO: fix
@Test
public void testLogicExpr() {
@ -99,6 +105,17 @@ public class TypingTests {
assertEquals(TypedAST_LogicExpr.get(), resultTypedAst);
}
@Test
public void testMain() {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Main.get());
assertEquals(TypedAST_Main.get(), resultTypedAst);
try {
throw new ExecutionControl.NotImplementedException("Main Class not yet implemented in TypedAST");
} catch (ExecutionControl.NotImplementedException e) {
throw new RuntimeException(e);
}
}
@Test
public void testMethod() {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Method.get());
@ -136,12 +153,11 @@ public class TypingTests {
assertEquals(TypedAST_Print.get(), resultTypedAst);
}
// @Test
// public void testReturn() {
// TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Return.get());
// assertEquals(TypedAST_Return.get(), resultTypedAst);
// }
//TODO: fix
@Test
public void testReturn() {
TypedProgram resultTypedAst = Compiler.generateTypedASTFromAst(AST_Return.get());
assertEquals(TypedAST_Return.get(), resultTypedAst);
}
@Test
public void testVariableDefWithDecl() {

View File

@ -0,0 +1,217 @@
package testResources.AST.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_CompAssign {
public static Program get() {
return new Program(
List.of(
new Class(
"CompAssign",
List.of(),
List.of(
new Method(
Type.INT,
"increase",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.ADD,
new IntLiteral(1)
)
),
new Return(
new FieldVarAccess(
false,
null,
"a"
)
)
)
)
),
new Method(
Type.INT,
"decrease",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.SUB,
new IntLiteral(1)
)
),
new Return(
new FieldVarAccess(
false,
null,
"a"
)
)
)
)
),
new Method(
Type.INT,
"multiply",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.MUL,
new IntLiteral(2)
)
),
new Return(
new FieldVarAccess(
false,
null,
"a"
)
)
)
)
),
new Method(
Type.INT,
"divide",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.DIV,
new IntLiteral(2)
)
),
new Return(
new FieldVarAccess(
false,
null,
"a"
)
)
)
)
),
new Method(
Type.INT,
"modulus",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.MOD,
new IntLiteral(2)
)
),
new Return(
new FieldVarAccess(
false,
null,
"a"
)
)
)
)
)
),
List.of(
new Constructor(
"CompAssign",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,144 @@
package testResources.AST.ASTFeatures;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.Program;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_DataTypes {
public static Program get() {
return new Program(
List.of(
new Class(
"DataTypes",
List.of(
new Declaration(
"x",
Type.INT
),
new Declaration(
"y",
Type.BOOL
),
new Declaration(
"z",
Type.CHAR
)
),
List.of(
new Method(
Type.INT,
"integer",
List.of(
new Parameter(
"i",
Type.INT
)
),
new Block(
List.of(
new Declaration(
"a",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new IntLiteral(1)
),
new Return(
new FieldVarAccess(
false,
null,
"a"
)
)
)
)
),
new Method(
Type.BOOL,
"bool",
List.of(
new Parameter(
"b",
Type.BOOL
)
),
new Block(
List.of(
new Declaration(
"a",
Type.BOOL
),
new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new BoolLiteral(true)
),
new Return(
new FieldVarAccess(
false,
null,
"a"
)
)
)
)
),
new Method(
Type.CHAR,
"character",
List.of(
new Parameter(
"c",
Type.CHAR
)
),
new Block(
List.of(
new Declaration(
"a",
Type.CHAR
),
new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new CharLiteral('a')
),
new Return(
new FieldVarAccess(
false,
null,
"a"
)
)
)
)
)
),
List.of(
new Constructor(
"DataTypes",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -1,86 +0,0 @@
package testResources.AST.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_IncrDecr {
public static Program get() {
return new Program(
List.of(
new Class(
"IncrDecr",
List.of(),
List.of(
new Method(
Type.INT,
"increment",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.ADD,
new IntLiteral(
1
)
)
)
)
)
),
new Method(
Type.INT,
"decrement",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.SUB,
new IntLiteral(
1
)
)
)
)
)
)
),
List.of(
new Constructor(
"IncrDecr",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,46 @@
package testResources.AST.ASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_Main {
public static Program get() {
return new Program(
List.of(
new Class(
"Main",
new Block(
List.of(
new Declaration(
"i",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new IntLiteral(0)
)
)
),
List.of(),
List.of(),
List.of(
new Constructor(
"Main",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -63,14 +63,14 @@ public class AST_Return {
)
),
new Method(
Type.REFERENCE("AST_Return"),
Type.REFERENCE("Return"),
"returnClass",
List.of(),
new Block(
List.of(
new Return(
new New(
Type.REFERENCE("AST_Return"),
Type.REFERENCE("Return"),
List.of()
)
)

View File

@ -66,6 +66,59 @@ public class AST_While {
)
)
)
),
new Method(
Type.VOID,
"doWhileLoop",
List.of(),
new Block(
List.of(
new Declaration(
"i",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new IntLiteral(0)
),
new DoWhile(
new Block(
List.of(
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.ADD,
new IntLiteral(1)
)
)
)
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.LT,
new IntLiteral(5)
)
)
)
)
)
),
List.of(

View File

@ -0,0 +1,285 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_CompAssign {
public static TypedProgram get() {
return new TypedProgram(
List.of(
new TypedClass(
"CompAssign",
List.of(),
List.of(
new TypedMethod(
"increase",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.ADD,
new TypedIntLiteral(
1,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"decrease",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.SUB,
new TypedIntLiteral(
1,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"multiply",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.MUL,
new TypedIntLiteral(
2,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"divide",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.DIV,
new TypedIntLiteral(
2,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"modulus",
Type.INT,
List.of(
new TypedParameter(
"a",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Operator.MOD,
new TypedIntLiteral(
2,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
)
),
Type.INT
)
)
),
List.of(
new TypedConstructor(
"CompAssign",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
Type.REFERENCE("CompAssign")
)
),
null
);
}
}

View File

@ -0,0 +1,183 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_DataTypes {
public static TypedProgram get() {
return new TypedProgram(
List.of(
new TypedClass(
"DataTypes",
List.of(
new TypedDeclaration(
"x",
Type.INT
),
new TypedDeclaration(
"y",
Type.BOOL
),
new TypedDeclaration(
"z",
Type.CHAR
)
),
List.of(
new TypedMethod(
"integer",
Type.INT,
List.of(
new TypedParameter(
"i",
Type.INT
)
),
List.of(),
new TypedBlock(
List.of(
new TypedLocalVariable(
"a",
Type.INT
)
),
List.of(
new TypedAssignment(
new TypedIntLiteral(
1,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.INT
),
Type.INT
)
),
Type.INT
)
),
new TypedMethod(
"bool",
Type.BOOL,
List.of(
new TypedParameter(
"b",
Type.BOOL
)
),
List.of(),
new TypedBlock(
List.of(
new TypedLocalVariable(
"a",
Type.BOOL
)
),
List.of(
new TypedAssignment(
new TypedBoolLiteral(
true,
Type.BOOL
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.BOOL
),
Type.BOOL
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.BOOL
),
Type.BOOL
)
),
Type.BOOL
)
),
new TypedMethod(
"character",
Type.CHAR,
List.of(
new TypedParameter(
"c",
Type.CHAR
)
),
List.of(),
new TypedBlock(
List.of(
new TypedLocalVariable(
"a",
Type.CHAR
)
),
List.of(
new TypedAssignment(
new TypedCharLiteral(
'a',
Type.CHAR
),
new TypedFieldVarAccess(
false,
null,
"a",
Type.CHAR
),
Type.CHAR
),
new TypedReturn(
new TypedFieldVarAccess(
false,
null,
"a",
Type.CHAR
),
Type.CHAR
)
),
Type.CHAR
)
)
),
List.of(
new TypedConstructor(
"DataTypes",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
Type.REFERENCE("DataTypes")
)
),
null
);
}
}

View File

@ -1,86 +0,0 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import java.util.List;
public class TypedAST_IncrDecr {
public static Program get() {
return new Program(
List.of(
new Class(
"IncrDecr",
List.of(),
List.of(
new Method(
Type.INT,
"increment",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.ADD,
new IntLiteral(
1
)
)
)
)
)
),
new Method(
Type.INT,
"decrement",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.SUB,
new IntLiteral(
1
)
)
)
)
)
)
),
List.of(
new Constructor(
"IncrDecr",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,56 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.TypedBlock;
import de.maishai.typedast.typedclass.TypedClass;
import de.maishai.typedast.typedclass.TypedConstructor;
import de.maishai.typedast.typedclass.TypedProgram;
import jdk.jshell.spi.ExecutionControl;
import java.util.List;
public class TypedAST_Main {
public static TypedProgram get() {
return new TypedProgram(
List.of(
new TypedClass(
"Main",
// new Block(
// List.of(
// new Declaration(
// "i",
// Type.INT
// ),
// new Assignment(
// new FieldVarAccess(
// false,
// null,
// "i"
// ),
// new IntLiteral(0)
// )
// )
// ),
List.of(),
List.of(),
List.of(
new TypedConstructor(
"Main",
List.of(),
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
),
null,
null,
Type.REFERENCE("Main")
)
),
null
);
}
}

View File

@ -1,95 +1,131 @@
package testResources.TypedAST.TypedASTFeatures;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAST_Return {
public static Program get() {
return new Program(
public static TypedProgram get() {
return new TypedProgram(
List.of(
new Class(
new TypedClass(
"Return",
List.of(),
List.of(
new Method(
Type.INT,
new TypedMethod(
"returnInt",
Type.INT,
List.of(),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new IntLiteral(10)
new TypedReturn(
new TypedIntLiteral(
10,
Type.INT
),
Type.INT
)
)
),
Type.INT
)
),
new Method(
Type.VOID,
new TypedMethod(
"returnVoid",
Type.VOID,
List.of(),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
null
new TypedReturn(
null,
Type.VOID
)
)
),
Type.VOID
)
),
new Method(
Type.BOOL,
new TypedMethod(
"returnBoolean",
Type.BOOL,
List.of(),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new BoolLiteral(true)
new TypedReturn(
new TypedBoolLiteral(
true,
Type.BOOL
),
Type.BOOL
)
)
),
Type.BOOL
)
),
new Method(
Type.CHAR,
new TypedMethod(
"returnChar",
Type.CHAR,
List.of(),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new CharLiteral('a')
new TypedReturn(
new TypedCharLiteral(
'a',
Type.CHAR
),
Type.CHAR
)
)
),
Type.CHAR
)
),
new Method(
Type.REFERENCE("AST_Return"),
new TypedMethod(
"returnClass",
Type.REFERENCE("Return"),
List.of(),
new Block(
List.of(),
new TypedBlock(
List.of(),
List.of(
new Return(
new New(
Type.REFERENCE("AST_Return"),
new TypedReturn(
new TypedNew(
Type.REFERENCE("Return"),
List.of()
)
),
Type.REFERENCE("Return")
)
)
),
Type.REFERENCE("Return")
)
)
),
List.of(
new Constructor(
new TypedConstructor(
"Return",
List.of(),
new Block(
List.of()
)
new TypedBlock(
List.of(),
List.of(),
Type.VOID
),
Type.VOID,
List.of()
)
)
),
null,
null,
Type.REFERENCE("Return")
)
)
),
null
);
}
}

View File

@ -90,6 +90,81 @@ public class TypedAST_While {
)
)
)
),
new TypedMethod(
"doWhileLoop",
Type.VOID,
List.of(),
List.of(),
new TypedBlock(
List.of(
new TypedLocalVariable(
"i",
Type.INT
)
),
List.of(
new TypedAssignment(
new TypedIntLiteral(
0,
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Type.INT
),
new TypedDoWhile(
new TypedBlock(
List.of(),
List.of(
new TypedAssignment(
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Operator.ADD,
new TypedIntLiteral(
1,
Type.INT
),
Type.INT
),
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Type.INT
)
),
Type.VOID
),
new TypedBinary(
new TypedFieldVarAccess(
false,
null,
"i",
Type.INT
),
Operator.LT,
new TypedIntLiteral(
5,
Type.INT
),
Type.BOOL
),
Type.VOID
)
)
)
)
),
List.of(

View File

@ -1,3 +1,12 @@
public class Comment {
// This is a comment
// This is another comment
// With multiple lines
/* This is a comment
with multiple lines written in a block
which is closed/started with a * and a /
*/
}

View File

@ -0,0 +1,26 @@
public class CompAssign {
public int increase(int a) {
a += 1;
return a;
}
public int decrease(int a) {
a -= 1;
return a;
}
public int multiply(int a) {
a *= 2;
return a;
}
public int divide(int a) {
a /= 2;
return a;
}
public int modulus(int a) {
a %= 2;
return a;
}
}

View File

@ -0,0 +1,20 @@
public class DataTypes {
int x;
boolean y;
char z;
public int integer(int i) {
int a = 1;
return a;
}
public boolean bool(boolean b) {
boolean a = true;
return a;
}
public char character(char c) {
char a = 'a';
return a;
}
}

View File

@ -1,9 +0,0 @@
public class IncrDecr {
public int increment(int a) {
return a += 1;
}
public int decrement(int a) {
return a -= 1;
}
}

View File

@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
int i = 0;
}
}

View File

@ -15,7 +15,7 @@ public class Return {
return 'a';
}
public AST_Return returnClass() {
return new AST_Return();
public Return returnClass() {
return new Return();
}
}

View File

@ -5,4 +5,11 @@ public class While {
i = i + 1;
}
}
public void doWhileLoop() {
int i = 0;
do {
i = i + 1;
} while (i < 5);
}
}