added Object Type with attatched ID to Type and ReturnType

This commit is contained in:
laurenz 2024-05-07 14:34:52 +02:00
parent 1ff02f86e8
commit f6d546be86
11 changed files with 429 additions and 368 deletions

View File

@ -8,7 +8,7 @@ field : type id ';';
localVar : type id ';'; localVar : type id ';';
assignSign : ASSIGN | ADD_ASSIGN | SUB_ASSIGN | MUL_ASSIGN; assignSign : ASSIGN | ADD_ASSIGN | SUB_ASSIGN | MUL_ASSIGN;
returntype : type | VOID; returntype : type | VOID;
type : INT | BOOL | CHAR; type : INT | BOOL | CHAR | id;
meth : PUBLIC? returntype id '(' params? ')' block; meth : PUBLIC? returntype id '(' params? ')' block;
mainmeth : PUBLIC 'static' 'void' 'main' '(' 'String[] args' ')' block; mainmeth : PUBLIC 'static' 'void' 'main' '(' 'String[] args' ')' block;

View File

@ -82,6 +82,11 @@ public class ASTGenerator {
return Type.BOOL; return Type.BOOL;
if (ctx.CHAR() != null) if (ctx.CHAR() != null)
return Type.CHAR; return Type.CHAR;
if (ctx.id() != null) {
Type type = Type.OBJECT;
type.setObjectType(new Id(ctx.id().getText()));
return type;
}
throw new RuntimeException(); throw new RuntimeException();
} }
@ -92,8 +97,14 @@ public class ASTGenerator {
return ReturnType.BOOL; return ReturnType.BOOL;
if (ctx.type().CHAR() != null) if (ctx.type().CHAR() != null)
return ReturnType.CHAR; return ReturnType.CHAR;
if (ctx.VOID() != null) if (ctx.VOID() != null) {
return ReturnType.VOID; return ReturnType.VOID;
}
if (ctx.type().id() != null){
ReturnType type = ReturnType.OBJECT;
type.setObjectType(new Id(ctx.type().id().getText()));
return type;
}
throw new RuntimeException(); throw new RuntimeException();
} }
} }

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 // Generated from C:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
package de.maishai.antlr; package de.maishai.antlr;
import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.ParserRuleContext;

View File

@ -1,4 +1,4 @@
// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 // Generated from C:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
package de.maishai.antlr; package de.maishai.antlr;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;

View File

@ -1,4 +1,4 @@
// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 // Generated from C:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
package de.maishai.antlr; package de.maishai.antlr;
import org.antlr.v4.runtime.Lexer; import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStream;

View File

@ -1,4 +1,4 @@
// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 // Generated from C:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
package de.maishai.antlr; package de.maishai.antlr;
import org.antlr.v4.runtime.tree.ParseTreeListener; import org.antlr.v4.runtime.tree.ParseTreeListener;

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 // Generated from C:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
package de.maishai.antlr; package de.maishai.antlr;
import org.antlr.v4.runtime.tree.ParseTreeVisitor; import org.antlr.v4.runtime.tree.ParseTreeVisitor;

View File

@ -1,8 +1,26 @@
package de.maishai.ast; package de.maishai.ast;
import de.maishai.ast.records.Id;
public enum ReturnType { public enum ReturnType {
INT, INT,
BOOL, BOOL,
CHAR, CHAR,
VOID VOID,
OBJECT;
Id objectType;
public Id getObjectType() {
if(this == ReturnType.OBJECT){
return objectType;
}
return null;
}
public void setObjectType(Id objectType) {
if(this == ReturnType.OBJECT){
this.objectType = objectType;
}
}
} }

View File

@ -1,7 +1,25 @@
package de.maishai.ast; package de.maishai.ast;
import de.maishai.ast.records.Id;
public enum Type { public enum Type {
INT, INT,
BOOL, BOOL,
CHAR CHAR,
OBJECT;
Id objectType;
public Id getObjectType() {
if(this == Type.OBJECT){
return objectType;
}
return null;
}
public void setObjectType(Id objectType) {
if(this == Type.OBJECT){
this.objectType = objectType;
}
}
} }