Commit c4f8d8c0 authored by Alexandru Dura's avatar Alexandru Dura
Browse files

Add one more test containing lists and gaps

parent d22d556b
......@@ -4,7 +4,7 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class SPPFNode {
public class SPPFNode implements Cloneable {
static public class FamilyNode {
private SPPFNode[] child;
......
......@@ -70,6 +70,8 @@ class DotVisitor implements SPPFNodeVisitor {
if (n.getLabel() instanceof ItemLabel) {
ps.print(currentID + " [shape=box,color=red,label=\"" + n.prettyPrint(info) + "\"];\n");
} else if (n.getChildren().size() > 1) {
ps.print(currentID + " [shape=box,color=red,label=\"" + n.prettyPrint(info) + "\"];\n");
} else {
ps.print(currentID + " [shape=box,label=\"" + n.prettyPrint(info) + "\"];\n");
}
......
......@@ -289,4 +289,51 @@ public class EarleyParserTest {
tpr.visit(root);
Util.dumpParseResult("testJava3-notr.dot", root, g);
}
@Test public void testJava4() {
Grammar g = new Grammar();
Java14Grammar.addRules(g);
EarleyParser parser = new EarleyParser(g);
Category str[] = {
Java14Grammar.t_CLASS,
Java14Grammar.t_IDENTIFIER,
Java14Grammar.t_LBRACE,
Java14Grammar.t_METAVARID,
Java14Grammar.t_METAVARID,
Java14Grammar.t_LPAREN,
Java14Grammar.t_RPAREN,
Java14Grammar.t_LBRACE,
Java14Grammar.t_METAVARID,
Java14Grammar.t_GAP,
Java14Grammar.t_METAVARID,
Java14Grammar.t_GAP,
Java14Grammar.t_METAVARID,
Java14Grammar.t_RBRACE,
Java14Grammar.t_RBRACE};
SPPFNode root = parser.parse(str, Java14Grammar.n_class_declaration);
assertNotNull(root);
Util.dumpParseResult("testJava4-bt.dot", root, g);
// debinarize
SPPFDebinarizeVisitor dbv = new SPPFDebinarizeVisitor();
dbv.visit(root);
Util.dumpParseResult("testJava4.dot", root, g);
// remove trivial productions
SPPFTrivialProductionRemover tpr = new SPPFTrivialProductionRemover(g) {
@Override public boolean isTrivialProduction(Category head, Category body) {
String sig = head.getName() + "." + body.getName();
if (body.getName().equals("METAVARID"))
return true;
if (body.getName().equals("GAP"))
return true;
return false;
}
};
tpr.visit(root);
Util.dumpParseResult("testJava4-notr.dot", root, g);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment