7be02af6673d58f56b7dae630bfc5e5a3f51b60a
[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     /** if this element always matches exactly one token, return a topology covering exactly those possible tokens, otherwise <tt>null</tt> */
14     Forest epsilonForm() { throw new Error("no epsilon form: " + this); }
15     final boolean possiblyEpsilon(Walk.Cache cache) {
16         Boolean ret = cache==null ? null : cache.possiblyEpsilon.get(this);
17         if (ret != null) return ret.booleanValue();
18         ret = new Walk.PossiblyEpsilon().walk(this) ? Boolean.TRUE : Boolean.FALSE;
19         if (cache != null) cache.possiblyEpsilon.put(this, ret);
20         return ret;
21     }
22 }