still working on task 6

This commit is contained in:
simonkellet 2023-10-19 17:44:58 +01:00
parent f13138827f
commit a3f6b13947
7 changed files with 29 additions and 16 deletions

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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.

View File

@ -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');