Package antlr
Class Lookahead
- java.lang.Object
-
- antlr.Lookahead
-
- All Implemented Interfaces:
java.lang.Cloneable
public class Lookahead extends java.lang.Object implements java.lang.CloneableThis object holds all information needed to represent the lookahead for any particular lookahead computation for a single lookahead depth. Final lookahead information is a simple bit set, but intermediate stages need computation cycle and FOLLOW information.Concerning the cycle variable. If lookahead is computed for a RuleEnd node, then computation is part of a FOLLOW cycle for this rule. If lookahead is computed for a RuleBlock node, the computation is part of a FIRST cycle to this rule.
Concerning the epsilonDepth variable. This is not the depth relative to the rule reference that epsilon was encountered. That value is
initial_k - epsilonDepth + 1Also, lookahead depths past rule ref for local follow are:initial_k - (initial_k - epsilonDepth)Used for rule references. If we try to compute look(k, ruleref) and there are fewer than k lookahead terminals before the end of the the rule, epsilon will be returned (don't want to pass the end of the rule). We must track when the the lookahead got stuck. For example,a : b A B E F G; b : C ;LOOK(5, ref-to(b)) is {} with depth = 4, which indicates that at 2 (5-4+1) tokens ahead, end of rule was reached. Therefore, the token at 4=5-(5-4) past rule ref b must be included in the set == F. The situation is complicated by the fact that a computation may hit the end of a rule at many different depths. For example, a : b A B C ; b : E F // epsilon depth of 1 relative to initial k=3 | G // epsilon depth of 2 ;Here, LOOK(3,ref-to(b)) returns epsilon, but the depths are {1, 2}; i.e., 3-(3-1) and 3-(3-2). Those are the lookahead depths past the rule ref needed for the local follow.This is null unless an epsilon is created.
- See Also:
combineWith(Lookahead)
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.Stringcycleis this computation part of a computation cycle?(package private) BitSetepsilonDepthWhat k values were being computed when end of rule hit?(package private) BitSetfsetactual bitset of the lookahead(package private) booleanhasEpsilonDoes this lookahead depth include Epsilon token type? This is used to avoid having a bit in the set for Epsilon as it conflicts with parsing binary files.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()Make a deep copy of everything in this objectvoidcombineWith(Lookahead q)booleancontainsEpsilon()Lookaheadintersection(Lookahead q)What is the intersection of two lookahead depths? Only the Epsilon "bit" and bitset are considered.booleannil()static Lookaheadof(int el)voidresetEpsilon()voidsetEpsilon()java.lang.StringtoString()java.lang.StringtoString(java.lang.String separator, CharFormatter formatter)java.lang.StringtoString(java.lang.String separator, CharFormatter formatter, Grammar g)java.lang.StringtoString(java.lang.String separator, Vector vocab)
-
-
-
Field Detail
-
fset
BitSet fset
actual bitset of the lookahead
-
cycle
java.lang.String cycle
is this computation part of a computation cycle?
-
epsilonDepth
BitSet epsilonDepth
What k values were being computed when end of rule hit?
-
hasEpsilon
boolean hasEpsilon
Does this lookahead depth include Epsilon token type? This is used to avoid having a bit in the set for Epsilon as it conflicts with parsing binary files.
-
-
Constructor Detail
-
Lookahead
public Lookahead()
-
Lookahead
public Lookahead(BitSet p)
create a new lookahead set with the LL(1) set to the parameter
-
Lookahead
public Lookahead(java.lang.String c)
create an empty lookahead set, but with cycle
-
-
Method Detail
-
clone
public java.lang.Object clone()
Make a deep copy of everything in this object- Overrides:
clonein classjava.lang.Object
-
combineWith
public void combineWith(Lookahead q)
-
containsEpsilon
public boolean containsEpsilon()
-
intersection
public Lookahead intersection(Lookahead q)
What is the intersection of two lookahead depths? Only the Epsilon "bit" and bitset are considered.
-
nil
public boolean nil()
-
of
public static Lookahead of(int el)
-
resetEpsilon
public void resetEpsilon()
-
setEpsilon
public void setEpsilon()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString
public java.lang.String toString(java.lang.String separator, CharFormatter formatter)
-
toString
public java.lang.String toString(java.lang.String separator, CharFormatter formatter, Grammar g)
-
toString
public java.lang.String toString(java.lang.String separator, Vector vocab)
-
-