This commit is contained in:
ChUrl
2020-12-13 14:48:20 +01:00
parent 2712318654
commit d949a7fa8b
3 changed files with 77 additions and 55 deletions

View File

@ -43,7 +43,7 @@ class Demo {
}
@Test
void demoBalance() throws URISyntaxException, IOException {
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);
@ -52,6 +52,26 @@ class Demo {
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
ASTCompacter.clean(tree, grammar);
ExpressionBalancer.balance(tree);
ExpressionBalancer.flip(tree);
System.out.println("Before left-precedence:\n" + tree);
ExpressionBalancer.leftPrecedence(tree);
System.out.println("After left-precedence:\n" + tree);
}
@Test
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);
Lexer lex = this.initLexer("General.stups");
AST tree = parser.parse(lex.getAllTokens(), lex.getVocabulary());
ASTCompacter.clean(tree, grammar);
ExpressionBalancer.flip(tree);
ExpressionBalancer.leftPrecedence(tree);
System.out.println("Before operator-precedence:\n" + tree);
ExpressionBalancer.operatorPrecedence(tree);
System.out.println("After operator-precedence:\n" + tree);
}
}

View File

@ -1,7 +1,6 @@
class MyClass {
public static void main(String[] args) {
while (1 < 2)
i = 1;
boolean b = true;
}
}