generator tests finished, library javadoc externalized
This commit is contained in:
parent
a845321785
commit
d1d97bc329
12
.classpath
12
.classpath
|
@ -2,20 +2,24 @@
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||||
<classpathentry kind="lib" path="lib/antlr-4.7-complete.jar" sourcepath="lib/antlr-4.7-source.zip"/>
|
<classpathentry kind="lib" path="lib/antlr-4.7-complete.jar" sourcepath="lib/antlr-4.7-source.zip">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="javadoc_location" value="http://www.antlr.org/api/Java/"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="lib" path="lib/hamcrest-all-1.3.jar">
|
<classpathentry kind="lib" path="lib/hamcrest-all-1.3.jar">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="javadoc_location" value="jar:platform:/resource/Vertalerbouw/lib/hamcrest-all-1.3-javadoc.jar!/"/>
|
<attribute name="javadoc_location" value="http://hamcrest.org/JavaHamcrest/javadoc/1.3/"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="lib" path="lib/junit-4.12.jar">
|
<classpathentry kind="lib" path="lib/junit-4.12.jar">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="javadoc_location" value="jar:platform:/resource/Vertalerbouw/lib/junit-4.12-javadoc.jar!/"/>
|
<attribute name="javadoc_location" value="http://junit.org/junit4/javadoc/4.12/"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="lib" path="lib/commons-lang3-3.5.jar">
|
<classpathentry kind="lib" path="lib/commons-lang3-3.5.jar">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="javadoc_location" value="jar:platform:/resource/Vertalerbouw/lib/commons-lang3-3.5-javadoc.jar!/"/>
|
<attribute name="javadoc_location" value="https://commons.apache.org/proper/commons-lang/javadocs/api-3.6/"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lib/junit.jar
BIN
lib/junit.jar
Binary file not shown.
|
@ -156,7 +156,7 @@ public class BoppiBasicGenerator extends BasicBaseVisitor<Void> {
|
||||||
|
|
||||||
switch (ctx.op.getType()) {
|
switch (ctx.op.getType()) {
|
||||||
case BasicLexer.MINUS:
|
case BasicLexer.MINUS:
|
||||||
emit(OpCode.rsubI, new Num(0), getReg(ctx.singleExpr()), getReg(ctx));
|
emit(OpCode.rsubI, getReg(ctx.singleExpr()), new Num(0), getReg(ctx));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -291,6 +291,7 @@ public class BoppiBasicGenerator extends BasicBaseVisitor<Void> {
|
||||||
emit(OpCode.out, new Str("Unknown type: "), getReg(expr));
|
emit(OpCode.out, new Str("Unknown type: "), getReg(expr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
copyReg(ctx.expr(0), ctx);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,18 @@
|
||||||
package pp.s1184725.boppi.test;
|
package pp.s1184725.boppi.test;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.empty;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
|
||||||
import static org.hamcrest.Matchers.is;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.*;
|
||||||
import java.util.logging.LogRecord;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import pp.s1184725.boppi.Annotations;
|
import pp.s1184725.boppi.*;
|
||||||
import pp.s1184725.boppi.BasicParser;
|
|
||||||
import pp.s1184725.boppi.BasicParserHelper;
|
|
||||||
import pp.s1184725.boppi.BoppiBasicChecker;
|
|
||||||
|
|
||||||
public class CheckerTest {
|
public class CheckerTest {
|
||||||
static final Path directory = Paths.get("src/pp/s1184725/boppi/test/parsing/");
|
static final Path directory = Paths.get("src/pp/s1184725/boppi/test/parsing/");
|
||||||
|
@ -39,9 +32,6 @@ public class CheckerTest {
|
||||||
return pair.getRight();
|
return pair.getRight();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void debug() {
|
|
||||||
log.forEach(entry -> System.out.println(entry.getMessage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,18 @@
|
||||||
package pp.s1184725.boppi.test;
|
package pp.s1184725.boppi.test;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
|
import static org.hamcrest.Matchers.is;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
@ -20,32 +29,83 @@ import pp.s1184725.boppi.BoppiBasicChecker;
|
||||||
import pp.s1184725.boppi.BoppiBasicGenerator;
|
import pp.s1184725.boppi.BoppiBasicGenerator;
|
||||||
|
|
||||||
public class GeneratorTest {
|
public class GeneratorTest {
|
||||||
static private List<LogRecord> generateAndGetLog(String code) {
|
static final Path directory = Paths.get("src/pp/s1184725/boppi/test/parsing/");
|
||||||
|
private Pair<String, List<LogRecord>> result;
|
||||||
|
|
||||||
|
static private Pair<String, List<LogRecord>> generateAndGetLog(String code, String input) {
|
||||||
Logger logger = Logger.getAnonymousLogger();
|
Logger logger = Logger.getAnonymousLogger();
|
||||||
Pair<BasicParser, List<LogRecord>> pair = BasicParserHelper.getParserWithLog(code, logger);
|
Pair<BasicParser, List<LogRecord>> pair = BasicParserHelper.getParserWithLog(code, logger);
|
||||||
|
return derp(logger, pair, input);
|
||||||
|
}
|
||||||
|
|
||||||
|
static private Pair<String, List<LogRecord>> generateAndGetLog(Path code, String input) throws IOException {
|
||||||
|
Logger logger = Logger.getAnonymousLogger();
|
||||||
|
Pair<BasicParser, List<LogRecord>> pair = BasicParserHelper.getParserWithLog(code, logger);
|
||||||
|
return derp(logger, pair, input);
|
||||||
|
}
|
||||||
|
|
||||||
|
static private Pair<String, List<LogRecord>> derp(Logger logger, Pair<BasicParser, List<LogRecord>> pair, String input) {
|
||||||
Annotations annotater = new Annotations();
|
Annotations annotater = new Annotations();
|
||||||
ParserRuleContext tree = pair.getLeft().program();
|
ParserRuleContext tree = pair.getLeft().program();
|
||||||
new BoppiBasicChecker(logger, annotater).visit(tree);
|
new BoppiBasicChecker(logger, annotater).visit(tree);
|
||||||
BoppiBasicGenerator generator = new BoppiBasicGenerator(annotater);
|
BoppiBasicGenerator generator = new BoppiBasicGenerator(annotater);
|
||||||
generator.visit(tree);
|
generator.visit(tree);
|
||||||
// System.out.println(generator.prog.prettyPrint());
|
|
||||||
// System.out.println(BasicParserHelper.getAnnotatedDOT(tree, annotater));
|
|
||||||
Simulator s = new Simulator(generator.prog);
|
Simulator s = new Simulator(generator.prog);
|
||||||
InputStream in = new ByteArrayInputStream("1\nq\n".getBytes(StandardCharsets.UTF_8));
|
InputStream in = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8));
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
s.setIn(in);
|
s.setIn(in);
|
||||||
s.setOut(out);
|
s.setOut(out);
|
||||||
s.run();
|
try {
|
||||||
System.out.println(out.toString());
|
s.run();
|
||||||
return pair.getRight();
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
logger.severe(e.getMessage());
|
||||||
|
}
|
||||||
|
return Pair.of(out.toString().replaceAll("\r\n", "\n"), pair.getRight());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void correctExpressionTest() throws IOException {
|
||||||
|
result = generateAndGetLog(directory.resolve("simpleExpression.boppi"), "");
|
||||||
|
assertThat(result.getRight(), empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void basicTest() {
|
public void wrongExpressionTest() {
|
||||||
// generateAndGetLog("print(5*3)");
|
result = generateAndGetLog("1/0", "");
|
||||||
// generateAndGetLog("var int x; var int y; x := 3*(y := 4); print(x,y)");
|
assertThat(result.getRight(), hasSize(1));
|
||||||
// generateAndGetLog("print('T', 'e', 's', 't', '!')");
|
assertThat(result.getRight().get(0).getMessage(), containsString("zero"));
|
||||||
// generateAndGetLog("var int i; if read(i) == 1 then var char c; read(c); print(c,c); else print(i) fi");
|
}
|
||||||
generateAndGetLog("var int i; i := 10; while i > 0 do print('A', i); i := i-1 od");
|
|
||||||
|
@Test
|
||||||
|
public void correctVariableTest() throws IOException {
|
||||||
|
result = generateAndGetLog(directory.resolve("simpleVariable.boppi"), "");
|
||||||
|
assertThat(result.getRight(), empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void basicPrograms() throws IOException {
|
||||||
|
result = generateAndGetLog("print(5*3)", "");
|
||||||
|
assertThat(result.getRight(), empty());
|
||||||
|
assertThat(result.getLeft(), is("15\n"));
|
||||||
|
|
||||||
|
result = generateAndGetLog("print('T', 'e', 's', 't', '!')", "");
|
||||||
|
assertThat(result.getRight(), empty());
|
||||||
|
assertThat(result.getLeft(), is("T\ne\ns\nt\n!\n"));
|
||||||
|
|
||||||
|
result = generateAndGetLog("var int x; var int y; x := 3*(y := 4); print(x,y)", "");
|
||||||
|
assertThat(result.getRight(), empty());
|
||||||
|
assertThat(result.getLeft(), is("12\n4\n"));
|
||||||
|
|
||||||
|
result = generateAndGetLog(directory.resolve("basicProgram1.boppi"), "1\nT\n");
|
||||||
|
assertThat(result.getRight(), empty());
|
||||||
|
assertThat(result.getLeft(), is("T\nT\n"));
|
||||||
|
|
||||||
|
result = generateAndGetLog(directory.resolve("fibonacciIterative.boppi"), "6\n");
|
||||||
|
assertThat(result.getRight(), empty());
|
||||||
|
assertThat(result.getLeft(), is("13\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
var int i;
|
||||||
|
|
||||||
|
if read(i) == 1 then
|
||||||
|
var char c;
|
||||||
|
read(c);
|
||||||
|
print(c,c);
|
||||||
|
else
|
||||||
|
print(i)
|
||||||
|
fi
|
|
@ -0,0 +1,18 @@
|
||||||
|
var int n;
|
||||||
|
var int i;
|
||||||
|
var int current;
|
||||||
|
var int previous;
|
||||||
|
current := 1;
|
||||||
|
|
||||||
|
read(n);
|
||||||
|
i := 0;
|
||||||
|
|
||||||
|
while i < n do
|
||||||
|
var int next;
|
||||||
|
next := current + previous;
|
||||||
|
previous := current;
|
||||||
|
current := next;
|
||||||
|
i := i+1;
|
||||||
|
od;
|
||||||
|
|
||||||
|
print(current);
|
|
@ -26,3 +26,8 @@ true;
|
||||||
3 == 2;
|
3 == 2;
|
||||||
1 < 2 == false;
|
1 < 2 == false;
|
||||||
!(true <> false) == ('c' == 'd');
|
!(true <> false) == ('c' == 'd');
|
||||||
|
|
||||||
|
// printing
|
||||||
|
print('1');
|
||||||
|
print(1)+4;
|
||||||
|
print(3, 'A', false);
|
||||||
|
|
Loading…
Reference in New Issue