projects
/
sbp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
checkpoint
[sbp.git]
/
src
/
edu
/
berkeley
/
sbp
/
Union.java
diff --git
a/src/edu/berkeley/sbp/Union.java
b/src/edu/berkeley/sbp/Union.java
index
7370a68
..
4de0bb4
100644
(file)
--- a/
src/edu/berkeley/sbp/Union.java
+++ b/
src/edu/berkeley/sbp/Union.java
@@
-10,16
+10,24
@@
import java.lang.ref.*;
/** an element which can produce one of several alternatives */
public class Union extends Element implements Iterable<Sequence> {
/** an element which can produce one of several alternatives */
public class Union extends Element implements Iterable<Sequence> {
+ /** display form for the Union (ie not including the RHS) */
final String shortForm;
final String shortForm;
+
+ /** this is just a hint to use when printing out the grammar in visual form */
final boolean synthetic;
final boolean synthetic;
+
+ /** the actual alternatives */
private final List<Sequence> alternatives = new ArrayList<Sequence>();
public Iterator<Sequence> iterator() { return alternatives.iterator(); }
private final List<Sequence> alternatives = new ArrayList<Sequence>();
public Iterator<Sequence> iterator() { return alternatives.iterator(); }
-
- void reachable(HashSet<Sequence.Position> h) { for(Sequence s : alternatives) s.reachable(h); }
+ public boolean contains(Sequence s) { return alternatives.contains(s); }
/** adds an alternative */
/** adds an alternative */
- public void add(Sequence s) { alternatives.add(s); }
+ public void add(Sequence s) {
+ alternatives.add(s);
+ for(Sequence n : s.needs) add(n);
+ for(Sequence n : s.hates) add(n);
+ }
/**
* Since every cycle in a non-degenerate grammar contains at
/**
* Since every cycle in a non-degenerate grammar contains at
@@
-36,6
+44,9
@@
public class Union extends Element implements Iterable<Sequence> {
this.synthetic = synthetic;
}
this.synthetic = synthetic;
}
+ public static Union epsilon = new Union("()");
+ static { epsilon.add(Sequence.empty); }
+
private Forest.Ref epsilonForm = null;
Forest epsilonForm() {
if (epsilonForm != null) return epsilonForm;
private Forest.Ref epsilonForm = null;
Forest epsilonForm() {
if (epsilonForm != null) return epsilonForm;