DoStmt zu ASTPrinter hinzufügen

This commit is contained in:
JanUlrich 2017-08-17 15:58:56 +02:00
parent a9c49676a9
commit 52f562b570
6 changed files with 30 additions and 14 deletions

View File

@ -53,6 +53,8 @@ public interface StatementVisitor {
void visit(WhileStmt whileStmt); void visit(WhileStmt whileStmt);
void visit(DoStmt whileStmt);
void visit(Null aNull); void visit(Null aNull);
void visit(Literal literal); void visit(Literal literal);

View File

@ -1,16 +1,18 @@
package de.dhbwstuttgart.syntaxtree.statement; package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.Token;
/**
* Created by Felix_K on 17.08.2017.
*/
public class DoStmt extends WhileStmt public class DoStmt extends WhileStmt
{ {
public DoStmt(Expression expr, Statement loopBlock, Token offset) public DoStmt(Expression expr, Statement loopBlock, Token offset)
{ {
super(expr, loopBlock, offset); super(expr, loopBlock, offset);
} }
@Override
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
} }

View File

@ -21,15 +21,6 @@ public class WhileStmt extends Statement
this.loopBlock = loopBlock; this.loopBlock = loopBlock;
} }
/**
* <br/>Author: Martin Pl�micke
* @return
*/
public String toString()
{
return "WHILE " + loopBlock.toString();
}
@Override @Override
public void accept(StatementVisitor visitor) { public void accept(StatementVisitor visitor) {
visitor.visit(this); visitor.visit(this);

View File

@ -1,5 +1,6 @@
package de.dhbwstuttgart.syntaxtree.visual; package de.dhbwstuttgart.syntaxtree.visual;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.*; import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal; import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
@ -292,7 +293,19 @@ public class OutputGenerator implements ASTVisitor {
@Override @Override
public void visit(WhileStmt whileStmt) { public void visit(WhileStmt whileStmt) {
out.append("while(");
whileStmt.expr.accept(this);
out.append(")");
whileStmt.loopBlock.accept(this);
}
@Override
public void visit(DoStmt whileStmt) {
out.append("do ");
whileStmt.loopBlock.accept(this);
out.append("while(");
whileStmt.expr.accept(this);
out.append(");");
} }
@Override @Override

View File

@ -204,6 +204,11 @@ public class TYPE implements StatementVisitor{
throw new NotImplementedException(); throw new NotImplementedException();
} }
@Override
public void visit(DoStmt whileStmt) {
throw new NotImplementedException();
}
@Override @Override
public void visit(Null aNull) { public void visit(Null aNull) {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@ -1,6 +1,8 @@
package parser; package parser;
import de.dhbwstuttgart.parser.JavaTXParser; import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
@ -15,6 +17,7 @@ public class RunParserTest {
public void testMain() throws Exception { public void testMain() throws Exception {
String[] args = new String[1]; String[] args = new String[1];
args[0] = rootDirectory+"WhileTest.jav"; args[0] = rootDirectory+"WhileTest.jav";
new JavaTXParser().parse(new File(args[0])); SourceFile sf = new JavaTXParser().parse(new File(args[0]));
System.out.println(ASTPrinter.print(sf));
} }
} }