[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6724]
This commit is contained in:
parrt 2010-02-24 11:10:13 -08:00
parent d2b5f95016
commit 80ea7cf0db
9 changed files with 65 additions and 61 deletions

View File

@ -1,35 +0,0 @@
package org.antlr.v4.analysis;
import org.antlr.misc.IntervalSet;
/** */
public class AtomLabel extends Label {
/** The token type or character value; or, signifies special label. */
protected int label;
public AtomLabel(int label) {
this.label = label;
}
public int hashCode() { return label; }
public boolean equals(Object o) {
if ( o==null ) return false;
if ( this == o ) return true; // equals if same object
if ( o.getClass() == SetLabel.class ) {
return IntervalSet.of(label).equals(o);
}
return label!=((AtomLabel)o).label;
}
public boolean intersect(Label other) {
if ( other.getClass() == AtomLabel.class ) {
return label==((AtomLabel)other).label;
}
return ((SetLabel)other).label.member(this.label);
}
// public int compareTo(Object o) {
// return this.label-((AtomLabel)o).label;
// }
}

View File

@ -1,13 +1,12 @@
package org.antlr.v4.analysis;
package org.antlr.v4.automata;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.GrammarAST;
/** */
public class ActionLabel extends Label {
public class ActionTransition extends Transition {
public GrammarAST actionAST;
public ActionLabel(GrammarAST actionAST) {
public ActionTransition(GrammarAST actionAST) {
this.actionAST = actionAST;
}
@ -15,6 +14,10 @@ public class ActionLabel extends Label {
return true; // we are to be ignored by analysis 'cept for predicates
}
public int compareTo(Object o) {
return 0;
}
public String toString() {
return "{"+actionAST+"}";
}

View File

@ -0,0 +1,35 @@
package org.antlr.v4.automata;
import org.antlr.v4.misc.IntervalSet;
/** */
public class AtomTransition extends Transition {
/** The token type or character value; or, signifies special label. */
protected int label;
public AtomTransition(int label) {
this.label = label;
}
public int hashCode() { return label; }
public boolean equals(Object o) {
if ( o==null ) return false;
if ( this == o ) return true; // equals if same object
if ( o.getClass() == SetTransition.class ) {
return IntervalSet.of(label).equals(o);
}
return label!=((AtomTransition)o).label;
}
// public boolean intersect(Label other) {
// if ( other.getClass() == AtomTransition.class ) {
// return label==((AtomTransition)other).label;
// }
// return ((SetLabel)other).label.member(this.label);
// }
public int compareTo(Object o) {
return this.label-((AtomTransition)o).label;
}
}

View File

@ -1,4 +1,4 @@
package org.antlr.v4.analysis;
package org.antlr.v4.automata;
import org.antlr.runtime.Token;

View File

@ -1,5 +1,6 @@
package org.antlr.v4.analysis;
package org.antlr.v4.automata;
import org.antlr.v4.analysis.SemanticContext;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.GrammarAST;
@ -8,14 +9,14 @@ import org.antlr.v4.tool.GrammarAST;
* may have to combine a bunch of them as it collects predicates from
* multiple NFA configurations into a single DFA state.
*/
public class PredicateLabel extends Label {
public class PredicateTransition extends Label {
protected SemanticContext semanticContext;
public PredicateLabel(GrammarAST predicateASTNode) {
public PredicateTransition(GrammarAST predicateASTNode) {
this.semanticContext = new SemanticContext.Predicate(predicateASTNode);
}
public PredicateLabel(SemanticContext semCtx) {
public PredicateTransition(SemanticContext semCtx) {
this.semanticContext = semCtx;
}
@ -30,10 +31,10 @@ public class PredicateLabel extends Label {
if ( this == o ) {
return true; // equals if same object
}
if ( !(o instanceof PredicateLabel) ) {
if ( !(o instanceof PredicateTransition) ) {
return false;
}
return semanticContext.equals(((PredicateLabel)o).semanticContext);
return semanticContext.equals(((PredicateTransition)o).semanticContext);
}
public String toString() {

View File

@ -1,15 +1,15 @@
package org.antlr.v4.analysis;
package org.antlr.v4.automata;
import org.antlr.v4.misc.IntSet;
import org.antlr.v4.misc.IntervalSet;
/** A label containing a set of values */
public class SetLabel extends Label {
public class SetTransition extends Label {
/** A set of token types or character codes if label==SET */
// TODO: try IntervalSet for everything
protected IntSet label;
public SetLabel(IntSet label) {
public SetTransition(IntSet label) {
if ( label==null ) {
this.label = IntervalSet.of(INVALID);
return;
@ -17,21 +17,21 @@ public class SetLabel extends Label {
this.label = label;
}
public boolean intersect(Label other) {
if ( other.getClass() == SetLabel.class ) {
return label.and(((SetLabel)other).label).isNil();
}
return label.member(((AtomLabel)other).label);
}
// public boolean intersect(Label other) {
// if ( other.getClass() == SetTransition.class ) {
// return label.and(((SetTransition)other).label).isNil();
// }
// return label.member(((AtomTransition)other).label);
// }
public int hashCode() { return label.hashCode(); }
public boolean equals(Object o) {
if ( o==null ) return false;
if ( this == o ) return true; // equals if same object
if ( o.getClass() == AtomLabel.class ) {
o = IntervalSet.of(((AtomLabel)o).label);
if ( o.getClass() == AtomTransition.class ) {
o = IntervalSet.of(((AtomTransition)o).label);
}
return this.label.equals(((SetLabel)o).label);
return this.label.equals(((SetTransition)o).label);
}
}

View File

@ -1,4 +1,4 @@
package org.antlr.v4.analysis;
package org.antlr.v4.automata;
import org.antlr.analysis.State;

View File

@ -1,6 +1,6 @@
package org.antlr.v4.semantics;
import org.antlr.v4.analysis.Label;
import org.antlr.v4.automata.Label;
import org.antlr.v4.tool.*;
import java.util.List;

View File

@ -3,7 +3,7 @@ package org.antlr.v4.tool;
import org.antlr.runtime.*;
import org.antlr.runtime.tree.TreeWizard;
import org.antlr.v4.Tool;
import org.antlr.v4.analysis.Label;
import org.antlr.v4.automata.Label;
import org.antlr.v4.parse.ANTLRLexer;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.parse.GrammarASTAdaptor;