mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 09:48:03 +00:00
update records
This commit is contained in:
parent
2b10b883a6
commit
73def2733a
@ -6,7 +6,7 @@ class : PUBLIC? 'class' id '{' (field | meth)* '}';
|
|||||||
|
|
||||||
field : type id ';';
|
field : type id ';';
|
||||||
localVar : type id ';';
|
localVar : type id ';';
|
||||||
assignSign : '=' | '+=' | '-=' | '*=';
|
assignSign : ASSIGN | ADD_ASSIGN | SUB_ASSIGN | MUL_ASSIGN;
|
||||||
returntype : type | VOID;
|
returntype : type | VOID;
|
||||||
type : INT | BOOL | CHAR;
|
type : INT | BOOL | CHAR;
|
||||||
|
|
||||||
@ -26,11 +26,11 @@ stmt : 'if' '(' expr ')' block ('else' block)? #If
|
|||||||
| 'return' ';' #ReturnVoid
|
| 'return' ';' #ReturnVoid
|
||||||
| 'break' ';' #Break
|
| 'break' ';' #Break
|
||||||
| 'continue' ';' #Continue
|
| 'continue' ';' #Continue
|
||||||
| stmtexpr #StatementExpressionstmt
|
| id assignSign expr ';' #Assignment
|
||||||
|
| stmtexpr ';' #StatementExpressionstmt
|
||||||
;
|
;
|
||||||
|
|
||||||
stmtexpr : id assignSign expr ';' #Assignment
|
stmtexpr : methCall #MethodCall
|
||||||
| methCall ';' #MethodCall
|
|
||||||
| NEW type '(' args? ')' #New
|
| NEW type '(' args? ')' #New
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -38,7 +38,6 @@ expr : expr binaryOp expr #BinaryOperation
|
|||||||
| unaryOp expr #UnaryOperation
|
| unaryOp expr #UnaryOperation
|
||||||
| literal #Constant
|
| literal #Constant
|
||||||
| '(' expr ')' #Expression
|
| '(' expr ')' #Expression
|
||||||
| methCall #MethodCallExpression
|
|
||||||
| fieldId #Identifier
|
| fieldId #Identifier
|
||||||
| stmtexpr #StatementExpressionexpr
|
| stmtexpr #StatementExpressionexpr
|
||||||
| NULL #Null
|
| NULL #Null
|
||||||
@ -75,6 +74,11 @@ NE : '!=';
|
|||||||
AND : '&&';
|
AND : '&&';
|
||||||
OR : '||';
|
OR : '||';
|
||||||
|
|
||||||
|
ASSIGN : '=';
|
||||||
|
ADD_ASSIGN : '+=';
|
||||||
|
SUB_ASSIGN : '-=';
|
||||||
|
MUL_ASSIGN : '*=';
|
||||||
|
|
||||||
NOT : '!';
|
NOT : '!';
|
||||||
|
|
||||||
INT : 'int';
|
INT : 'int';
|
||||||
|
@ -46,9 +46,9 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
|
|||||||
|
|
||||||
public static Expression generateConstant(DecafParser.LiteralContext ctx){
|
public static Expression generateConstant(DecafParser.LiteralContext ctx){
|
||||||
if(ctx.NUMBER() != null)
|
if(ctx.NUMBER() != null)
|
||||||
return new IntConstant(Integer.valueOf(ctx.NUMBER().getText()));
|
return new IntLiteral(Integer.valueOf(ctx.NUMBER().getText()));
|
||||||
if(ctx.boolean_() != null)
|
if(ctx.boolean_() != null)
|
||||||
return new BoolConstant(Boolean.valueOf(ctx.boolean_().getText()));
|
return new BoolLiteral(Boolean.valueOf(ctx.boolean_().getText()));
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
src/main/java/de/maishai/ast/AssignSign.java
Normal file
8
src/main/java/de/maishai/ast/AssignSign.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package de.maishai.ast;
|
||||||
|
|
||||||
|
public enum AssignSign {
|
||||||
|
ASSIGN,
|
||||||
|
ADD_ASSIGN,
|
||||||
|
SUB_ASSIGN,
|
||||||
|
MUL_ASSIGN,
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package de.maishai.ast.records;
|
package de.maishai.ast.records;
|
||||||
|
|
||||||
|
|
||||||
public record Assignment(Id loc, Expression value) implements Statement, Expression {
|
import de.maishai.ast.AssignSign;
|
||||||
|
|
||||||
|
public record Assignment(Id loc, AssignSign assignment, Expression value) implements Statement {
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package de.maishai.ast.records;
|
|
||||||
|
|
||||||
|
|
||||||
public record BoolConstant(Boolean value) implements Expression {
|
|
||||||
}
|
|
5
src/main/java/de/maishai/ast/records/BoolLiteral.java
Normal file
5
src/main/java/de/maishai/ast/records/BoolLiteral.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package de.maishai.ast.records;
|
||||||
|
|
||||||
|
|
||||||
|
public record BoolLiteral(Boolean value) implements Expression {
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
package de.maishai.ast.records;
|
|
||||||
|
|
||||||
|
|
||||||
public record CharConstant(char value) implements Expression {
|
|
||||||
}
|
|
5
src/main/java/de/maishai/ast/records/CharLiteral.java
Normal file
5
src/main/java/de/maishai/ast/records/CharLiteral.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package de.maishai.ast.records;
|
||||||
|
|
||||||
|
|
||||||
|
public record CharLiteral(char value) implements Expression {
|
||||||
|
}
|
@ -2,5 +2,5 @@ package de.maishai.ast.records;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record Class(Id id , List<LocalVariable> variables, List<Method> methods) implements Node {
|
public record Class(Id id , List<Field> fields, List<Method> methods) implements Node {
|
||||||
}
|
}
|
||||||
|
6
src/main/java/de/maishai/ast/records/Constructor.java
Normal file
6
src/main/java/de/maishai/ast/records/Constructor.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package de.maishai.ast.records;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record Constructor(Id id, List<Parameter> params, Block block) {
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
package de.maishai.ast.records;
|
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 Binary, BoolLiteral, CharLiteral, Id, IntLiteral, MethodCall, New {
|
||||||
}
|
}
|
||||||
|
4
src/main/java/de/maishai/ast/records/FieldId.java
Normal file
4
src/main/java/de/maishai/ast/records/FieldId.java
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package de.maishai.ast.records;
|
||||||
|
|
||||||
|
public record FieldId(Boolean field, Expression recipient, Id id) {
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
package de.maishai.ast.records;
|
|
||||||
|
|
||||||
|
|
||||||
public record IntConstant(Integer value) implements Expression {
|
|
||||||
}
|
|
5
src/main/java/de/maishai/ast/records/IntLiteral.java
Normal file
5
src/main/java/de/maishai/ast/records/IntLiteral.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package de.maishai.ast.records;
|
||||||
|
|
||||||
|
|
||||||
|
public record IntLiteral(Integer value) implements Expression {
|
||||||
|
}
|
@ -1,8 +1,6 @@
|
|||||||
package de.maishai.ast.records;
|
package de.maishai.ast.records;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record MethodCall(Id id, List<Expression> args) implements Expression, Statement {
|
public record MethodCall(Boolean field, Expression recipient, Id id, List<Expression> args) implements Expression, Statement {
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package de.maishai.ast.records;
|
package de.maishai.ast.records;
|
||||||
|
|
||||||
public sealed interface Node permits Expression, Statement, Block, Class, MainMethod, Method, Parameter, Program, Variable {
|
public sealed interface Node permits Block, Class, Expression, LocalVariable, MainMethod, Method, Parameter, Program, Statement {
|
||||||
}
|
}
|
||||||
|
@ -12,5 +12,5 @@ import de.maishai.ast.records.Return;
|
|||||||
import de.maishai.ast.records.ReturnVoid;
|
import de.maishai.ast.records.ReturnVoid;
|
||||||
import de.maishai.ast.records.While;
|
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 {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user