From 706e6ee872d19209e231a88b7f5adebe2043f01b Mon Sep 17 00:00:00 2001 From: laurenz Date: Tue, 7 May 2024 15:45:46 +0200 Subject: [PATCH] changed For to explicitly have an assignement in first and last place --- src/main/antlr/Decaf.g4 | 5 +++-- src/main/java/de/maishai/ast/records/For.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/antlr/Decaf.g4 b/src/main/antlr/Decaf.g4 index f1e9cf0..8ee8ad9 100644 --- a/src/main/antlr/Decaf.g4 +++ b/src/main/antlr/Decaf.g4 @@ -19,14 +19,14 @@ param : type id; block : '{' (localVar | stmt)* '}'; stmt : 'if' '(' expr ')' block ('else' block)? #If - | 'for' '(' expr ';' expr ';' expr ')' block #For + | 'for' '(' assignement ';' expr ';' assignement ')' block #For | 'while' '(' expr ')' block #While | 'do' block 'while' '(' expr ')' #DoWhile | 'return' expr ';' #Return | 'return' ';' #ReturnVoid | 'break' ';' #Break | 'continue' ';' #Continue - | id assignSign expr ';' #Assignment + | assignement ';' #Assignment | stmtexpr ';' #StatementExpressionstmt ; @@ -48,6 +48,7 @@ unaryOp : SUB | NOT; fieldId : (THIS '.')? (recipient '.')* id; +assignement : id assignSign expr ; methCall : (THIS '.')? (recipient '.')* methName; recipient : methName | id; methName : id '(' args? ')'; diff --git a/src/main/java/de/maishai/ast/records/For.java b/src/main/java/de/maishai/ast/records/For.java index 1e51e77..0361306 100644 --- a/src/main/java/de/maishai/ast/records/For.java +++ b/src/main/java/de/maishai/ast/records/For.java @@ -1,5 +1,5 @@ package de.maishai.ast.records; -public record For(Expression assign, Expression cond, Expression inc, Block block) implements Statement { +public record For(Assignment assign, Expression cond, Assignment inc, Block block) implements Statement { }