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

Restrict visibility of some classes, members and methods

parent dbcee794
public class DottedRule {
class DottedRule {
final EarleyRule r;
final int dot;
......
public class EarleyItem {
class EarleyItem {
final int start; // 0 means beginning of input
final DottedRule rule;
SPPFNode sppf;
......
import javax.swing.plaf.nimbus.State;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.TreeSet;
public class EarleyParser {
private boolean DEBUG = true;
......@@ -31,7 +24,7 @@ public class EarleyParser {
return grammar.toString();
}
class StateSet extends HashSet<EarleyItem> {
static class StateSet extends HashSet<EarleyItem> {
public StateSet(Collection<EarleyItem> c) {
super(c);
}
......@@ -44,7 +37,6 @@ public class EarleyParser {
Iterator<EarleyItem> it = iterator();
if (it.hasNext()) {
EarleyItem item = it.next();
// the following is optional, let's see if it works
it.remove();
return item;
}
......@@ -65,8 +57,7 @@ public class EarleyParser {
for (int i = 0; i < s.length + 1; ++i) {
System.out.println("=== Item set at position " + i + " ===");
for (EarleyItem item : state[i]) {
if (true || item.isComplete())
System.out.println(item.prettyPrint(grammar));
System.out.println(item.prettyPrint(grammar));
}
}
}
......
public class EarleyRule implements Comparable<EarleyRule> {
class EarleyRule implements Comparable<EarleyRule> {
final int body[];
final int head;
......
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
public class SPPFNode {
static class FamilyNode {
SPPFNode child1;
SPPFNode child2;
private SPPFNode[] child;
FamilyNode(SPPFNode child1, SPPFNode child2) {
this.child1 = child1;
this.child2 = child2;
FamilyNode(SPPFNode child0, SPPFNode child1) {
assert child0 != null || child1 == null;
child = new SPPFNode[2];
child[0] = child0;
child[1] = child1;
}
public SPPFNode getChild(int i) {
return child[i];
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((child1 == null) ? 0 : child1.hashCode());
result = prime * result + ((child2 == null) ? 0 : child2.hashCode());
result = prime * result + ((child[0] == null) ? 0 : child[0].hashCode());
result = prime * result + ((child[1] == null) ? 0 : child[1].hashCode());
return result;
}
......@@ -32,15 +33,15 @@ public class SPPFNode {
if (getClass() != obj.getClass())
return false;
FamilyNode other = (FamilyNode) obj;
if (child1 == null) {
if (other.child1 != null)
if (child[0] == null) {
if (other.child[0] != null)
return false;
} else if (!child1.equals(other.child1))
} else if (!child[0].equals(other.child[0]))
return false;
if (child2 == null) {
if (other.child2 != null)
if (child[1] == null) {
if (other.child[1] != null)
return false;
} else if (!child2.equals(other.child2))
} else if (!child[1].equals(other.child[1]))
return false;
return true;
}
......@@ -65,8 +66,8 @@ public class SPPFNode {
children.add(new FamilyNode(child, null));
}
public void addChildren(SPPFNode child1, SPPFNode child2) {
children.add(new FamilyNode(child1, child2));
public void addChildren(SPPFNode child0, SPPFNode child1) {
children.add(new FamilyNode(child0, child1));
}
public void addEpsilon() {
......
......@@ -45,22 +45,22 @@ class DotVisitor implements SPPFNodeVisitor {
int currentID = nodeID++;
visitedFamilies.put(f, currentID);
if (f.child1 == null) {
if (f.getChild(0) == null) {
// epsilon
ps.print(currentID + " [label=\u03b5];\n");
} else {
ps.print(currentID + " [shape=circle];\n");
f.child1.accept(this);
if (f.child2 != null) {
f.child2.accept(this);
f.getChild(0).accept(this);
if (f.getChild(1) != null) {
f.getChild(1).accept(this);
}
}
if (f.child1 != null)
ps.print(currentID + " -> " + visitedNodes.get(f.child1) + ";\n");
if (f.child2 != null)
ps.print(currentID + " -> " + visitedNodes.get(f.child2) + ";\n");
if (f.getChild(0) != null)
ps.print(currentID + " -> " + visitedNodes.get(f.getChild(0)) + ";\n");
if (f.getChild(1) != null)
ps.print(currentID + " -> " + visitedNodes.get(f.getChild(1)) + ";\n");
}
@Override
......
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