added arbitrary expression inversion, lookforward, and syntax for lookback
[sbp.git] / src / edu / berkeley / sbp / Element.java
1 package edu.berkeley.sbp;
2 import edu.berkeley.sbp.util.*;
3 import edu.berkeley.sbp.*;
4 import edu.berkeley.sbp.*;
5 import java.io.*;
6 import java.util.*;
7 import java.lang.reflect.*;
8 import java.lang.ref.*;
9
10 /** the root superclass for all components of the grammar (terminals, nonterminals, literals, etc) */
11 public abstract class Element {
12
13     /** add all positions reachable from the start of this Element to @rp */
14     abstract void reachable(HashSet<Sequence.Position> rp);
15
16     abstract Topology toAtom();
17     public Topology noFollow() { return null; }
18     Forest epsilonForm() { throw new Error("no epsilon form: " + this); }
19     final boolean possiblyEpsilon(Walk.Cache cache)   {
20         Boolean ret = cache==null ? null : cache.possiblyEpsilon.get(this);
21         if (ret != null) return ret.booleanValue();
22         ret = new Walk.PossiblyEpsilon().walk(this) ? Boolean.TRUE : Boolean.FALSE;
23         if (cache != null) cache.possiblyEpsilon.put(this, ret);
24         return ret;
25     }
26 }