fix mainmethod potentially empty

This commit is contained in:
Boolean-True 2024-05-07 14:51:34 +02:00
parent f6d546be86
commit 1f0d690043
9 changed files with 376 additions and 363 deletions

View File

@ -2,7 +2,7 @@ grammar Decaf;
program : (class)+; program : (class)+;
class : PUBLIC? 'class' id '{' mainmeth (field | meth | constructor)* '}'; class : PUBLIC? 'class' id '{' mainmeth? (field | meth | constructor)* '}';
field : type id ';'; field : type id ';';
localVar : type id ';'; localVar : type id ';';

View File

@ -25,7 +25,10 @@ public class ASTGenerator {
if (ctx.field() != null) { if (ctx.field() != null) {
fields = ctx.field().stream().map(ASTGenerator::generateFieldVariable).toList(); fields = ctx.field().stream().map(ASTGenerator::generateFieldVariable).toList();
} }
MainMethod mainMethod = generateMainMethod(ctx.mainmeth()); MainMethod mainMethod = null;
if(ctx.mainmeth() != null){
mainMethod = generateMainMethod(ctx.mainmeth());
}
List<Constructor> constructors = new ArrayList<>(); List<Constructor> constructors = new ArrayList<>();
if (ctx.constructor() != null) { if (ctx.constructor() != null) {
constructors = ctx.constructor().stream().map(ASTGenerator::generateConstructor).toList(); constructors = ctx.constructor().stream().map(ASTGenerator::generateConstructor).toList();

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 // Generated from C:/dev/Compilerbau/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:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 // Generated from C:/dev/Compilerbau/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:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 // Generated from C:/dev/Compilerbau/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:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 // Generated from C:/dev/Compilerbau/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:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 // Generated from C:/dev/Compilerbau/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;