Package org.antlr.runtime
Class DFA
- java.lang.Object
-
- org.antlr.runtime.DFA
-
public class DFA extends Object
A DFA implemented as a set of transition tables. Any state that has a semantic predicate edge is special; those states are generated with if-then-else structures in a specialStateTransition() which is generated by cyclicDFA template. There are at most 32767 states (16-bit signed short). Could get away with byte sometimes but would have to generate different types and the simulation code too. For a point of reference, the Java lexer's Tokens rule DFA has 326 states roughly.
-
-
Field Summary
Fields Modifier and Type Field Description protected short[]
accept
static boolean
debug
protected int
decisionNumber
protected short[]
eof
protected short[]
eot
protected char[]
max
protected char[]
min
protected BaseRecognizer
recognizer
Which recognizer encloses this DFA? Needed to check backtrackingprotected short[]
special
protected short[][]
transition
-
Constructor Summary
Constructors Constructor Description DFA()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
error(NoViableAltException nvae)
A hook for debugging interfaceString
getDescription()
protected void
noViableAlt(int s, IntStream input)
int
predict(IntStream input)
From the input stream, predict what alternative will succeed using this DFA (representing the covering regular approximation to the underlying CFL).int
specialStateTransition(int s, IntStream input)
static short[]
unpackEncodedString(String encodedString)
Given a String that has a run-length-encoding of some unsigned shorts like "\1\2\3\9", convert to short[] {2,9,9,9}.static char[]
unpackEncodedStringToUnsignedChars(String encodedString)
Hideous duplication of code, but I need different typed arrays out :(
-
-
-
Field Detail
-
eot
protected short[] eot
-
eof
protected short[] eof
-
min
protected char[] min
-
max
protected char[] max
-
accept
protected short[] accept
-
special
protected short[] special
-
transition
protected short[][] transition
-
decisionNumber
protected int decisionNumber
-
recognizer
protected BaseRecognizer recognizer
Which recognizer encloses this DFA? Needed to check backtracking
-
debug
public static final boolean debug
- See Also:
- Constant Field Values
-
-
Method Detail
-
predict
public int predict(IntStream input) throws RecognitionException
From the input stream, predict what alternative will succeed using this DFA (representing the covering regular approximation to the underlying CFL). Return an alternative number 1..n. Throw an exception upon error.- Throws:
RecognitionException
-
noViableAlt
protected void noViableAlt(int s, IntStream input) throws NoViableAltException
- Throws:
NoViableAltException
-
error
protected void error(NoViableAltException nvae)
A hook for debugging interface
-
specialStateTransition
public int specialStateTransition(int s, IntStream input) throws NoViableAltException
- Throws:
NoViableAltException
-
getDescription
public String getDescription()
-
unpackEncodedString
public static short[] unpackEncodedString(String encodedString)
Given a String that has a run-length-encoding of some unsigned shorts like "\1\2\3\9", convert to short[] {2,9,9,9}. We do this to avoid static short[] which generates so much init code that the class won't compile. :(
-
unpackEncodedStringToUnsignedChars
public static char[] unpackEncodedStringToUnsignedChars(String encodedString)
Hideous duplication of code, but I need different typed arrays out :(
-
-