forked from JavaTX/JavaCompilerCore
DoStmt zu ASTPrinter hinzufügen
This commit is contained in:
parent
a9c49676a9
commit
52f562b570
@ -53,6 +53,8 @@ public interface StatementVisitor {
|
||||
|
||||
void visit(WhileStmt whileStmt);
|
||||
|
||||
void visit(DoStmt whileStmt);
|
||||
|
||||
void visit(Null aNull);
|
||||
|
||||
void visit(Literal literal);
|
||||
|
@ -1,16 +1,18 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
/**
|
||||
* Created by Felix_K on 17.08.2017.
|
||||
*/
|
||||
public class DoStmt extends WhileStmt
|
||||
{
|
||||
|
||||
public DoStmt(Expression expr, Statement loopBlock, Token offset)
|
||||
{
|
||||
super(expr, loopBlock, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -21,15 +21,6 @@ public class WhileStmt extends Statement
|
||||
this.loopBlock = loopBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* <br/>Author: Martin Pl�micke
|
||||
* @return
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return "WHILE " + loopBlock.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.visual;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
|
||||
@ -292,7 +293,19 @@ public class OutputGenerator implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
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
|
||||
|
@ -204,6 +204,11 @@ public class TYPE implements StatementVisitor{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DoStmt whileStmt) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Null aNull) {
|
||||
throw new NotImplementedException();
|
||||
|
@ -1,6 +1,8 @@
|
||||
package parser;
|
||||
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@ -15,6 +17,7 @@ public class RunParserTest {
|
||||
public void testMain() throws Exception {
|
||||
String[] args = new String[1];
|
||||
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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user