still working on task 6

main
simonkellet 1 year ago
parent f13138827f
commit a3f6b13947
  1. 2
      Triangle.Compiler/src/main/java/triangle/abstractSyntaxTrees/visitors/CommandVisitor.java
  2. 19
      Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java
  3. 1
      Triangle.Compiler/src/main/java/triangle/syntacticAnalyzer/Parser.java
  4. 17
      Triangle.Compiler/src/main/java/triangle/treeDrawer/LayoutVisitor.java
  5. BIN
      build/libs/Triangle-Tools.jar
  6. BIN
      loopwhile.tam
  7. 6
      programs/loopwhile.tri

@ -25,6 +25,6 @@ public interface CommandVisitor<TArg, TResult> {
TResult visitWhileCommand(WhileCommand ast, TArg arg); TResult visitWhileCommand(WhileCommand ast, TArg arg);
TResult visitLoopWhile(LoopWhile loopWhile, TArg arg); TResult visitLoopWhile(LoopWhile ast, TArg arg);
} }

@ -189,6 +189,19 @@ public final class Checker implements ActualParameterVisitor<FormalParameter, Vo
return null; return null;
} }
@Override
public Void visitLoopWhile(LoopWhile ast, Void arg) {
ast.C1.visit(this);
var eType = ast.E.visit(this);
checkAndReportError(eType.equals(StdEnvironment.booleanType), "Boolean expression expected here", ast.E);
ast.C2.visit(this);
return null;
}
// Expressions // Expressions
@ -982,10 +995,4 @@ public final class Checker implements ActualParameterVisitor<FormalParameter, Vo
StdEnvironment.booleanType); StdEnvironment.booleanType);
} }
@Override
public Void visitLoopWhile(LoopWhile loopWhile, Void arg) {
// TODO Auto-generated method stub
return null;
}
} }

@ -365,7 +365,6 @@ public class Parser {
accept(Token.BEGIN); accept(Token.BEGIN);
Command c1AST = parseCommand(); //C1 = LOOP Command c1AST = parseCommand(); //C1 = LOOP
accept(Token.END); accept(Token.END);
System.out.println("c1AST: " + c1AST.getPosition()); System.out.println("c1AST: " + c1AST.getPosition());
accept(Token.WHILE); accept(Token.WHILE);

@ -163,6 +163,16 @@ public class LayoutVisitor implements ActualParameterVisitor<Void, DrawingTree>,
var d2 = ast.C.visit(this); var d2 = ast.C.visit(this);
return layoutBinary("WhileCom.", d1, d2); return layoutBinary("WhileCom.", d1, d2);
} }
@Override
public DrawingTree visitLoopWhile(LoopWhile ast, Void arg) {
var d1 = ast.C1.visit(this);
var d2 = ast.E.visit(this);
var d3 = ast.C2.visit(this);
return layoutTernary("LoopWhile.", d1, d2, d3);
}
// Expressions // Expressions
@Override @Override
@ -681,11 +691,4 @@ public class LayoutVisitor implements ActualParameterVisitor<Void, DrawingTree>,
return r; return r;
} }
@Override
public DrawingTree visitLoopWhile(LoopWhile loopWhile, Void arg) {
// TODO Auto-generated method stub
return null;
}
} }

Binary file not shown.

Binary file not shown.

@ -1,10 +1,14 @@
! print out ababababa ! print out ababababa
let let
var a : Integer var a : Integer;
var b : Integer
in in
begin begin
a := 0; a := 0;
b := 10;
putint(b);
loop loop
begin begin
put('a'); put('a');

Loading…
Cancel
Save