projects
/
sbp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
checkpoint harmony
[sbp.git]
/
src
/
edu
/
berkeley
/
sbp
/
Sequence.java
diff --git
a/src/edu/berkeley/sbp/Sequence.java
b/src/edu/berkeley/sbp/Sequence.java
index
d274013
..
d8f39fd
100644
(file)
--- a/
src/edu/berkeley/sbp/Sequence.java
+++ b/
src/edu/berkeley/sbp/Sequence.java
@@
-89,6
+89,14
@@
public abstract class Sequence extends Element implements Iterable<Element> {
/** the imaginary position before or after an element of a sequence; corresponds to an "LR item" */
public class Position {
/** the imaginary position before or after an element of a sequence; corresponds to an "LR item" */
public class Position {
+ private Forest zero = null;
+ public Forest zero() {
+ if (zero != null) return zero;
+ if (pos > 0) throw new Error();
+ return zero = rewrite(null);
+ }
+
+
final int pos;
private final Position next;
final Forest[] holder;
final int pos;
private final Position next;
final Forest[] holder;
@@
-113,7
+121,7
@@
public abstract class Sequence extends Element implements Iterable<Element> {
/** true iff this Position is the last one in the sequence */
public boolean isLast() { return next()==null; }
/** true iff this Position is the last one in the sequence */
public boolean isLast() { return next()==null; }
- // Reduction /////////////////////////////////////////////////////////////////////////////////
+ // Position /////////////////////////////////////////////////////////////////////////////////
final <T> Forest<T> rewrite(Token.Location loc) {
if (this==firstp()) return epsilonForm();
final <T> Forest<T> rewrite(Token.Location loc) {
if (this==firstp()) return epsilonForm();