@Test public void testParser3() { GrammarGraph graph = GrammarGraph.from(grammar, input3, Configuration.DEFAULT); ParseResult result = Iguana.parse(input3, graph, startSymbol); assertTrue(result.isParseSuccess()); assertEquals(getParseResult3(graph), result); assertEquals(getTree3(), result.asParseSuccess().getTree()); }
@Test public void testParser2() { GrammarGraph graph = GrammarGraph.from(grammar, input2); ParseResult result = Iguana.parse(input2, graph, startSymbol); assertTrue(result.isParseSuccess()); assertEquals(getParseResult2(graph), result); assertEquals(getTree2(), result.asParseSuccess().getTree()); }
@Test public void test() { System.out.println(grammar); // Input input = Input.fromString("xawz"); Input input = Input.fromString("xyaw"); GrammarGraph graph = GrammarGraph.from(grammar, input, Configuration.DEFAULT); ParseResult result = Iguana.parse(input, graph, Nonterminal.withName("S")); }
@Test public void test() { System.out.println(grammar); grammar = new EBNFToBNF().transform(grammar); System.out.println(grammar); Input input = Input.fromString("abcbcbc"); GrammarGraph graph = GrammarGraph.from(grammar, input, Configuration.DEFAULT); ParseResult result = Iguana.parse(input, graph, Nonterminal.withName("X")); Assert.assertTrue(result.isParseSuccess()); // Visualization.generateGrammarGraph("/Users/anastasiaizmaylova/git/diguana/test/org/jgll/parser/datadependent/", graph); // Visualization.generateSPPFGraph("/Users/anastasiaizmaylova/git/diguana/test/org/jgll/parser/datadependent/", // result.asParseSuccess().getSPPFNode(), input); Assert.assertTrue(result.asParseSuccess().getStatistics().getCountAmbiguousNodes() == 0); }
@Test public void test() { Grammar grammar = Grammar.builder() // $default$ ::= {UNDEFINED,-1,NON_REC} PREC(1,1) .addRule( Rule.withHead(Nonterminal.builder("$default$").build()) .setLayoutStrategy(NO_LAYOUT) .setRecursion(Recursion.NON_REC) .setAssociativity(Associativity.UNDEFINED) .setPrecedence(-1) .setPrecedenceLevel(PrecedenceLevel.from(1, 1, -1, false, false, false, false)) .build()) // E ::= ('-') E {UNDEFINED,1,RIGHT_REC} PREC(1,1) .addRule( Rule.withHead(Nonterminal.builder("E").build()) .addSymbol( Terminal.builder(Sequence.builder(Character.builder(45).build()).build()) .build()) .addSymbol(Nonterminal.builder("E").build()) .setRecursion(Recursion.RIGHT_REC) .setAssociativity(Associativity.UNDEFINED) .setPrecedence(1) .setPrecedenceLevel(PrecedenceLevel.from(1, 1, 1, true, false, false, false)) .build()) // E ::= ('a') {UNDEFINED,-1,NON_REC} PREC(1,1) .addRule( Rule.withHead(Nonterminal.builder("E").build()) .addSymbol( Terminal.builder(Sequence.builder(Character.builder(97).build()).build()) .build()) .setRecursion(Recursion.NON_REC) .setAssociativity(Associativity.UNDEFINED) .setPrecedence(-1) .setPrecedenceLevel(PrecedenceLevel.from(1, 1, 1, true, false, false, false)) .build()) // E ::= E ('^') E {LEFT,2,LEFT_RIGHT_REC} PREC(2,2) .addRule( Rule.withHead(Nonterminal.builder("E").build()) .addSymbol(Nonterminal.builder("E").build()) .addSymbol( Terminal.builder(Sequence.builder(Character.builder(94).build()).build()) .build()) .addSymbol(Nonterminal.builder("E").build()) .setRecursion(Recursion.LEFT_RIGHT_REC) .setAssociativity(Associativity.LEFT) .setPrecedence(2) .setPrecedenceLevel(PrecedenceLevel.from(2, 2, -1, false, false, true, false)) .build()) // E ::= E ('*') E {UNDEFINED,3,LEFT_RIGHT_REC} PREC(3,3) .addRule( Rule.withHead(Nonterminal.builder("E").build()) .addSymbol(Nonterminal.builder("E").build()) .addSymbol( Terminal.builder(Sequence.builder(Character.builder(42).build()).build()) .build()) .addSymbol(Nonterminal.builder("E").build()) .setRecursion(Recursion.LEFT_RIGHT_REC) .setAssociativity(Associativity.UNDEFINED) .setPrecedence(3) .setPrecedenceLevel(PrecedenceLevel.from(3, 3, 3, false, false, true, false)) .build()) // S ::= E {UNDEFINED,-1,NON_REC} PREC(1,1) .addRule( Rule.withHead(Nonterminal.builder("S").build()) .addSymbol(Nonterminal.builder("E").build()) .setRecursion(Recursion.NON_REC) .setAssociativity(Associativity.UNDEFINED) .setPrecedence(-1) .setPrecedenceLevel(PrecedenceLevel.from(1, 1, -1, false, false, false, false)) .build()) .build(); // grammar = new EBNFToBNF().transform(grammar); System.out.println(grammar); grammar = new DesugarPrecedenceAndAssociativity().transform(grammar); System.out.println(grammar.toStringWithOrderByPrecedence()); Input input = Input.fromString("a*-a^a"); GrammarGraph graph = GrammarGraph.from(grammar, input, Configuration.DEFAULT); // Visualization.generateGrammarGraph("test/org/iguana/parser/datadependent/precedence/", // graph); ParseResult result = Iguana.parse(input, graph, Nonterminal.withName("S")); Assert.assertTrue(result.isParseSuccess()); // Visualization.generateSPPFGraph("test/org/iguana/parser/datadependent/precedence/", // result.asParseSuccess().getSPPFNode(), input); Assert.assertEquals(0, result.asParseSuccess().getStatistics().getCountAmbiguousNodes()); }