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 visitLoopWhile(LoopWhile loopWhile, TArg arg);
TResult visitLoopWhile(LoopWhile ast, TArg arg);
}

@ -190,6 +190,19 @@ public final class Checker implements ActualParameterVisitor<FormalParameter, Vo
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
// Returns the TypeDenoter denoting the type of the expression. Does
@ -982,10 +995,4 @@ public final class Checker implements ActualParameterVisitor<FormalParameter, Vo
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);
Command c1AST = parseCommand(); //C1 = LOOP
accept(Token.END);
System.out.println("c1AST: " + c1AST.getPosition());
accept(Token.WHILE);

@ -164,6 +164,16 @@ public class LayoutVisitor implements ActualParameterVisitor<Void, DrawingTree>,
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
@Override
public DrawingTree visitArrayExpression(ArrayExpression ast, Void obj) {
@ -681,11 +691,4 @@ public class LayoutVisitor implements ActualParameterVisitor<Void, DrawingTree>,
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
let
var a : Integer
var a : Integer;
var b : Integer
in
begin
a := 0;
b := 10;
putint(b);
loop
begin
put('a');

Loading…
Cancel
Save