mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 17:08:03 +00:00
assign has it's own rule
This commit is contained in:
parent
706e6ee872
commit
ee0a465c84
@ -19,14 +19,14 @@ param : type id;
|
||||
block : '{' (localVar | stmt)* '}';
|
||||
|
||||
stmt : 'if' '(' expr ')' block ('else' block)? #If
|
||||
| 'for' '(' assignement ';' expr ';' assignement ')' block #For
|
||||
| 'for' '(' assign ';' expr ';' assign ')' block #For
|
||||
| 'while' '(' expr ')' block #While
|
||||
| 'do' block 'while' '(' expr ')' #DoWhile
|
||||
| 'return' expr ';' #Return
|
||||
| 'return' ';' #ReturnVoid
|
||||
| 'break' ';' #Break
|
||||
| 'continue' ';' #Continue
|
||||
| assignement ';' #Assignment
|
||||
| assign ';' #Assignment
|
||||
| stmtexpr ';' #StatementExpressionstmt
|
||||
;
|
||||
|
||||
@ -48,7 +48,7 @@ unaryOp : SUB | NOT;
|
||||
|
||||
fieldId : (THIS '.')? (recipient '.')* id;
|
||||
|
||||
assignement : id assignSign expr ;
|
||||
assign : id assignSign expr ;
|
||||
methCall : (THIS '.')? (recipient '.')* methName;
|
||||
recipient : methName | id;
|
||||
methName : id '(' args? ')';
|
||||
|
@ -25,9 +25,9 @@ public class StatementGenerator extends DecafBaseVisitor<Statement> {
|
||||
|
||||
@Override
|
||||
public For visitFor(DecafParser.ForContext ctx) {
|
||||
Expression init = new ExpressionGenerator().visit(ctx.expr(0));
|
||||
Expression expr = new ExpressionGenerator().visit(ctx.expr(1));
|
||||
Expression update = new ExpressionGenerator().visit(ctx.expr(2));
|
||||
Assignment init = generateAssign(ctx.assign(0));
|
||||
Expression expr = new ExpressionGenerator().visit(ctx.expr());
|
||||
Assignment update = generateAssign(ctx.assign(1));
|
||||
Block block = new BlockGenerator().visit(ctx.block());
|
||||
return new For(init, expr, update, block);
|
||||
}
|
||||
@ -68,6 +68,10 @@ public class StatementGenerator extends DecafBaseVisitor<Statement> {
|
||||
|
||||
@Override
|
||||
public Statement visitAssignment(DecafParser.AssignmentContext ctx) {
|
||||
return generateAssign(ctx.assign());
|
||||
}
|
||||
|
||||
private Assignment generateAssign(DecafParser.AssignContext ctx) {
|
||||
Id id = new Id(ctx.id().getText());
|
||||
AssignSign sign = getAssignSign(ctx.assignSign());
|
||||
Expression expr = new ExpressionGenerator().visit(ctx.expr());
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
||||
// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
|
||||
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
|
||||
package de.maishai.antlr;
|
||||
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
@ -432,6 +432,18 @@ public class DecafBaseListener implements DecafListener {
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitFieldId(DecafParser.FieldIdContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterAssign(DecafParser.AssignContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitAssign(DecafParser.AssignContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
|
||||
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
|
||||
package de.maishai.antlr;
|
||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||
|
||||
@ -257,6 +257,13 @@ public class DecafBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitFieldId(DecafParser.FieldIdContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitAssign(DecafParser.AssignContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
|
||||
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
|
||||
package de.maishai.antlr;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
|
||||
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
|
||||
package de.maishai.antlr;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||
|
||||
@ -395,6 +395,16 @@ public interface DecafListener extends ParseTreeListener {
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitFieldId(DecafParser.FieldIdContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#assign}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterAssign(DecafParser.AssignContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#assign}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitAssign(DecafParser.AssignContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#methCall}.
|
||||
* @param ctx the parse tree
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
|
||||
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/Projekt/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1
|
||||
package de.maishai.antlr;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
||||
|
||||
@ -239,6 +239,12 @@ public interface DecafVisitor<T> extends ParseTreeVisitor<T> {
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitFieldId(DecafParser.FieldIdContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#assign}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitAssign(DecafParser.AssignContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#methCall}.
|
||||
* @param ctx the parse tree
|
||||
|
Loading…
Reference in New Issue
Block a user