mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 00:18:03 +00:00
Add mainmeth
This commit is contained in:
parent
73102c9897
commit
fd35b4583e
@ -1,7 +1,7 @@
|
|||||||
grammar Decaf;
|
grammar Decaf;
|
||||||
|
|
||||||
|
|
||||||
class : PUBLIC 'class' id '{' mainmeth? (field | meth | constructor)* '}';
|
class : PUBLIC 'class' id '{' (field | meth | mainmeth | constructor)* '}';
|
||||||
|
|
||||||
field : PUBLIC? type id ';';
|
field : PUBLIC? type id ';';
|
||||||
assignSign : ASSIGN | ADD_ASSIGN | SUB_ASSIGN | MUL_ASSIGN | MOD_ASSIGN | DIV_ASSIGN;
|
assignSign : ASSIGN | ADD_ASSIGN | SUB_ASSIGN | MUL_ASSIGN | MOD_ASSIGN | DIV_ASSIGN;
|
||||||
|
@ -27,11 +27,18 @@ public class ASTGenerator {
|
|||||||
else {
|
else {
|
||||||
constructors.add(new Constructor(ctx.id().IDENTIFIER().getText(), List.of(), new Block(List.of())));
|
constructors.add(new Constructor(ctx.id().IDENTIFIER().getText(), List.of(), new Block(List.of())));
|
||||||
}
|
}
|
||||||
|
Block mainmeth = null;
|
||||||
|
if (ctx.mainmeth() != null) {
|
||||||
|
if (ctx.mainmeth().size() > 1) {
|
||||||
|
throw new RuntimeException("Only one main method allowed!");
|
||||||
|
}
|
||||||
|
mainmeth = new BlockGenerator().visit(ctx.mainmeth().get(0).block());
|
||||||
|
}
|
||||||
List<Method> meths = new ArrayList<>();
|
List<Method> meths = new ArrayList<>();
|
||||||
if (ctx.meth() != null) {
|
if (ctx.meth() != null) {
|
||||||
meths = ctx.meth().stream().map(ASTGenerator::generateMethod).toList();
|
meths = ctx.meth().stream().map(ASTGenerator::generateMethod).toList();
|
||||||
}
|
}
|
||||||
return new Class(ctx.id().IDENTIFIER().getText(), declarations, meths, constructors);
|
return new Class(ctx.id().IDENTIFIER().getText(), mainmeth, declarations, meths, constructors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Declaration generateFieldVariable(DecafParser.FieldContext ctx) {
|
public static Declaration generateFieldVariable(DecafParser.FieldContext ctx) {
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/dev/Uni/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;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/dev/Uni/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;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/dev/Uni/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;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/dev/Uni/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
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/dev/Uni/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;
|
||||||
|
|
||||||
|
@ -2,5 +2,8 @@ package de.maishai.ast.records;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record Class(String classname , List<Declaration> fieldDeclarations, List<Method> methods, List<Constructor> constructors) implements Node {
|
public record Class(String classname, Block mainmeth, List<Declaration> fieldDeclarations, List<Method> methods, List<Constructor> constructors) implements Node {
|
||||||
|
public Class(String classname, List<Declaration> fieldDeclarations, List<Method> methods, List<Constructor> constructors) {
|
||||||
|
this(classname, null, fieldDeclarations, methods, constructors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user