renamings
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
import lexer.StupsLexer;
|
import lexer.StupsLexer;
|
||||||
import org.antlr.v4.runtime.CharStreams;
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
import org.antlr.v4.runtime.Lexer;
|
import org.antlr.v4.runtime.Lexer;
|
||||||
import parser.Parser;
|
import parser.StupsParser;
|
||||||
import parser.grammar.Grammar;
|
import parser.grammar.Grammar;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -50,9 +50,9 @@ public final class StupsCompiler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Parser parser = Parser.fromGrammar(grammar);
|
StupsParser stupsParser = StupsParser.fromGrammar(grammar);
|
||||||
|
|
||||||
parser.parse(lexer.getAllTokens(), lexer.getVocabulary());
|
stupsParser.parse(lexer.getAllTokens(), lexer.getVocabulary());
|
||||||
|
|
||||||
System.out.println("Compilation completed.");
|
System.out.println("Compilation completed.");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,21 +15,21 @@ import java.util.List;
|
|||||||
|
|
||||||
import static util.Logger.log;
|
import static util.Logger.log;
|
||||||
|
|
||||||
public class Parser {
|
public class StupsParser {
|
||||||
|
|
||||||
private final ParsingTable parsetable;
|
private final ParsingTable parsetable;
|
||||||
|
|
||||||
public Parser(ParsingTable parsetable) {
|
public StupsParser(ParsingTable parsetable) {
|
||||||
this.parsetable = parsetable;
|
this.parsetable = parsetable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Parser fromGrammar(Path path) throws IOException {
|
public static StupsParser fromGrammar(Path path) throws IOException {
|
||||||
return Parser.fromGrammar(Grammar.fromFile(path));
|
return StupsParser.fromGrammar(Grammar.fromFile(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Parser fromGrammar(Grammar grammar) {
|
public static StupsParser fromGrammar(Grammar grammar) {
|
||||||
GrammarAnalyzer analyzer = new GrammarAnalyzer(grammar);
|
GrammarAnalyzer analyzer = new GrammarAnalyzer(grammar);
|
||||||
return new Parser(analyzer.getTable());
|
return new StupsParser(analyzer.getTable());
|
||||||
}
|
}
|
||||||
|
|
||||||
public AST parse(List<? extends Token> token, Vocabulary voc) {
|
public AST parse(List<? extends Token> token, Vocabulary voc) {
|
||||||
@ -34,10 +34,10 @@ class Demo {
|
|||||||
void demoClean() throws URISyntaxException, IOException {
|
void demoClean() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Grammar grammar = Grammar.fromFile(path);
|
Grammar grammar = Grammar.fromFile(path);
|
||||||
Parser parser = Parser.fromGrammar(grammar);
|
StupsParser stupsParser = StupsParser.fromGrammar(grammar);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("General.stups");
|
Lexer lex = this.initLexer("General.stups");
|
||||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
AST tree = stupsParser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||||
|
|
||||||
ASTCompacter.clean(tree, grammar);
|
ASTCompacter.clean(tree, grammar);
|
||||||
}
|
}
|
||||||
@ -46,10 +46,10 @@ class Demo {
|
|||||||
void demoLeftPrecedence() throws URISyntaxException, IOException {
|
void demoLeftPrecedence() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Grammar grammar = Grammar.fromFile(path);
|
Grammar grammar = Grammar.fromFile(path);
|
||||||
Parser parser = Parser.fromGrammar(grammar);
|
StupsParser stupsParser = StupsParser.fromGrammar(grammar);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("General.stups");
|
Lexer lex = this.initLexer("General.stups");
|
||||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
AST tree = stupsParser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||||
|
|
||||||
ASTCompacter.clean(tree, grammar);
|
ASTCompacter.clean(tree, grammar);
|
||||||
ASTBalancer.flip(tree);
|
ASTBalancer.flip(tree);
|
||||||
@ -62,10 +62,10 @@ class Demo {
|
|||||||
void demoOperatorPrecedence() throws URISyntaxException, IOException {
|
void demoOperatorPrecedence() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Grammar grammar = Grammar.fromFile(path);
|
Grammar grammar = Grammar.fromFile(path);
|
||||||
Parser parser = Parser.fromGrammar(grammar);
|
StupsParser stupsParser = StupsParser.fromGrammar(grammar);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("General.stups");
|
Lexer lex = this.initLexer("General.stups");
|
||||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
AST tree = stupsParser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||||
|
|
||||||
ASTCompacter.clean(tree, grammar);
|
ASTCompacter.clean(tree, grammar);
|
||||||
ASTBalancer.flip(tree);
|
ASTBalancer.flip(tree);
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import java.nio.file.Paths;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class LexerParserGrammarTest {
|
class LexerStupsParserGrammarTest {
|
||||||
|
|
||||||
private Lexer initLexer(String program) {
|
private Lexer initLexer(String program) {
|
||||||
try {
|
try {
|
||||||
@ -31,80 +31,80 @@ class LexerParserGrammarTest {
|
|||||||
@Test
|
@Test
|
||||||
void testEmptyFile() throws URISyntaxException, IOException {
|
void testEmptyFile() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Parser parser = Parser.fromGrammar(path);
|
StupsParser stupsParser = StupsParser.fromGrammar(path);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("EmptyFile.stups");
|
Lexer lex = this.initLexer("EmptyFile.stups");
|
||||||
|
|
||||||
assertThat(parser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
assertThat(stupsParser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testEmptyMain() throws URISyntaxException, IOException {
|
void testEmptyMain() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Parser parser = Parser.fromGrammar(path);
|
StupsParser stupsParser = StupsParser.fromGrammar(path);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("EmptyMain.stups");
|
Lexer lex = this.initLexer("EmptyMain.stups");
|
||||||
|
|
||||||
assertThat(parser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
assertThat(stupsParser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGeneralComment() throws URISyntaxException, IOException {
|
void testGeneralComment() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Parser parser = Parser.fromGrammar(path);
|
StupsParser stupsParser = StupsParser.fromGrammar(path);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("GeneralComment.stups");
|
Lexer lex = this.initLexer("GeneralComment.stups");
|
||||||
|
|
||||||
assertThat(parser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
assertThat(stupsParser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void tesMultiDecl() throws URISyntaxException, IOException {
|
void tesMultiDecl() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Parser parser = Parser.fromGrammar(path);
|
StupsParser stupsParser = StupsParser.fromGrammar(path);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("MultipleDeclarations.stups");
|
Lexer lex = this.initLexer("MultipleDeclarations.stups");
|
||||||
|
|
||||||
assertThat(parser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
assertThat(stupsParser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDeclarationAssignment() throws URISyntaxException, IOException {
|
void testDeclarationAssignment() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Parser parser = Parser.fromGrammar(path);
|
StupsParser stupsParser = StupsParser.fromGrammar(path);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("DeclarationAssignment.stups");
|
Lexer lex = this.initLexer("DeclarationAssignment.stups");
|
||||||
|
|
||||||
assertThat(parser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
assertThat(stupsParser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testExpr() throws URISyntaxException, IOException {
|
void testExpr() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Parser parser = Parser.fromGrammar(path);
|
StupsParser stupsParser = StupsParser.fromGrammar(path);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("Expr.stups");
|
Lexer lex = this.initLexer("Expr.stups");
|
||||||
|
|
||||||
assertThat(parser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
assertThat(stupsParser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGeneralWhile() throws URISyntaxException, IOException {
|
void testGeneralWhile() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Parser parser = Parser.fromGrammar(path);
|
StupsParser stupsParser = StupsParser.fromGrammar(path);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("GeneralWhile.stups");
|
Lexer lex = this.initLexer("GeneralWhile.stups");
|
||||||
|
|
||||||
assertThat(parser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
assertThat(stupsParser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGeneralIfElse() throws URISyntaxException, IOException {
|
void testGeneralIfElse() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Parser parser = Parser.fromGrammar(path);
|
StupsParser stupsParser = StupsParser.fromGrammar(path);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("GeneralIfElse.stups");
|
Lexer lex = this.initLexer("GeneralIfElse.stups");
|
||||||
|
|
||||||
assertThat(parser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
assertThat(stupsParser.parse(lex.getAllTokens(), lex.getVocabulary())).isNotNull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,7 +4,7 @@ import lexer.StupsLexer;
|
|||||||
import org.antlr.v4.runtime.CharStreams;
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
import org.antlr.v4.runtime.Lexer;
|
import org.antlr.v4.runtime.Lexer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import parser.Parser;
|
import parser.StupsParser;
|
||||||
import parser.grammar.Grammar;
|
import parser.grammar.Grammar;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -34,10 +34,10 @@ class ASTCompacterTest {
|
|||||||
void testRemoveEpsilon() throws URISyntaxException, IOException {
|
void testRemoveEpsilon() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Grammar grammar = Grammar.fromFile(path);
|
Grammar grammar = Grammar.fromFile(path);
|
||||||
Parser parser = Parser.fromGrammar(grammar);
|
StupsParser stupsParser = StupsParser.fromGrammar(grammar);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("GeneralOperator.stups");
|
Lexer lex = this.initLexer("GeneralOperator.stups");
|
||||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
AST tree = stupsParser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||||
|
|
||||||
assertThat(ASTCompacter.removeEpsilon(tree, grammar)).isEqualTo(2);
|
assertThat(ASTCompacter.removeEpsilon(tree, grammar)).isEqualTo(2);
|
||||||
System.out.println(tree);
|
System.out.println(tree);
|
||||||
@ -47,10 +47,10 @@ class ASTCompacterTest {
|
|||||||
void testCompact() throws URISyntaxException, IOException {
|
void testCompact() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Grammar grammar = Grammar.fromFile(path);
|
Grammar grammar = Grammar.fromFile(path);
|
||||||
Parser parser = Parser.fromGrammar(grammar);
|
StupsParser stupsParser = StupsParser.fromGrammar(grammar);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("GeneralOperator.stups");
|
Lexer lex = this.initLexer("GeneralOperator.stups");
|
||||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
AST tree = stupsParser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||||
|
|
||||||
assertThat(ASTCompacter.compact(tree, grammar)).isEqualTo(14);
|
assertThat(ASTCompacter.compact(tree, grammar)).isEqualTo(14);
|
||||||
System.out.println(tree);
|
System.out.println(tree);
|
||||||
@ -60,10 +60,10 @@ class ASTCompacterTest {
|
|||||||
void testRemoveNullable() throws URISyntaxException, IOException {
|
void testRemoveNullable() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Grammar grammar = Grammar.fromFile(path);
|
Grammar grammar = Grammar.fromFile(path);
|
||||||
Parser parser = Parser.fromGrammar(grammar);
|
StupsParser stupsParser = StupsParser.fromGrammar(grammar);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("GeneralOperator.stups");
|
Lexer lex = this.initLexer("GeneralOperator.stups");
|
||||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
AST tree = stupsParser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||||
ASTCompacter.removeEpsilon(tree, grammar);
|
ASTCompacter.removeEpsilon(tree, grammar);
|
||||||
|
|
||||||
assertThat(ASTCompacter.removeNullable(tree, grammar)).isEqualTo(2);
|
assertThat(ASTCompacter.removeNullable(tree, grammar)).isEqualTo(2);
|
||||||
@ -74,10 +74,10 @@ class ASTCompacterTest {
|
|||||||
void testClean() throws URISyntaxException, IOException {
|
void testClean() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Grammar grammar = Grammar.fromFile(path);
|
Grammar grammar = Grammar.fromFile(path);
|
||||||
Parser parser = Parser.fromGrammar(grammar);
|
StupsParser stupsParser = StupsParser.fromGrammar(grammar);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("GeneralOperator.stups");
|
Lexer lex = this.initLexer("GeneralOperator.stups");
|
||||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
AST tree = stupsParser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||||
|
|
||||||
ASTCompacter.clean(tree, grammar);
|
ASTCompacter.clean(tree, grammar);
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import lexer.StupsLexer;
|
|||||||
import org.antlr.v4.runtime.CharStreams;
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
import org.antlr.v4.runtime.Lexer;
|
import org.antlr.v4.runtime.Lexer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import parser.Parser;
|
import parser.StupsParser;
|
||||||
import parser.ast.AST;
|
import parser.ast.AST;
|
||||||
import parser.grammar.Grammar;
|
import parser.grammar.Grammar;
|
||||||
import typechecker.SymbolAlreadyDefinedException;
|
import typechecker.SymbolAlreadyDefinedException;
|
||||||
@ -38,10 +38,10 @@ class SymbolTableTest {
|
|||||||
void testSingleSymbol() throws URISyntaxException, IOException {
|
void testSingleSymbol() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Grammar grammar = Grammar.fromFile(path);
|
Grammar grammar = Grammar.fromFile(path);
|
||||||
Parser parser = Parser.fromGrammar(grammar);
|
StupsParser stupsParser = StupsParser.fromGrammar(grammar);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("SingleSymbol.stups");
|
Lexer lex = this.initLexer("SingleSymbol.stups");
|
||||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
AST tree = stupsParser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||||
tree.preprocess(grammar);
|
tree.preprocess(grammar);
|
||||||
|
|
||||||
SymbolTable table = SymbolTable.fromAST(tree);
|
SymbolTable table = SymbolTable.fromAST(tree);
|
||||||
@ -54,10 +54,10 @@ class SymbolTableTest {
|
|||||||
void testMultipleSymbol() throws URISyntaxException, IOException {
|
void testMultipleSymbol() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Grammar grammar = Grammar.fromFile(path);
|
Grammar grammar = Grammar.fromFile(path);
|
||||||
Parser parser = Parser.fromGrammar(grammar);
|
StupsParser stupsParser = StupsParser.fromGrammar(grammar);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("MultipleSymbol.stups");
|
Lexer lex = this.initLexer("MultipleSymbol.stups");
|
||||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
AST tree = stupsParser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||||
tree.preprocess(grammar);
|
tree.preprocess(grammar);
|
||||||
|
|
||||||
SymbolTable table = SymbolTable.fromAST(tree);
|
SymbolTable table = SymbolTable.fromAST(tree);
|
||||||
@ -75,10 +75,10 @@ class SymbolTableTest {
|
|||||||
void testExistingSymbol() throws URISyntaxException, IOException {
|
void testExistingSymbol() throws URISyntaxException, IOException {
|
||||||
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
Path path = Paths.get(this.getClass().getClassLoader().getResource("exampleGrammars/Grammar.grammar").toURI());
|
||||||
Grammar grammar = Grammar.fromFile(path);
|
Grammar grammar = Grammar.fromFile(path);
|
||||||
Parser parser = Parser.fromGrammar(grammar);
|
StupsParser stupsParser = StupsParser.fromGrammar(grammar);
|
||||||
|
|
||||||
Lexer lex = this.initLexer("ExistingSymbol.stups");
|
Lexer lex = this.initLexer("ExistingSymbol.stups");
|
||||||
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
|
AST tree = stupsParser.parse(lex.getAllTokens(), lex.getVocabulary());
|
||||||
tree.preprocess(grammar);
|
tree.preprocess(grammar);
|
||||||
|
|
||||||
assertThatThrownBy(() -> SymbolTable.fromAST(tree)).isInstanceOf(SymbolAlreadyDefinedException.class);
|
assertThatThrownBy(() -> SymbolTable.fromAST(tree)).isInstanceOf(SymbolAlreadyDefinedException.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user