From d5801b91d7d043dd507764b8b3ef325d733a835a Mon Sep 17 00:00:00 2001 From: parrt Date: Wed, 24 Feb 2010 13:41:22 -0800 Subject: [PATCH] add fields and NFA/DFA [git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6727] --- .../org/antlr/v4/automata/BlockEndState.java | 5 ++++ .../antlr/v4/automata/BlockStartState.java | 14 ++++++++++ .../org/antlr/v4/automata/BlockStopState.java | 5 ---- tool/src/org/antlr/v4/automata/DFA.java | 4 +++ .../org/antlr/v4/automata/LoopbackState.java | 4 +++ tool/src/org/antlr/v4/automata/NFA.java | 5 ++++ tool/src/org/antlr/v4/automata/NFAState.java | 27 +++++-------------- .../org/antlr/v4/automata/RuleStartState.java | 1 + .../org/antlr/v4/automata/SetTransition.java | 10 ++++--- 9 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 tool/src/org/antlr/v4/automata/BlockEndState.java delete mode 100644 tool/src/org/antlr/v4/automata/BlockStopState.java create mode 100644 tool/src/org/antlr/v4/automata/DFA.java create mode 100644 tool/src/org/antlr/v4/automata/NFA.java diff --git a/tool/src/org/antlr/v4/automata/BlockEndState.java b/tool/src/org/antlr/v4/automata/BlockEndState.java new file mode 100644 index 000000000..5b0170a9a --- /dev/null +++ b/tool/src/org/antlr/v4/automata/BlockEndState.java @@ -0,0 +1,5 @@ +package org.antlr.v4.automata; + +/** */ +public class BlockEndState extends NFAState { +} diff --git a/tool/src/org/antlr/v4/automata/BlockStartState.java b/tool/src/org/antlr/v4/automata/BlockStartState.java index 0263db4cb..063fb28a3 100644 --- a/tool/src/org/antlr/v4/automata/BlockStartState.java +++ b/tool/src/org/antlr/v4/automata/BlockStartState.java @@ -1,5 +1,19 @@ package org.antlr.v4.automata; +import java.util.ArrayList; +import java.util.List; + /** */ public class BlockStartState extends NFAState { + public static final int INITIAL_NUM_TRANSITIONS = 4; + + BlockEndState endState; + + /** What's its decision number from 1..n? */ + protected int decisionNumber = 0; + + /** Track the transitions emanating from this NFA state. */ + protected List transitions = + new ArrayList(INITIAL_NUM_TRANSITIONS); + } diff --git a/tool/src/org/antlr/v4/automata/BlockStopState.java b/tool/src/org/antlr/v4/automata/BlockStopState.java deleted file mode 100644 index b212bae17..000000000 --- a/tool/src/org/antlr/v4/automata/BlockStopState.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.antlr.v4.automata; - -/** */ -public class BlockStopState extends NFAState { -} diff --git a/tool/src/org/antlr/v4/automata/DFA.java b/tool/src/org/antlr/v4/automata/DFA.java new file mode 100644 index 000000000..cb7bb3de0 --- /dev/null +++ b/tool/src/org/antlr/v4/automata/DFA.java @@ -0,0 +1,4 @@ +package org.antlr.v4.automata; + +public class DFA { +} diff --git a/tool/src/org/antlr/v4/automata/LoopbackState.java b/tool/src/org/antlr/v4/automata/LoopbackState.java index b1c8f8abb..77d4034e1 100644 --- a/tool/src/org/antlr/v4/automata/LoopbackState.java +++ b/tool/src/org/antlr/v4/automata/LoopbackState.java @@ -2,4 +2,8 @@ package org.antlr.v4.automata; /** */ public class LoopbackState extends NFAState { + BlockStartState loopStartState; + + /** What's its decision number from 1..n? */ + protected int decisionNumber = 0; } diff --git a/tool/src/org/antlr/v4/automata/NFA.java b/tool/src/org/antlr/v4/automata/NFA.java new file mode 100644 index 000000000..7e327263a --- /dev/null +++ b/tool/src/org/antlr/v4/automata/NFA.java @@ -0,0 +1,5 @@ +package org.antlr.v4.automata; + +/** */ +public class NFA { +} diff --git a/tool/src/org/antlr/v4/automata/NFAState.java b/tool/src/org/antlr/v4/automata/NFAState.java index 6b4b43948..4eda0a556 100644 --- a/tool/src/org/antlr/v4/automata/NFAState.java +++ b/tool/src/org/antlr/v4/automata/NFAState.java @@ -1,27 +1,14 @@ package org.antlr.v4.automata; -import org.antlr.analysis.Transition; - -import java.util.ArrayList; -import java.util.List; - -/** - * // I need to distinguish between NFA decision states for (...)* and (...)+ - // during NFA interpretation. - public static final int LOOPBACK = 1; - public static final int BLOCK_START = 2; - public static final int OPTIONAL_BLOCK_START = 3; - public static final int BYPASS = 4; - public static final int RIGHT_EDGE_OF_BLOCK = 5; - - make subclasses for all of these - */ public class NFAState extends State { - public static final int INITIAL_NUM_TRANSITIONS = 4; + /** Which NFA are we in? */ + public NFA nfa = null; - /** Track the transitions emanating from this NFA state. */ - protected List transitions = - new ArrayList(INITIAL_NUM_TRANSITIONS); + /** For o-A->o type NFA tranitions, record the label that leads to this + * state. Useful for creating rich error messages when we find + * insufficiently (with preds) covered states. + */ + public NFATransition incidentTransition; @Override public int getNumberOfTransitions() { diff --git a/tool/src/org/antlr/v4/automata/RuleStartState.java b/tool/src/org/antlr/v4/automata/RuleStartState.java index 3593859e2..c03f32627 100644 --- a/tool/src/org/antlr/v4/automata/RuleStartState.java +++ b/tool/src/org/antlr/v4/automata/RuleStartState.java @@ -2,4 +2,5 @@ package org.antlr.v4.automata; /** */ public class RuleStartState extends NFAState { + RuleStopState stopState; } diff --git a/tool/src/org/antlr/v4/automata/SetTransition.java b/tool/src/org/antlr/v4/automata/SetTransition.java index e03d6a05a..947a29c06 100644 --- a/tool/src/org/antlr/v4/automata/SetTransition.java +++ b/tool/src/org/antlr/v4/automata/SetTransition.java @@ -4,19 +4,23 @@ import org.antlr.v4.misc.IntSet; import org.antlr.v4.misc.IntervalSet; /** A label containing a set of values */ -public class SetTransition extends Label { +public class SetTransition extends NFATransition { /** A set of token types or character codes if label==SET */ protected IntSet label; public SetTransition(IntSet label) { if ( label==null ) { - this.label = IntervalSet.of(INVALID); + this.label = IntervalSet.of(Label.INVALID); return; } this.label = label; } -// public boolean intersect(Label other) { + public int compareTo(Object o) { + return 0; + } + + // public boolean intersect(Label other) { // if ( other.getClass() == SetTransition.class ) { // return label.and(((SetTransition)other).label).isNil(); // }