add test to try things out

This commit is contained in:
ChUrl
2020-12-11 18:34:04 +01:00
parent 374b994b29
commit 50a57387cc
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,42 @@
package parser;
import lexer.StupsLexer;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.Lexer;
import org.junit.jupiter.api.Test;
import parser.grammar.Grammar;
import util.ast.AST;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
class GeneralTest {
private Lexer initLexer(String program) {
try {
Path path = Paths.get(this.getClass().getClassLoader().getResource("examplePrograms/" + program).toURI());
String programCode = Files.readString(path, StandardCharsets.US_ASCII);
return new StupsLexer(CharStreams.fromString(programCode));
} catch (Exception ignore) {
ignore.printStackTrace();
}
return null;
}
@Test
void testClean() throws URISyntaxException, IOException {
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
Grammar grammar = Grammar.fromFile(path);
LL1Parser parser = LL1Parser.fromGrammar(grammar);
Lexer lex = this.initLexer("General.stups");
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
ASTCompacter.clean(tree, grammar);
}
}

View File

@ -0,0 +1,6 @@
class MyClass {
public static void main(String[] args) {
int a = (1 + 2) * 3;
}
}