1 // (C) 2006-2007 all rights reserved; see LICENSE file for BSD-style license
3 package edu.berkeley.sbp;
8 * the root superclass for all components of the grammar (terminals,
9 * nonterminals, literals, etc)
12 public abstract class Element implements SequenceOrElement {
14 /** sorry, you can't make up new, custom elements */
17 /** a more verbose version of toString() for displaying whole grammars */
18 abstract StringBuffer toString(StringBuffer sb);
20 /** a slow and inefficient epsilon-ness checker used when constructing parse trees (see Union.epsilonForm()) */
21 public static boolean possiblyEpsilon(SequenceOrElement e) {
22 if (e instanceof Atom) return false;
23 if (e instanceof Sequence) {
24 Sequence s = (Sequence)e;
25 for(Sequence.Pos p = s.firstp(); !p.isLast(); p = p.next())
26 if (!possiblyEpsilon(p.element()))
30 if (e instanceof Union) {
32 if (u.visiting) return true;
36 if (possiblyEpsilon(s))
45 boolean visiting = false;