renamings
This commit is contained in:
@ -5,8 +5,8 @@ import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import parser.ast.AST;
|
||||
import parser.ast.ASTBalancer;
|
||||
import parser.ast.ASTCompacter;
|
||||
import parser.ast.ExpressionBalancer;
|
||||
import parser.grammar.Grammar;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -34,7 +34,7 @@ class Demo {
|
||||
void demoClean() 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);
|
||||
Parser parser = Parser.fromGrammar(grammar);
|
||||
|
||||
Lexer lex = this.initLexer("General.stups");
|
||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||
@ -46,15 +46,15 @@ class Demo {
|
||||
void demoLeftPrecedence() 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);
|
||||
Parser parser = Parser.fromGrammar(grammar);
|
||||
|
||||
Lexer lex = this.initLexer("General.stups");
|
||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||
|
||||
ASTCompacter.clean(tree, grammar);
|
||||
ExpressionBalancer.flip(tree);
|
||||
ASTBalancer.flip(tree);
|
||||
System.out.println("Before left-precedence:\n" + tree);
|
||||
ExpressionBalancer.leftPrecedence(tree);
|
||||
ASTBalancer.leftPrecedence(tree);
|
||||
System.out.println("After left-precedence:\n" + tree);
|
||||
}
|
||||
|
||||
@ -62,16 +62,16 @@ class Demo {
|
||||
void demoOperatorPrecedence() 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);
|
||||
Parser parser = Parser.fromGrammar(grammar);
|
||||
|
||||
Lexer lex = this.initLexer("General.stups");
|
||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||
|
||||
ASTCompacter.clean(tree, grammar);
|
||||
ExpressionBalancer.flip(tree);
|
||||
ExpressionBalancer.leftPrecedence(tree);
|
||||
ASTBalancer.flip(tree);
|
||||
ASTBalancer.leftPrecedence(tree);
|
||||
System.out.println("Before operator-precedence:\n" + tree);
|
||||
ExpressionBalancer.operatorPrecedence(tree);
|
||||
ASTBalancer.operatorPrecedence(tree);
|
||||
System.out.println("After operator-precedence:\n" + tree);
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ class LexerParserGrammarTest {
|
||||
@Test
|
||||
void testEmptyFile() throws URISyntaxException, IOException {
|
||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||
LL1Parser parser = LL1Parser.fromGrammar(path);
|
||||
Parser parser = Parser.fromGrammar(path);
|
||||
|
||||
Lexer lex = this.initLexer("EmptyFile.stups");
|
||||
|
||||
@ -41,7 +41,7 @@ class LexerParserGrammarTest {
|
||||
@Test
|
||||
void testEmptyMain() throws URISyntaxException, IOException {
|
||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||
LL1Parser parser = LL1Parser.fromGrammar(path);
|
||||
Parser parser = Parser.fromGrammar(path);
|
||||
|
||||
Lexer lex = this.initLexer("EmptyMain.stups");
|
||||
|
||||
@ -51,7 +51,7 @@ class LexerParserGrammarTest {
|
||||
@Test
|
||||
void testGeneralComment() throws URISyntaxException, IOException {
|
||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||
LL1Parser parser = LL1Parser.fromGrammar(path);
|
||||
Parser parser = Parser.fromGrammar(path);
|
||||
|
||||
Lexer lex = this.initLexer("GeneralComment.stups");
|
||||
|
||||
@ -61,7 +61,7 @@ class LexerParserGrammarTest {
|
||||
@Test
|
||||
void tesMultiDecl() throws URISyntaxException, IOException {
|
||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||
LL1Parser parser = LL1Parser.fromGrammar(path);
|
||||
Parser parser = Parser.fromGrammar(path);
|
||||
|
||||
Lexer lex = this.initLexer("MultipleDeclarations.stups");
|
||||
|
||||
@ -71,7 +71,7 @@ class LexerParserGrammarTest {
|
||||
@Test
|
||||
void testDeclarationAssignment() throws URISyntaxException, IOException {
|
||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||
LL1Parser parser = LL1Parser.fromGrammar(path);
|
||||
Parser parser = Parser.fromGrammar(path);
|
||||
|
||||
Lexer lex = this.initLexer("DeclarationAssignment.stups");
|
||||
|
||||
@ -81,7 +81,7 @@ class LexerParserGrammarTest {
|
||||
@Test
|
||||
void testExpr() throws URISyntaxException, IOException {
|
||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||
LL1Parser parser = LL1Parser.fromGrammar(path);
|
||||
Parser parser = Parser.fromGrammar(path);
|
||||
|
||||
Lexer lex = this.initLexer("Expr.stups");
|
||||
|
||||
@ -91,7 +91,7 @@ class LexerParserGrammarTest {
|
||||
@Test
|
||||
void testGeneralWhile() throws URISyntaxException, IOException {
|
||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||
LL1Parser parser = LL1Parser.fromGrammar(path);
|
||||
Parser parser = Parser.fromGrammar(path);
|
||||
|
||||
Lexer lex = this.initLexer("GeneralWhile.stups");
|
||||
|
||||
@ -101,7 +101,7 @@ class LexerParserGrammarTest {
|
||||
@Test
|
||||
void testGeneralIfElse() throws URISyntaxException, IOException {
|
||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||
LL1Parser parser = LL1Parser.fromGrammar(path);
|
||||
Parser parser = Parser.fromGrammar(path);
|
||||
|
||||
Lexer lex = this.initLexer("GeneralIfElse.stups");
|
||||
|
||||
|
||||
@ -4,22 +4,22 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class ExpressionBalancerTest {
|
||||
class ASTBalancerTest {
|
||||
|
||||
//EXPR
|
||||
//├── EXPR: SUB
|
||||
//| └── INTEGER_LIT: 2
|
||||
//└── INTEGER_LIT: 1
|
||||
private static AST tree1() {
|
||||
AST tree = new AST(new Node("EXPR"));
|
||||
AST tree = new AST(new ASTNode("EXPR"));
|
||||
|
||||
Node right = new Node("INTEGER_LIT");
|
||||
ASTNode right = new ASTNode("INTEGER_LIT");
|
||||
right.setValue("1");
|
||||
|
||||
Node left = new Node("EXPR");
|
||||
ASTNode left = new ASTNode("EXPR");
|
||||
left.setValue("SUB");
|
||||
|
||||
Node lleft = new Node("INTEGER_LIT");
|
||||
ASTNode lleft = new ASTNode("INTEGER_LIT");
|
||||
lleft.setValue("2");
|
||||
left.setChildren(lleft);
|
||||
|
||||
@ -29,21 +29,21 @@ class ExpressionBalancerTest {
|
||||
}
|
||||
|
||||
private static AST tree2() {
|
||||
AST tree = new AST(new Node("EXPR"));
|
||||
AST tree = new AST(new ASTNode("EXPR"));
|
||||
|
||||
Node right = new Node("INTEGER_LIT");
|
||||
ASTNode right = new ASTNode("INTEGER_LIT");
|
||||
right.setValue("1");
|
||||
|
||||
Node left = new Node("EXPR");
|
||||
ASTNode left = new ASTNode("EXPR");
|
||||
left.setValue("SUB");
|
||||
|
||||
Node lleft = new Node("EXPR");
|
||||
ASTNode lleft = new ASTNode("EXPR");
|
||||
lleft.setValue("SUB");
|
||||
|
||||
Node lright = new Node("INTEGER_LIT");
|
||||
ASTNode lright = new ASTNode("INTEGER_LIT");
|
||||
lright.setValue("2");
|
||||
|
||||
Node llleft = new Node("INTEGER_LIT");
|
||||
ASTNode llleft = new ASTNode("INTEGER_LIT");
|
||||
llleft.setValue("3");
|
||||
|
||||
lleft.setChildren(llleft);
|
||||
@ -55,21 +55,21 @@ class ExpressionBalancerTest {
|
||||
}
|
||||
|
||||
private static AST tree3() {
|
||||
AST tree = new AST(new Node("EXPR"));
|
||||
AST tree = new AST(new ASTNode("EXPR"));
|
||||
|
||||
Node right = new Node("INTEGER_LIT");
|
||||
ASTNode right = new ASTNode("INTEGER_LIT");
|
||||
right.setValue("1");
|
||||
|
||||
Node left = new Node("EXPR");
|
||||
ASTNode left = new ASTNode("EXPR");
|
||||
left.setValue("SUB");
|
||||
|
||||
Node lleft = new Node("EXPR");
|
||||
ASTNode lleft = new ASTNode("EXPR");
|
||||
lleft.setValue("MUL");
|
||||
|
||||
Node lright = new Node("INTEGER_LIT");
|
||||
ASTNode lright = new ASTNode("INTEGER_LIT");
|
||||
lright.setValue("2");
|
||||
|
||||
Node llleft = new Node("INTEGER_LIT");
|
||||
ASTNode llleft = new ASTNode("INTEGER_LIT");
|
||||
llleft.setValue("3");
|
||||
|
||||
lleft.setChildren(llleft);
|
||||
@ -85,7 +85,7 @@ class ExpressionBalancerTest {
|
||||
AST tree = tree1();
|
||||
System.out.println("Before:\n" + tree);
|
||||
|
||||
ExpressionBalancer.flip(tree);
|
||||
ASTBalancer.flip(tree);
|
||||
System.out.println("After:\n" + tree);
|
||||
|
||||
assertThat(tree.getRoot().getChildren().get(0).getName()).isEqualTo("INTEGER_LIT");
|
||||
@ -97,8 +97,8 @@ class ExpressionBalancerTest {
|
||||
AST tree = tree1();
|
||||
System.out.println("Before:\n" + tree);
|
||||
|
||||
ExpressionBalancer.flip(tree);
|
||||
ExpressionBalancer.flip(tree);
|
||||
ASTBalancer.flip(tree);
|
||||
ASTBalancer.flip(tree);
|
||||
System.out.println("After:\n" + tree);
|
||||
|
||||
assertThat(tree).isEqualTo(tree1());
|
||||
@ -109,7 +109,7 @@ class ExpressionBalancerTest {
|
||||
AST tree = tree2();
|
||||
System.out.println("Before:\n" + tree);
|
||||
|
||||
ExpressionBalancer.flip(tree);
|
||||
ASTBalancer.flip(tree);
|
||||
System.out.println("After:\n" + tree);
|
||||
|
||||
assertThat(tree.getRoot().getChildren().get(0).getName()).isEqualTo("INTEGER_LIT");
|
||||
@ -123,8 +123,8 @@ class ExpressionBalancerTest {
|
||||
AST tree = tree2();
|
||||
System.out.println("Before:\n" + tree);
|
||||
|
||||
ExpressionBalancer.flip(tree);
|
||||
ExpressionBalancer.flip(tree);
|
||||
ASTBalancer.flip(tree);
|
||||
ASTBalancer.flip(tree);
|
||||
System.out.println("After:\n" + tree);
|
||||
|
||||
assertThat(tree).isEqualTo(tree2());
|
||||
@ -133,10 +133,10 @@ class ExpressionBalancerTest {
|
||||
@Test
|
||||
void testTree1LeftPrecedence() {
|
||||
AST tree = tree1();
|
||||
ExpressionBalancer.flip(tree);
|
||||
ASTBalancer.flip(tree);
|
||||
System.out.println("Before:\n" + tree);
|
||||
|
||||
ExpressionBalancer.leftPrecedence(tree);
|
||||
ASTBalancer.leftPrecedence(tree);
|
||||
System.out.println("After:\n" + tree);
|
||||
|
||||
assertThat(tree.size()).isEqualTo(3);
|
||||
@ -146,10 +146,10 @@ class ExpressionBalancerTest {
|
||||
@Test
|
||||
void testTree2LeftPrecedence() {
|
||||
AST tree = tree2();
|
||||
ExpressionBalancer.flip(tree);
|
||||
ASTBalancer.flip(tree);
|
||||
System.out.println("Before:\n" + tree);
|
||||
|
||||
ExpressionBalancer.leftPrecedence(tree);
|
||||
ASTBalancer.leftPrecedence(tree);
|
||||
System.out.println("After:\n" + tree);
|
||||
|
||||
assertThat(tree.size()).isEqualTo(5);
|
||||
@ -159,15 +159,15 @@ class ExpressionBalancerTest {
|
||||
@Test
|
||||
void testTree2OperatorPrecedence() {
|
||||
AST tree = tree2();
|
||||
ExpressionBalancer.flip(tree);
|
||||
ExpressionBalancer.leftPrecedence(tree);
|
||||
ASTBalancer.flip(tree);
|
||||
ASTBalancer.leftPrecedence(tree);
|
||||
System.out.println("Before:\n" + tree);
|
||||
|
||||
AST tree1 = tree2();
|
||||
ExpressionBalancer.flip(tree1);
|
||||
ExpressionBalancer.leftPrecedence(tree1);
|
||||
ASTBalancer.flip(tree1);
|
||||
ASTBalancer.leftPrecedence(tree1);
|
||||
|
||||
ExpressionBalancer.operatorPrecedence(tree);
|
||||
ASTBalancer.operatorPrecedence(tree);
|
||||
System.out.println("After:\n" + tree);
|
||||
|
||||
assertThat(tree).isEqualTo(tree1);
|
||||
@ -176,13 +176,13 @@ class ExpressionBalancerTest {
|
||||
@Test
|
||||
void testTree3OperatorPrecedence() {
|
||||
AST tree = tree3();
|
||||
ExpressionBalancer.flip(tree);
|
||||
ExpressionBalancer.leftPrecedence(tree);
|
||||
ASTBalancer.flip(tree);
|
||||
ASTBalancer.leftPrecedence(tree);
|
||||
System.out.println("Before:\n" + tree);
|
||||
|
||||
assertThat(tree.getRoot().getValue()).isEqualTo("MUL");
|
||||
|
||||
ExpressionBalancer.operatorPrecedence(tree);
|
||||
ASTBalancer.operatorPrecedence(tree);
|
||||
System.out.println("After:\n" + tree);
|
||||
|
||||
assertThat(tree.size()).isEqualTo(5);
|
||||
@ -4,7 +4,7 @@ import lexer.StupsLexer;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import parser.LL1Parser;
|
||||
import parser.Parser;
|
||||
import parser.grammar.Grammar;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -34,7 +34,7 @@ class ASTCompacterTest {
|
||||
void testRemoveEpsilon() 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);
|
||||
Parser parser = Parser.fromGrammar(grammar);
|
||||
|
||||
Lexer lex = this.initLexer("GeneralOperator.stups");
|
||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||
@ -47,7 +47,7 @@ class ASTCompacterTest {
|
||||
void testCompact() 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);
|
||||
Parser parser = Parser.fromGrammar(grammar);
|
||||
|
||||
Lexer lex = this.initLexer("GeneralOperator.stups");
|
||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||
@ -60,7 +60,7 @@ class ASTCompacterTest {
|
||||
void testRemoveNullable() 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);
|
||||
Parser parser = Parser.fromGrammar(grammar);
|
||||
|
||||
Lexer lex = this.initLexer("GeneralOperator.stups");
|
||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||
@ -74,7 +74,7 @@ class ASTCompacterTest {
|
||||
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);
|
||||
Parser parser = Parser.fromGrammar(grammar);
|
||||
|
||||
Lexer lex = this.initLexer("GeneralOperator.stups");
|
||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||
|
||||
@ -8,7 +8,7 @@ class ASTTest {
|
||||
|
||||
@Test
|
||||
void testOneNode() {
|
||||
Node root = new Node("Wurzel");
|
||||
ASTNode root = new ASTNode("Wurzel");
|
||||
|
||||
AST tree = new AST(root);
|
||||
System.out.println(tree);
|
||||
@ -18,9 +18,9 @@ class ASTTest {
|
||||
|
||||
@Test
|
||||
void testThreeNodesBinary() {
|
||||
Node root = new Node("Wurzel");
|
||||
Node childA = new Node("A");
|
||||
Node childB = new Node("B");
|
||||
ASTNode root = new ASTNode("Wurzel");
|
||||
ASTNode childA = new ASTNode("A");
|
||||
ASTNode childB = new ASTNode("B");
|
||||
|
||||
root.addChild(childA);
|
||||
root.addChild(childB);
|
||||
@ -33,9 +33,9 @@ class ASTTest {
|
||||
|
||||
@Test
|
||||
void testThreeNodesLinear() {
|
||||
Node root = new Node("Wurzel");
|
||||
Node childA = new Node("A");
|
||||
Node childB = new Node("B");
|
||||
ASTNode root = new ASTNode("Wurzel");
|
||||
ASTNode childA = new ASTNode("A");
|
||||
ASTNode childB = new ASTNode("B");
|
||||
|
||||
root.addChild(childA);
|
||||
childA.addChild(childB);
|
||||
|
||||
@ -2,7 +2,7 @@ package parser.grammar;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import parser.LL1ParsingTable;
|
||||
import parser.ParsingTable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@ -10,7 +10,7 @@ import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class LL1GrammarAnalyzerTest {
|
||||
class GrammarAnalyzerTest {
|
||||
|
||||
private static Grammar grammar0;
|
||||
private static Grammar grammar1;
|
||||
@ -108,7 +108,7 @@ class LL1GrammarAnalyzerTest {
|
||||
|
||||
@Test
|
||||
void testFirstGrammar0() {
|
||||
LL1GrammarAnalyzer analyzer = new LL1GrammarAnalyzer(grammar0);
|
||||
GrammarAnalyzer analyzer = new GrammarAnalyzer(grammar0);
|
||||
|
||||
assertThat(analyzer.getFirst().get("S")).containsOnly("i", "a");
|
||||
assertThat(analyzer.getFirst().get("E")).containsOnly("b");
|
||||
@ -116,7 +116,7 @@ class LL1GrammarAnalyzerTest {
|
||||
|
||||
@Test
|
||||
void testFirstGrammar1() {
|
||||
LL1GrammarAnalyzer analyzer = new LL1GrammarAnalyzer(grammar1);
|
||||
GrammarAnalyzer analyzer = new GrammarAnalyzer(grammar1);
|
||||
|
||||
assertThat(analyzer.getFirst().get("E")).containsOnly("id", "(");
|
||||
assertThat(analyzer.getFirst().get("E2")).containsOnly("+", grammar1.getEpsilonSymbol());
|
||||
@ -127,7 +127,7 @@ class LL1GrammarAnalyzerTest {
|
||||
|
||||
@Test
|
||||
void testFirstGrammar2() {
|
||||
LL1GrammarAnalyzer analyzer = new LL1GrammarAnalyzer(grammar2);
|
||||
GrammarAnalyzer analyzer = new GrammarAnalyzer(grammar2);
|
||||
|
||||
assertThat(analyzer.getFirst().get("X")).containsOnly("c", "a", grammar2.getEpsilonSymbol());
|
||||
assertThat(analyzer.getFirst().get("Y")).containsOnly("c", grammar2.getEpsilonSymbol());
|
||||
@ -136,7 +136,7 @@ class LL1GrammarAnalyzerTest {
|
||||
|
||||
@Test
|
||||
void testFollowGrammar0() {
|
||||
LL1GrammarAnalyzer analyzer = new LL1GrammarAnalyzer(grammar0);
|
||||
GrammarAnalyzer analyzer = new GrammarAnalyzer(grammar0);
|
||||
|
||||
assertThat(analyzer.getFollow().get("S")).containsOnly("$");
|
||||
assertThat(analyzer.getFollow().get("E")).containsOnly("t");
|
||||
@ -144,7 +144,7 @@ class LL1GrammarAnalyzerTest {
|
||||
|
||||
@Test
|
||||
void testFollowGrammar1() {
|
||||
LL1GrammarAnalyzer analyzer = new LL1GrammarAnalyzer(grammar1);
|
||||
GrammarAnalyzer analyzer = new GrammarAnalyzer(grammar1);
|
||||
|
||||
assertThat(analyzer.getFollow().get("E")).containsOnly(")", "$");
|
||||
assertThat(analyzer.getFollow().get("E2")).containsOnly(")", "$");
|
||||
@ -155,7 +155,7 @@ class LL1GrammarAnalyzerTest {
|
||||
|
||||
@Test
|
||||
void testFollowGrammar2() {
|
||||
LL1GrammarAnalyzer analyzer = new LL1GrammarAnalyzer(grammar2);
|
||||
GrammarAnalyzer analyzer = new GrammarAnalyzer(grammar2);
|
||||
|
||||
assertThat(analyzer.getFollow().get("X")).containsOnly("a", "c", "d");
|
||||
assertThat(analyzer.getFollow().get("Y")).containsOnly("a", "c", "d");
|
||||
@ -164,8 +164,8 @@ class LL1GrammarAnalyzerTest {
|
||||
|
||||
@Test
|
||||
void testTableGrammar1() {
|
||||
LL1GrammarAnalyzer analyzer = new LL1GrammarAnalyzer(grammar1);
|
||||
LL1ParsingTable table = analyzer.getTable();
|
||||
GrammarAnalyzer analyzer = new GrammarAnalyzer(grammar1);
|
||||
ParsingTable table = analyzer.getTable();
|
||||
|
||||
assertThat(table.get("E", "id")).isEqualTo("T E2");
|
||||
assertThat(table.get("E", "(")).isEqualTo("T E2");
|
||||
@ -4,7 +4,7 @@ import lexer.StupsLexer;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import parser.LL1Parser;
|
||||
import parser.Parser;
|
||||
import parser.ast.AST;
|
||||
import parser.grammar.Grammar;
|
||||
import typechecker.SymbolAlreadyDefinedException;
|
||||
@ -38,7 +38,7 @@ class SymbolTableTest {
|
||||
void testSingleSymbol() 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);
|
||||
Parser parser = Parser.fromGrammar(grammar);
|
||||
|
||||
Lexer lex = this.initLexer("SingleSymbol.stups");
|
||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||
@ -54,7 +54,7 @@ class SymbolTableTest {
|
||||
void testMultipleSymbol() 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);
|
||||
Parser parser = Parser.fromGrammar(grammar);
|
||||
|
||||
Lexer lex = this.initLexer("MultipleSymbol.stups");
|
||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||
@ -75,7 +75,7 @@ class SymbolTableTest {
|
||||
void testExistingSymbol() 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);
|
||||
Parser parser = Parser.fromGrammar(grammar);
|
||||
|
||||
Lexer lex = this.initLexer("ExistingSymbol.stups");
|
||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||
|
||||
Reference in New Issue
Block a user