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