added unary operations to ast

This commit is contained in:
laurenz 2024-05-02 13:56:20 +02:00
parent 24c3a26136
commit 8cc109275a
10 changed files with 25 additions and 19 deletions

View File

@ -46,9 +46,9 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
public static Expression generateConstant(DecafParser.LiteralContext ctx){
if(ctx.NUMBER() != null)
return new IntConstant(Integer.valueOf(ctx.NUMBER().getText()));
return new IntLiteral(Integer.valueOf(ctx.NUMBER().getText()));
if(ctx.boolean_() != null)
return new BoolConstant(Boolean.valueOf(ctx.boolean_().getText()));
return new BoolLiteral(Boolean.valueOf(ctx.boolean_().getText()));
throw new RuntimeException();
}

View File

@ -0,0 +1,6 @@
package de.maishai.ast;
public enum UnaryOperator {
SUB,
NOT
}

View File

@ -1,5 +0,0 @@
package de.maishai.ast.records;
public record BoolConstant(Boolean value) implements Expression {
}

View File

@ -0,0 +1,5 @@
package de.maishai.ast.records;
public record BoolLiteral(Boolean value) implements Expression {
}

View File

@ -1,5 +0,0 @@
package de.maishai.ast.records;
public record CharConstant(char value) implements Expression {
}

View File

@ -0,0 +1,5 @@
package de.maishai.ast.records;
public record CharLiteral(char value) implements Expression {
}

View File

@ -1,5 +1,5 @@
package de.maishai.ast.records;
public sealed interface Expression extends Node permits Assignment, Binary, BoolConstant, CharConstant, Id, IntConstant, MethodCall, New {
public sealed interface Expression extends Node permits Assignment, Binary, BoolLiteral, CharLiteral, Id, IntLiteral, MethodCall, New, Unary {
}

View File

@ -1,5 +0,0 @@
package de.maishai.ast.records;
public record IntConstant(Integer value) implements Expression {
}

View File

@ -0,0 +1,5 @@
package de.maishai.ast.records;
public record IntLiteral(Integer value) implements Expression {
}

View File

@ -12,5 +12,5 @@ import de.maishai.ast.records.Return;
import de.maishai.ast.records.ReturnVoid;
import de.maishai.ast.records.While;
public sealed interface Statement extends Node permits Break, Continue, DoWhile, For, IfElse, MethodCall, New, Return, ReturnVoid, While {
public sealed interface Statement extends Node permits Assignment, Break, Continue, DoWhile, For, IfElse, MethodCall, New, Return, ReturnVoid, While {
}