mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-10-06 16:01:40 +00:00
added Object Type with attatched ID to Type and ReturnType
This commit is contained in:
parent
1ff02f86e8
commit
f6d546be86
@ -8,7 +8,7 @@ field : type id ';';
|
||||
localVar : type id ';';
|
||||
assignSign : ASSIGN | ADD_ASSIGN | SUB_ASSIGN | MUL_ASSIGN;
|
||||
returntype : type | VOID;
|
||||
type : INT | BOOL | CHAR;
|
||||
type : INT | BOOL | CHAR | id;
|
||||
|
||||
meth : PUBLIC? returntype id '(' params? ')' block;
|
||||
mainmeth : PUBLIC 'static' 'void' 'main' '(' 'String[] args' ')' block;
|
||||
|
@ -82,6 +82,11 @@ public class ASTGenerator {
|
||||
return Type.BOOL;
|
||||
if (ctx.CHAR() != null)
|
||||
return Type.CHAR;
|
||||
if (ctx.id() != null) {
|
||||
Type type = Type.OBJECT;
|
||||
type.setObjectType(new Id(ctx.id().getText()));
|
||||
return type;
|
||||
}
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@ -92,8 +97,14 @@ public class ASTGenerator {
|
||||
return ReturnType.BOOL;
|
||||
if (ctx.type().CHAR() != null)
|
||||
return ReturnType.CHAR;
|
||||
if (ctx.VOID() != null)
|
||||
if (ctx.VOID() != null) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -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;
|
||||
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
|
@ -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;
|
||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||
|
||||
|
@ -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;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
|
@ -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;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
||||
|
||||
|
@ -1,8 +1,26 @@
|
||||
package de.maishai.ast;
|
||||
|
||||
import de.maishai.ast.records.Id;
|
||||
|
||||
public enum ReturnType {
|
||||
INT,
|
||||
BOOL,
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,25 @@
|
||||
package de.maishai.ast;
|
||||
|
||||
import de.maishai.ast.records.Id;
|
||||
|
||||
public enum Type {
|
||||
INT,
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user