Skip to content

Commit

Permalink
#19 tilføjer ++ og -- statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Joklost committed Apr 22, 2016
1 parent d45e311 commit 20b8915
Show file tree
Hide file tree
Showing 7 changed files with 690 additions and 609 deletions.
2 changes: 2 additions & 0 deletions battlesim-compiler/battlesim.cup
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ Stmt ::= Dcl:d
| FunctionCall:fc MultEOL {: RESULT = new FunctionCallStmt(fc, fcleft); :}
| error EOL
| JAVASTRING:j {: RESULT = new JavaString(j, jleft); :}
| ObjectId:oi PLUSPLUS {: RESULT = new PlusPlusStmt(oi, oileft); :}
| ObjectId:oi MINUSMINUS {: RESULT = new MinusMinusStmt(oi, oileft); :}
;
Dcl ::= DECLARE DclIds:ds AS TypeId:ti MultEOL {: RESULT = new Dcl(ds, ti, dsleft); :}
;
Expand Down
12 changes: 12 additions & 0 deletions battlesim-compiler/src/com/company/AST/Nodes/MinusMinusStmt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.company.AST.Nodes;

/**
* Created by joklost on 4/22/16.
*/
public class MinusMinusStmt extends Stmt {
public IdentifierReferencing id;
public MinusMinusStmt(IdentifierReferencing id, int ln) {
super(ln);
this.id = id;
}
}
12 changes: 12 additions & 0 deletions battlesim-compiler/src/com/company/AST/Nodes/PlusPlusStmt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.company.AST.Nodes;

/**
* Created by joklost on 4/22/16.
*/
public class PlusPlusStmt extends Stmt {
public IdentifierReferencing id;
public PlusPlusStmt(IdentifierReferencing id, int ln) {
super(ln);
this.id = id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public interface VisitorInterface {
void visit(ReturnExpr r);
void visit(Return r);
void visit(FunctionCallStmt fcs);
void visit(PlusPlusStmt s);
void visit(MinusMinusStmt s);
void visit(PlusExpr pe);
void visit(MinusExpr me);
void visit(MultExpr me);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,18 @@ public void visit(FunctionCallStmt fcs) {
emit(";\n");
}

public void visit(PlusPlusStmt s) {
emitIndentation();
s.id.accept(this);
emit("++;\n");
}

public void visit(MinusMinusStmt s) {
emitIndentation();
s.id.accept(this);
emit("--;\n");
}

public void visit(PlusExpr pe) {
emit("(");
pe.leftExpr.accept(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ public void visit(FunctionCallStmt fcs) {
fcs.functionCall.accept(this);
}

public void visit(PlusPlusStmt s) {
s.id.accept(this);
s.type = unaryResultType(plusplusOperator, s.id.type);
}

public void visit(MinusMinusStmt s) {
s.id.accept(this);
s.type = unaryResultType(minusminusOperator, s.id.type);
}

public void visit(PlusExpr pe) {
// binary
pe.leftExpr.accept(this);
Expand Down
1,249 changes: 640 additions & 609 deletions battlesim-compiler/src/com/company/SyntaxAnalysis/Parser.java

Large diffs are not rendered by default.

0 comments on commit 20b8915

Please sign in to comment.