Got rid of the fields listed in the output model object hierarchy; created the exception throwing templates

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6882]
This commit is contained in:
parrt 2010-05-22 10:27:11 -08:00
parent bf92a4bc73
commit 03d9f0ba32
46 changed files with 701 additions and 604 deletions

View File

@ -106,11 +106,12 @@ public abstract class BaseRecognizer {
state.failed = false; state.failed = false;
return matchedSymbol; return matchedSymbol;
} }
if ( state.backtracking>0 ) { // if ( state.backtracking>0 ) {
state.failed = true; // state.failed = true;
return matchedSymbol; // return matchedSymbol;
} // }
matchedSymbol = recoverFromMismatchedToken(ttype, follow); matchedSymbol = recoverFromMismatchedToken(ttype, follow);
System.out.println("rsync'd to "+matchedSymbol);
return matchedSymbol; return matchedSymbol;
} }
@ -205,16 +206,16 @@ public abstract class BaseRecognizer {
* exception types. * exception types.
*/ */
public String getErrorMessage(RecognitionException e) { public String getErrorMessage(RecognitionException e) {
String[] tokenNames = getTokenNames(); String[] tokenNames = getTokenNames();
String msg = e.getMessage(); String msg = e.getMessage();
if ( e instanceof UnwantedTokenException ) { if ( e instanceof UnwantedTokenException ) {
UnwantedTokenException ute = (UnwantedTokenException)e; UnwantedTokenException ute = (UnwantedTokenException)e;
String tokenName="<unknown>"; String tokenName="<unknown>";
if ( ute.expecting== Token.EOF ) { if ( ute.expecting.member(Token.EOF) ) {
tokenName = "EOF"; tokenName = "EOF";
} }
else { else {
tokenName = tokenNames[ute.expecting]; tokenName = tokenNames[ute.expecting.getSingleElement()];
} }
msg = "extraneous input "+getTokenErrorDisplay(ute.getUnexpectedToken())+ msg = "extraneous input "+getTokenErrorDisplay(ute.getUnexpectedToken())+
" expecting "+tokenName; " expecting "+tokenName;
@ -222,22 +223,22 @@ public abstract class BaseRecognizer {
else if ( e instanceof MissingTokenException ) { else if ( e instanceof MissingTokenException ) {
MissingTokenException mte = (MissingTokenException)e; MissingTokenException mte = (MissingTokenException)e;
String tokenName="<unknown>"; String tokenName="<unknown>";
if ( mte.expecting== Token.EOF ) { if ( mte.expecting.member(Token.EOF) ) {
tokenName = "EOF"; tokenName = "EOF";
} }
else { else {
tokenName = tokenNames[mte.expecting]; tokenName = tokenNames[mte.expecting.getSingleElement()];
} }
msg = "missing "+tokenName+" at "+getTokenErrorDisplay(e.token); msg = "missing "+tokenName+" at "+getTokenErrorDisplay(e.token);
} }
else if ( e instanceof MismatchedTokenException ) { else if ( e instanceof MismatchedTokenException ) {
MismatchedTokenException mte = (MismatchedTokenException)e; MismatchedTokenException mte = (MismatchedTokenException)e;
String tokenName="<unknown>"; String tokenName="<unknown>";
if ( mte.expecting== Token.EOF ) { if ( mte.expecting.member(Token.EOF) ) {
tokenName = "EOF"; tokenName = "EOF";
} }
else { else {
tokenName = tokenNames[mte.expecting]; tokenName = tokenNames[mte.expecting.getSingleElement()];
} }
msg = "mismatched input "+getTokenErrorDisplay(e.token)+ msg = "mismatched input "+getTokenErrorDisplay(e.token)+
" expecting "+tokenName; " expecting "+tokenName;
@ -245,11 +246,11 @@ public abstract class BaseRecognizer {
else if ( e instanceof MismatchedTreeNodeException ) { else if ( e instanceof MismatchedTreeNodeException ) {
MismatchedTreeNodeException mtne = (MismatchedTreeNodeException)e; MismatchedTreeNodeException mtne = (MismatchedTreeNodeException)e;
String tokenName="<unknown>"; String tokenName="<unknown>";
if ( mtne.expecting==Token.EOF ) { if ( mtne.expecting.member(Token.EOF) ) {
tokenName = "EOF"; tokenName = "EOF";
} }
else { else {
tokenName = tokenNames[mtne.expecting]; tokenName = tokenNames[mtne.expecting.getSingleElement()];
} }
msg = "mismatched tree node: "+mtne.node+ msg = "mismatched tree node: "+mtne.node+
" expecting "+tokenName; " expecting "+tokenName;
@ -310,6 +311,7 @@ public abstract class BaseRecognizer {
* so that it creates a new Java type. * so that it creates a new Java type.
*/ */
public String getTokenErrorDisplay(Token t) { public String getTokenErrorDisplay(Token t) {
System.err.println("mmmm3");
String s = t.getText(); String s = t.getText();
if ( s==null ) { if ( s==null ) {
if ( t.getType()==Token.EOF ) { if ( t.getType()==Token.EOF ) {
@ -331,7 +333,7 @@ public abstract class BaseRecognizer {
* handle mismatched symbol exceptions but there could be a mismatched * handle mismatched symbol exceptions but there could be a mismatched
* token that the match() routine could not recover from. * token that the match() routine could not recover from.
*/ */
public void recover(RecognitionException re) { public void recover() {
if ( state.lastErrorIndex==state.input.index() ) { if ( state.lastErrorIndex==state.input.index() ) {
// uh oh, another error at same token index; must be a case // uh oh, another error at same token index; must be a case
// where LT(1) is in the recovery token set so nothing is // where LT(1) is in the recovery token set so nothing is
@ -575,9 +577,9 @@ public abstract class BaseRecognizer {
e = new UnwantedTokenException(this, ttype); e = new UnwantedTokenException(this, ttype);
/* /*
System.err.println("recoverFromMismatchedToken deleting "+ System.err.println("recoverFromMismatchedToken deleting "+
((TokenStream)input).LT(1)+ ((TokenStream)state.input).LT(1)+
" since "+((TokenStream)input).LT(2)+" is what we want"); " since "+((TokenStream)state.input).LT(2)+" is what we want");
*/ */
beginResync(); beginResync();
state.input.consume(); // simply delete extra token state.input.consume(); // simply delete extra token
endResync(); endResync();

View File

@ -27,15 +27,14 @@
*/ */
package org.antlr.v4.runtime; package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.LABitSet;
/** The recognizer did not match anything for a (..)+ loop. */ /** The recognizer did not match anything for a (..)+ loop. */
public class EarlyExitException extends RecognitionException { public class EarlyExitException extends RecognitionException {
public int decisionNumber;
/** Used for remote debugger deserialization */ /** Used for remote debugger deserialization */
public EarlyExitException() {;} public EarlyExitException() {;}
public EarlyExitException(BaseRecognizer recognizer, int decisionNumber) { public EarlyExitException(BaseRecognizer recognizer, LABitSet expecting) {
super(recognizer); super(recognizer, expecting);
this.decisionNumber = decisionNumber;
} }
} }

View File

@ -227,7 +227,8 @@ public abstract class Lexer /* extends BaseRecognizer */ implements TokenSource
String msg = null; String msg = null;
if ( e instanceof MismatchedTokenException ) { if ( e instanceof MismatchedTokenException ) {
MismatchedTokenException mte = (MismatchedTokenException)e; MismatchedTokenException mte = (MismatchedTokenException)e;
msg = "mismatched character "+getCharErrorDisplay(e.c)+" expecting "+getCharErrorDisplay(mte.expecting); msg = "mismatched character "+getCharErrorDisplay(e.c)+" expecting "+
getCharErrorDisplay(mte.expecting.getSingleElement());
} }
else if ( e instanceof NoViableAltException ) { else if ( e instanceof NoViableAltException ) {
NoViableAltException nvae = (NoViableAltException)e; NoViableAltException nvae = (NoViableAltException)e;

View File

@ -30,14 +30,11 @@ package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.LABitSet; import org.antlr.v4.runtime.misc.LABitSet;
public class MismatchedSetException extends RecognitionException { public class MismatchedSetException extends RecognitionException {
public LABitSet expecting;
/** Used for remote debugger deserialization */ /** Used for remote debugger deserialization */
public MismatchedSetException() {;} public MismatchedSetException() {;}
public MismatchedSetException(BaseRecognizer recognizer, LABitSet expecting) { public MismatchedSetException(BaseRecognizer recognizer, LABitSet expecting) {
super(recognizer); super(recognizer, expecting);
this.expecting = expecting;
} }
public String toString() { public String toString() {

View File

@ -27,18 +27,15 @@
*/ */
package org.antlr.v4.runtime; package org.antlr.v4.runtime;
import org.antlr.runtime.Token; import org.antlr.v4.runtime.misc.LABitSet;
/** A mismatched char or Token or tree node */ /** A mismatched char or Token or tree node */
public class MismatchedTokenException extends RecognitionException { public class MismatchedTokenException extends RecognitionException {
public int expecting = Token.INVALID_TOKEN_TYPE;
/** Used for remote debugger deserialization */ /** Used for remote debugger deserialization */
public MismatchedTokenException() {;} public MismatchedTokenException() {;}
public MismatchedTokenException(BaseRecognizer recognizer, int expecting) { public MismatchedTokenException(BaseRecognizer recognizer, int expecting) {
super(recognizer); super(recognizer, LABitSet.of(expecting));
this.expecting = expecting;
} }
public String toString() { public String toString() {

View File

@ -27,19 +27,18 @@
*/ */
package org.antlr.v4.runtime; package org.antlr.v4.runtime;
import org.antlr.v4.runtime.misc.LABitSet;
/** /**
*/ */
public class MismatchedTreeNodeException extends RecognitionException { public class MismatchedTreeNodeException extends RecognitionException {
public int expecting;
public MismatchedTreeNodeException() { public MismatchedTreeNodeException() {
} }
public MismatchedTreeNodeException(BaseRecognizer recognizer, public MismatchedTreeNodeException(BaseRecognizer recognizer,
int expecting) int expecting)
{ {
super(recognizer); super(recognizer, LABitSet.of(expecting));
this.expecting = expecting;
} }
public String toString() { public String toString() {

View File

@ -41,7 +41,7 @@ public class MissingTokenException extends MismatchedTokenException {
} }
public int getMissingType() { public int getMissingType() {
return expecting; return expecting.getSingleElement();
} }
public String toString() { public String toString() {

View File

@ -28,32 +28,24 @@
package org.antlr.v4.runtime; package org.antlr.v4.runtime;
import org.antlr.runtime.CharStream; import org.antlr.runtime.CharStream;
import org.antlr.v4.runtime.misc.LABitSet;
public class NoViableAltException extends RecognitionException { public class NoViableAltException extends RecognitionException {
public String grammarDecisionDescription;
public int decisionNumber;
public int stateNumber;
/** Used for remote debugger deserialization */ /** Used for remote debugger deserialization */
public NoViableAltException() {;} public NoViableAltException() {;}
public NoViableAltException(BaseRecognizer recognizer, public NoViableAltException(BaseRecognizer recognizer,
String grammarDecisionDescription, LABitSet expecting)
int decisionNumber,
int stateNumber)
{ {
super(recognizer); super(recognizer, expecting);
this.grammarDecisionDescription = grammarDecisionDescription;
this.decisionNumber = decisionNumber;
this.stateNumber = stateNumber;
} }
public String toString() { public String toString() {
if ( recognizer.state.input instanceof CharStream) { if ( recognizer.state.input instanceof CharStream) {
return "NoViableAltException('"+(char)getUnexpectedType()+"'@["+grammarDecisionDescription+"])"; return "NoViableAltException('"+(char)getUnexpectedType()+", expecting "+expecting+")";
} }
else { else {
return "NoViableAltException("+getUnexpectedType()+"@["+grammarDecisionDescription+"])"; return "NoViableAltException('"+getUnexpectedType()+", expecting "+expecting+")";
} }
} }
} }

View File

@ -35,6 +35,7 @@ import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.Tree; import org.antlr.runtime.tree.Tree;
import org.antlr.runtime.tree.TreeAdaptor; import org.antlr.runtime.tree.TreeAdaptor;
import org.antlr.runtime.tree.TreeNodeStream; import org.antlr.runtime.tree.TreeNodeStream;
import org.antlr.v4.runtime.misc.LABitSet;
/** The root of the ANTLR exception hierarchy. /** The root of the ANTLR exception hierarchy.
* *
@ -70,8 +71,7 @@ public class RecognitionException extends RuntimeException {
/** Who threw the exception? */ /** Who threw the exception? */
public BaseRecognizer recognizer; public BaseRecognizer recognizer;
/** What input stream did the error occur in? */ public LABitSet expecting;
//public transient IntStream input;
/** What is index of token/char were we looking at when the error occurred? */ /** What is index of token/char were we looking at when the error occurred? */
public int index; public int index;
@ -110,7 +110,12 @@ public class RecognitionException extends RuntimeException {
} }
public RecognitionException(BaseRecognizer recognizer) { public RecognitionException(BaseRecognizer recognizer) {
this(recognizer, null);
}
public RecognitionException(BaseRecognizer recognizer, LABitSet expecting) {
this.recognizer = recognizer; this.recognizer = recognizer;
this.expecting = expecting;
IntStream input = recognizer.state.input; IntStream input = recognizer.state.input;
this.index = input.index(); this.index = input.index();
if ( input instanceof TokenStream ) { if ( input instanceof TokenStream ) {
@ -131,10 +136,6 @@ public class RecognitionException extends RuntimeException {
} }
} }
// public RecognitionException(IntStream input) {
// this.input = input;
// }
protected void extractInformationFromTreeNodeStream(IntStream input) { protected void extractInformationFromTreeNodeStream(IntStream input) {
TreeNodeStream nodes = (TreeNodeStream)input; TreeNodeStream nodes = (TreeNodeStream)input;
this.node = nodes.LT(1); this.node = nodes.LT(1);

View File

@ -44,9 +44,6 @@ public class UnwantedTokenException extends MismatchedTokenException {
public String toString() { public String toString() {
String exp = ", expected "+expecting; String exp = ", expected "+expecting;
if ( expecting==Token.INVALID_TOKEN_TYPE ) {
exp = "";
}
if ( token==null ) { if ( token==null ) {
return "UnwantedTokenException(found="+null+exp+")"; return "UnwantedTokenException(found="+null+exp+")";
} }

View File

@ -43,6 +43,12 @@ public class LABitSet {
this.EOF = EOF; this.EOF = EOF;
} }
public static LABitSet of(int el) {
LABitSet s = new LABitSet(el + 1);
s.add(el);
return s;
}
/** or this element into this set (grow as necessary to accommodate) */ /** or this element into this set (grow as necessary to accommodate) */
public void add(int el) { public void add(int el) {
//System.out.println("add("+el+")"); //System.out.println("add("+el+")");
@ -57,7 +63,7 @@ public class LABitSet {
} }
public boolean member(int el) { public boolean member(int el) {
if ( el == Token.EOF && EOF ) return true; if ( el == Token.EOF ) return EOF;
int n = wordNumber(el); int n = wordNumber(el);
if (n >= bits.length) return false; if (n >= bits.length) return false;
return (bits[n] & bitMask(el)) != 0; return (bits[n] & bitMask(el)) != 0;
@ -123,24 +129,35 @@ public class LABitSet {
bits = newbits; bits = newbits;
} }
/** Get the first element you find and return it. */
public int getSingleElement() {
for (int i = 0; i < (bits.length << LOG_BITS); i++) {
if (member(i)) {
return i;
}
}
return Token.INVALID_TOKEN_TYPE;
}
/** Transform a bit set into a string by formatting each element as an integer /** Transform a bit set into a string by formatting each element as an integer
* separator The string to put in between elements * separator The string to put in between elements
* @return A commma-separated list of values * @return A commma-separated list of values
*/ */
public String toString() { public String toString() {
System.out.println("toStr");
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
String separator = ","; String separator = ",";
boolean havePrintedAnElement = false; boolean havePrintedAnElement = false;
buf.append('{'); buf.append('{');
if ( EOF ) { buf.append("EOF"); havePrintedAnElement=true; }
for (int i = 0; i < (bits.length << LOG_BITS); i++) { for (int i = 0; i < (bits.length << LOG_BITS); i++) {
System.out.println("i="+i);
if (member(i)) { if (member(i)) {
if (i > 0 && havePrintedAnElement ) { if ( havePrintedAnElement ) {
buf.append(separator); buf.append(separator);
} }
else { buf.append(i);
buf.append(i);
}
havePrintedAnElement = true; havePrintedAnElement = true;
} }
} }

View File

@ -80,6 +80,10 @@ RuleFunction(f,code,decls,context,scope,namedActions,finallyAction) ::= <<
try { try {
<code> <code>
} }
catch (RecognitionException re) {
reportError(re);
recover();
}
finally { finally {
<namedActions.after> <namedActions.after>
<f.globalScopesUsed:{s | <s>_stack.pop();}; separator="\n"> <f.globalScopesUsed:{s | <s>_stack.pop();}; separator="\n">
@ -94,45 +98,45 @@ CodeBlock(c, ops) ::= <<
<ops; separator="\n"> <ops; separator="\n">
>> >>
LL1Choice(choice, alts) ::= << LL1Choice(choice, alts, error) ::= <<
switch ( input.LA(1) ) { switch ( state.input.LA(1) ) {
<choice.altLook,alts:{look,alt| <cases(ttypes=look)> <choice.altLook,alts:{look,alt| <cases(ttypes=look)>
<alt> <alt>
break;}; separator="\n"> break;}; separator="\n">
default : default :
error <error>
} }
>> >>
// follow set included as choice by analysis // follow set included as choice by analysis
LL1OptionalBlock ::= LL1Choice LL1OptionalBlock ::= LL1Choice
LL1OptionalBlockSingleAlt(choice, expr, alts, preamble) ::= << LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error) ::= <<
<preamble; separator="\n"> <preamble; separator="\n">
if ( <expr> ) { if ( <expr> ) {
<alts; separator="\n"> <alts; separator="\n">
} }
else { else {
NoViableAltException nvae = new NoViableAltException("", 4, 0, input); <error>
} }
>> >>
LL1StarBlock(choice, alts) ::= << LL1StarBlock(choice, alts, error) ::= <<
<choice.loopLabel>: <choice.loopLabel>:
while (true) { while (true) {
switch ( input.LA(1) ) { switch ( state.input.LA(1) ) {
<choice.altLook,alts:{look,alt| <cases(ttypes=look)> <choice.altLook,alts:{look,alt| <cases(ttypes=look)>
<alt> <alt>
break;}; separator="\n"> break;}; separator="\n">
<cases(ttypes=choice.exitLook)> <cases(ttypes=choice.exitLook)>
break <choice.loopLabel>; break <choice.loopLabel>;
default : default :
error <error>
} }
} }
>> >>
LL1StarBlockSingleAlt(choice, expr, alts, preamble, iteration) ::= << LL1StarBlockSingleAlt(choice, expr, alts, preamble, iteration, error) ::= <<
<preamble; separator="\n"> <preamble; separator="\n">
while ( <expr> ) { while ( <expr> ) {
<alts; separator="\n"> <alts; separator="\n">
@ -140,24 +144,26 @@ while ( <expr> ) {
} }
>> >>
LL1PlusBlock(choice, alts) ::= << LL1PlusBlock(choice, alts, error, earlyExitError) ::= <<
int <choice.loopCounterVar> = 0; int <choice.loopCounterVar> = 0;
<choice.loopLabel>: <choice.loopLabel>:
while (true) { while (true) {
switch ( input.LA(1) ) { switch ( state.input.LA(1) ) {
<choice.altLook,alts:{look,alt| <cases(ttypes=look)> <choice.altLook,alts:{look,alt| <cases(ttypes=look)>
<alt> <alt>
break;}; separator="\n"> break;}; separator="\n">
<cases(ttypes=choice.exitLook)> <cases(ttypes=choice.exitLook)>
if ( <choice.loopCounterVar> >= 1 ) break <choice.loopLabel>; if ( <choice.loopCounterVar> >= 1 ) break <choice.loopLabel>;
else error else <earlyExitError>
default : default :
error <error>
} }
} }
>> >>
LL1PlusBlockSingleAlt(choice, expr, alts, preamble, iteration) ::= << LL1PlusBlockSingleAlt(choice, expr, alts, preamble, iteration,
error, earlyExitError) ::=
<<
<preamble; separator="\n"> <preamble; separator="\n">
do { do {
<alts; separator="\n"> <alts; separator="\n">
@ -165,8 +171,11 @@ do {
} while ( <expr> ); } while ( <expr> );
>> >>
ThrowNoViableAlt(t) ::= "throw new NoViableAlt(this, <t.expecting.name>);"
ThrowEarlyExitException(t) ::= "throw new ThrowEarlyExitException(this, <t.expecting.name>);"
TestSet(s) ::= << TestSet(s) ::= <<
<s.set.name>.member(input.LA(1)) <s.set.name>.member(state.input.LA(1))
>> >>
TestSetInline(s) ::= << TestSetInline(s) ::= <<
@ -190,7 +199,7 @@ MatchToken(m) ::= <<
Action(a, chunks) ::= "<chunks>" Action(a, chunks) ::= "<chunks>"
SemPred(p) ::= << SemPred(p) ::= <<
if (!(<p.ast.text>)) throw new FailedPredicateException(input, "<ruleName>", "<description>"); if (!(<p.ast.text>)) throw new FailedPredicateException(this,"<ruleName>", "<description>");
>> >>
ActionText(t) ::= "<t.text>" ActionText(t) ::= "<t.text>"
@ -236,7 +245,7 @@ TokenDecl(t) ::= "Token <t.name>;"
TokenListDecl(t) ::= "List\<Token> <t.name> = new ArrayList\<Token>();" TokenListDecl(t) ::= "List\<Token> <t.name> = new ArrayList\<Token>();"
RuleContextDecl(r) ::= "<r.ctxName> <r.name>;" RuleContextDecl(r) ::= "<r.ctxName> <r.name>;"
CaptureNextToken(d) ::= "<d.varName> = input.LA(1);" CaptureNextToken(d) ::= "<d.varName> = state.input.LA(1);"
StructDecl(s,attrs) ::= << StructDecl(s,attrs) ::= <<
public static class <s.name> extends ParserRuleContext { public static class <s.name> extends ParserRuleContext {

View File

@ -51,7 +51,7 @@ public class AnalysisPipeline {
System.out.println("\nDECISION "+s.decision); System.out.println("\nDECISION "+s.decision);
// TRY LINEAR APPROX FIXED LOOKAHEAD FIRST // TRY LINEAR APPROX FIXED LOOKAHEAD FIRST
LinearApproximator lin = new LinearApproximator(g, s.decision); LinearApproximator lin = new LinearApproximator(g);
DFA dfa = lin.createDFA(s); DFA dfa = lin.createDFA(s);
// IF NOT LINEAR APPROX, TRY NFA TO DFA CONVERSION // IF NOT LINEAR APPROX, TRY NFA TO DFA CONVERSION

View File

@ -65,13 +65,13 @@ public class LinearApproximator {
*/ */
OrderedHashSet<NFAConfig>[] configs; OrderedHashSet<NFAConfig>[] configs;
public LinearApproximator(Grammar g, int decision) { public LinearApproximator(Grammar g) {
this.g = g; this.g = g;
this.decision = decision; this.decision = decision;
} }
public LinearApproximator(Grammar g, int decision, int k) { public LinearApproximator(Grammar g, int k) {
this(g,decision); this(g);
max_k = k; max_k = k;
} }

View File

@ -105,4 +105,11 @@ public abstract class OutputModelFactory {
BitSetDecl b = new BitSetDecl(this, name, set); BitSetDecl b = new BitSetDecl(this, name, set);
return b; return b;
} }
public BitSetDecl createExpectingBitSet(GrammarAST ast, int decision, IntervalSet set) {
String inRuleName = ast.nfaState.rule.name;
String name = "EXPECTING_in_"+inRuleName+"_"+decision;
BitSetDecl b = new BitSetDecl(this, name, set);
return b;
}
} }

View File

@ -11,18 +11,32 @@ import org.stringtemplate.v4.misc.BlankST;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.*; import java.util.*;
/** Convert output model tree to template hierarchy */ /** Convert an output model tree to template hierarchy by walking
* the output model. Each output model object has a corresponding template
* of the same name. An output model object can have nested objects.
* We identify those nested objects by the list of arguments in the template
* definition. For example, here is the definition of the parser template:
*
* Parser(parser, scopes, funcs) ::= <<...>>
*
* The first template argument is always the output model object from which
* this walker will create the template. Any other arguments identify
* the field names within the output model object of nested model objects.
* So, in this case, template Parser is saying that output model object
* Parser has two fields the walker should chase called a scopes and funcs.
*
* This simple mechanism means we don't have to include code in every
* output model object that says how to create the corresponding template.
*/
public class OutputModelWalker { public class OutputModelWalker {
Tool tool; Tool tool;
STGroup templates; STGroup templates;
//Map<Class, String> modelToTemplateMap;
public OutputModelWalker(Tool tool, public OutputModelWalker(Tool tool,
STGroup templates) STGroup templates)
{ {
this.tool = tool; this.tool = tool;
this.templates = templates; this.templates = templates;
//this.modelToTemplateMap = modelToTemplateMap;
} }
public ST walk(OutputModelObject omo) { public ST walk(OutputModelObject omo) {
@ -42,28 +56,17 @@ public class OutputModelWalker {
return st; return st;
} }
List<String> kids = omo.getChildren();
LinkedHashMap<String,FormalArgument> formalArgs = st.impl.formalArguments; LinkedHashMap<String,FormalArgument> formalArgs = st.impl.formalArguments;
Set<String> argNames = formalArgs.keySet(); Set<String> argNames = formalArgs.keySet();
Iterator<String> it = argNames.iterator(); Iterator<String> arg_it = argNames.iterator();
// PASS IN OUTPUT MODEL OBJECT TO TEMPLATE // PASS IN OUTPUT MODEL OBJECT TO TEMPLATE
String modelArgName = it.next(); // ordered so this is first arg String modelArgName = arg_it.next(); // ordered so this is first arg
st.add(modelArgName, omo); st.add(modelArgName, omo);
// ENSURE TEMPLATE ARGS AND CHILD FIELDS MATCH UP
while ( it.hasNext() ) {
String argName = it.next();
if ( kids==null || !kids.contains(argName) ) {
tool.errMgr.toolError(ErrorType.CODE_TEMPLATE_ARG_ISSUE, templateName, argName);
return st;
}
}
// COMPUTE STs FOR EACH NESTED MODEL OBJECT NAMED AS ARG BY TEMPLATE // COMPUTE STs FOR EACH NESTED MODEL OBJECT NAMED AS ARG BY TEMPLATE
if ( kids!=null ) for (String fieldName : kids) { while ( arg_it.hasNext() ) {
if ( !argNames.contains(fieldName) ) continue; // they won't use so don't compute String fieldName = arg_it.next();
//System.out.println("computing ST for field "+fieldName+" of "+omo.getClass()); //System.out.println("computing ST for field "+fieldName+" of "+omo.getClass());
try { try {
Field fi = omo.getClass().getField(fieldName); Field fi = omo.getClass().getField(fieldName);

View File

@ -6,7 +6,6 @@ import org.antlr.v4.codegen.src.actions.ActionChunk;
import org.antlr.v4.tool.ActionAST; import org.antlr.v4.tool.ActionAST;
import org.antlr.v4.tool.GrammarAST; import org.antlr.v4.tool.GrammarAST;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** */ /** */
@ -20,13 +19,13 @@ public class Action extends SrcOp {
System.out.println("actions="+chunks); System.out.println("actions="+chunks);
} }
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ // return new ArrayList<String>() {{
if ( sup!=null ) addAll(sup); // if ( sup!=null ) addAll(sup);
add("chunks"); // add("chunks");
}}; // }};
} // }
} }

View File

@ -2,10 +2,11 @@ package org.antlr.v4.codegen.src;
import org.antlr.v4.codegen.OutputModelFactory; import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet; import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.LABitSet;
/** */ /** */
public class BitSetDecl extends Decl { public class BitSetDecl extends Decl {
public Object fset; // runtime bitset public LABitSet fset; // runtime bitset
public BitSetDecl(OutputModelFactory factory, String name, IntervalSet fset) { public BitSetDecl(OutputModelFactory factory, String name, IntervalSet fset) {
super(factory, name); super(factory, name);
this.fset = fset.toRuntimeBitSet(); this.fset = fset.toRuntimeBitSet();

View File

@ -1,7 +1,10 @@
package org.antlr.v4.codegen.src; package org.antlr.v4.codegen.src;
import org.antlr.v4.analysis.LinearApproximator;
import org.antlr.v4.automata.BlockStartState; import org.antlr.v4.automata.BlockStartState;
import org.antlr.v4.automata.NFAState;
import org.antlr.v4.codegen.OutputModelFactory; import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST; import org.antlr.v4.tool.GrammarAST;
import java.util.ArrayList; import java.util.ArrayList;
@ -12,12 +15,20 @@ public abstract class Choice extends SrcOp {
public int decision; public int decision;
public List<CodeBlock> alts; public List<CodeBlock> alts;
public List<SrcOp> preamble; public List<SrcOp> preamble;
public IntervalSet expecting;
public ThrowNoViableAlt error;
public Choice(OutputModelFactory factory, GrammarAST blkOrEbnfRootAST, List<CodeBlock> alts) { public Choice(OutputModelFactory factory, GrammarAST blkOrEbnfRootAST, List<CodeBlock> alts) {
this.factory = factory; super(factory, blkOrEbnfRootAST);
this.ast = blkOrEbnfRootAST;
this.alts = alts; this.alts = alts;
this.decision = ((BlockStartState)blkOrEbnfRootAST.nfaState).decision; this.decision = ((BlockStartState)blkOrEbnfRootAST.nfaState).decision;
LinearApproximator approx = new LinearApproximator(factory.g);
NFAState decisionState = ast.nfaState;
expecting = approx.LOOK(decisionState);
System.out.println("expecting="+expecting);
this.error = new ThrowNoViableAlt(factory, blkOrEbnfRootAST, expecting);
} }
public void addPreambleOp(SrcOp op) { public void addPreambleOp(SrcOp op) {
@ -25,9 +36,10 @@ public abstract class Choice extends SrcOp {
preamble.add(op); preamble.add(op);
} }
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("alts"); add("preamble"); }}; // return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup);
} // add("alts"); add("preamble"); add("error"); }};
// }
} }

View File

@ -20,9 +20,9 @@ public class CodeBlock extends SrcOp {
this(factory, new ArrayList<SrcOp>() {{ add(elem); }}); this(factory, new ArrayList<SrcOp>() {{ add(elem); }});
} }
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("ops"); }}; // return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("ops"); }};
} // }
} }

View File

@ -48,7 +48,7 @@ public class InvokeRule extends SrcOp implements LabeledOp {
} }
// compute follow // compute follow
LinearApproximator approx = new LinearApproximator(factory.g, -1); LinearApproximator approx = new LinearApproximator(factory.g);
IntervalSet fset = approx.LOOK(ast.nfaState.transition(0).target); IntervalSet fset = approx.LOOK(ast.nfaState.transition(0).target);
System.out.println("follow="+follow); System.out.println("follow="+follow);
follow = factory.createFollowBitSet(ast, fset); follow = factory.createFollowBitSet(ast, fset);

View File

@ -15,6 +15,7 @@ public class LL1Choice extends Choice {
public List<String[]> altLook; public List<String[]> altLook;
/** Lookahead for each alt 1..n */ /** Lookahead for each alt 1..n */
public IntervalSet[] altLookSets; public IntervalSet[] altLookSets;
public LL1Choice(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) { public LL1Choice(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
super(factory, blkAST, alts); super(factory, blkAST, alts);
DFA dfa = factory.g.decisionDFAs.get(decision); DFA dfa = factory.g.decisionDFAs.get(decision);

View File

@ -35,12 +35,12 @@ public abstract class LL1Loop extends LL1Choice {
} }
} }
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ // return new ArrayList<String>() {{
if ( sup!=null ) addAll(sup); add("expr"); add("iteration"); // if ( sup!=null ) addAll(sup); add("expr"); add("iteration");
}}; // }};
} // }
} }

View File

@ -4,7 +4,6 @@ import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet; import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST; import org.antlr.v4.tool.GrammarAST;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** */ /** */
@ -21,9 +20,9 @@ public class LL1OptionalBlockSingleAlt extends LL1Choice {
} }
} }
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("expr"); }}; // return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("expr"); }};
} // }
} }

View File

@ -13,6 +13,8 @@ public class LL1PlusBlock extends LL1Loop {
public String loopLabel; public String loopLabel;
public String loopCounterVar; public String loopCounterVar;
public String[] exitLook; public String[] exitLook;
public ThrowEarlyExitException earlyExitError;
public LL1PlusBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) { public LL1PlusBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
super(factory, blkAST, alts); super(factory, blkAST, alts);
PlusBlockStartState plusStart = (PlusBlockStartState)blkAST.nfaState; PlusBlockStartState plusStart = (PlusBlockStartState)blkAST.nfaState;
@ -24,5 +26,15 @@ public class LL1PlusBlock extends LL1Loop {
loopLabel = factory.gen.target.getLoopLabel(blkAST); loopLabel = factory.gen.target.getLoopLabel(blkAST);
loopCounterVar = factory.gen.target.getLoopCounter(blkAST); loopCounterVar = factory.gen.target.getLoopCounter(blkAST);
this.earlyExitError = new ThrowEarlyExitException(factory, blkAST, expecting);
} }
// @Override
// public List<String> getChildren() {
// final List<String> sup = super.getChildren();
// return new ArrayList<String>() {{
// if ( sup!=null ) addAll(sup); add("earlyExitError");
// }};
// }
} }

View File

@ -8,10 +8,18 @@ import java.util.List;
/** */ /** */
public class LL1PlusBlockSingleAlt extends LL1Loop { public class LL1PlusBlockSingleAlt extends LL1Loop {
public ThrowEarlyExitException earlyExitError;
public LL1PlusBlockSingleAlt(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) { public LL1PlusBlockSingleAlt(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
super(factory, blkAST, alts); super(factory, blkAST, alts);
IntervalSet loopBackLook = altLookSets[2]; // loop exit is alt 1 IntervalSet loopBackLook = altLookSets[2]; // loop exit is alt 1
addLookaheadTempVar(loopBackLook); addLookaheadTempVar(loopBackLook);
} }
// @Override
// public List<String> getChildren() {
// final List<String> sup = super.getChildren();
// return new ArrayList<String>() {{
// if ( sup!=null ) addAll(sup); add("earlyExitError");
// }};
// }
} }

View File

@ -39,7 +39,7 @@ public class MatchToken extends SrcOp implements LabeledOp {
factory.currentRule.peek().addDecl(d); factory.currentRule.peek().addDecl(d);
} }
LinearApproximator approx = new LinearApproximator(factory.g, -1); LinearApproximator approx = new LinearApproximator(factory.g);
IntervalSet fset = approx.LOOK(ast.nfaState.transition(0).target); IntervalSet fset = approx.LOOK(ast.nfaState.transition(0).target);
System.out.println("follow="+fset); System.out.println("follow="+fset);
follow = factory.createFollowBitSet(ast, fset); follow = factory.createFollowBitSet(ast, fset);

View File

@ -3,8 +3,6 @@ package org.antlr.v4.codegen.src;
import org.antlr.v4.codegen.OutputModelFactory; import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.tool.GrammarAST; import org.antlr.v4.tool.GrammarAST;
import java.util.List;
/** */ /** */
public abstract class OutputModelObject { public abstract class OutputModelObject {
public OutputModelFactory factory; public OutputModelFactory factory;
@ -27,7 +25,7 @@ public abstract class OutputModelObject {
* of type OutputModelObject that should be walked to complete model. * of type OutputModelObject that should be walked to complete model.
*/ */
// TODO: make list of Fields to avoid repeated look up // TODO: make list of Fields to avoid repeated look up
public List<String> getChildren() { // public List<String> getChildren() {
return null; // return null;
} // }
} }

View File

@ -32,9 +32,9 @@ public class Parser extends OutputModelObject {
for (Rule r : factory.g.rules.values()) funcs.add( new RuleFunction(factory, r) ); for (Rule r : factory.g.rules.values()) funcs.add( new RuleFunction(factory, r) );
} }
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("funcs"); add("scopes"); }}; // return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("funcs"); add("scopes"); }};
} // }
} }

View File

@ -36,15 +36,15 @@ public class ParserFile extends OutputModelObject {
bitSetDecls.add(b); bitSetDecls.add(b);
} }
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ // return new ArrayList<String>() {{
if ( sup!=null ) addAll(sup); // if ( sup!=null ) addAll(sup);
add("parser"); // add("parser");
add("dfaDecls"); // add("dfaDecls");
add("namedActions"); // add("namedActions");
add("bitSetDecls"); // add("bitSetDecls");
}}; // }};
} // }
} }

View File

@ -105,13 +105,13 @@ public class RuleFunction extends OutputModelObject {
decls.add(d); decls.add(d);
} }
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ // return new ArrayList<String>() {{
if ( sup!=null ) addAll(sup); // if ( sup!=null ) addAll(sup);
add("context"); add("scope"); add("decls"); add("code"); // add("context"); add("scope"); add("decls"); add("code");
add("finallyAction"); add("namedActions"); // add("finallyAction"); add("namedActions");
}}; // }};
} // }
} }

View File

@ -19,11 +19,11 @@ public class StructDecl extends Decl {
} }
} }
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ // return new ArrayList<String>() {{
if ( sup!=null ) addAll(sup); add("attrs"); // if ( sup!=null ) addAll(sup); add("attrs");
}}; // }};
} // }
} }

View File

@ -0,0 +1,12 @@
package org.antlr.v4.codegen.src;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
/** */
public class ThrowEarlyExitException extends ThrowRecognitionException {
public ThrowEarlyExitException(OutputModelFactory factory, GrammarAST ast, IntervalSet expecting) {
super(factory, ast, expecting);
}
}

View File

@ -0,0 +1,14 @@
package org.antlr.v4.codegen.src;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
/** */
public class ThrowNoViableAlt extends ThrowRecognitionException {
public ThrowNoViableAlt(OutputModelFactory factory, GrammarAST blkOrEbnfRootAST,
IntervalSet expecting)
{
super(factory, blkOrEbnfRootAST, expecting);
}
}

View File

@ -0,0 +1,25 @@
package org.antlr.v4.codegen.src;
import org.antlr.v4.automata.BlockStartState;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
/** */
public class ThrowRecognitionException extends SrcOp {
public int decision;
public String grammarFile;
public int grammarLine;
public int grammarCharPosInLine;
public BitSetDecl expecting;
public ThrowRecognitionException(OutputModelFactory factory, GrammarAST ast, IntervalSet expecting) {
super(factory, ast);
this.decision = ((BlockStartState)ast.nfaState).decision;
grammarLine = ast.getLine();
grammarLine = ast.getCharPositionInLine();
grammarFile = factory.g.fileName;
this.expecting = factory.createExpectingBitSet(ast, decision, expecting);
factory.defineBitSet(this.expecting);
}
}

View File

@ -1,6 +1,5 @@
package org.antlr.v4.codegen.src.actions; package org.antlr.v4.codegen.src.actions;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** */ /** */
@ -11,12 +10,12 @@ public class DynScopeAttrRef_index extends DynScopeAttrRef {
this.indexChunks = indexChunks; this.indexChunks = indexChunks;
} }
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ // return new ArrayList<String>() {{
if ( sup!=null ) addAll(sup); // if ( sup!=null ) addAll(sup);
add("indexChunks"); // add("indexChunks");
}}; // }};
} // }
} }

View File

@ -1,6 +1,5 @@
package org.antlr.v4.codegen.src.actions; package org.antlr.v4.codegen.src.actions;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** */ /** */
@ -13,12 +12,12 @@ public class SetAttr extends ActionChunk {
this.rhsChunks = rhsChunks; this.rhsChunks = rhsChunks;
} }
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ // return new ArrayList<String>() {{
if ( sup!=null ) addAll(sup); // if ( sup!=null ) addAll(sup);
add("rhsChunks"); // add("rhsChunks");
}}; // }};
} // }
} }

View File

@ -1,6 +1,5 @@
package org.antlr.v4.codegen.src.actions; package org.antlr.v4.codegen.src.actions;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** */ /** */
@ -14,13 +13,13 @@ public class SetDynScopeAttr extends ActionChunk {
this.attr = attr; this.attr = attr;
this.rhsChunks = rhsChunks; this.rhsChunks = rhsChunks;
} }
//
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ // return new ArrayList<String>() {{
if ( sup!=null ) addAll(sup); // if ( sup!=null ) addAll(sup);
add("rhsChunks"); // add("rhsChunks");
}}; // }};
} // }
} }

View File

@ -1,6 +1,5 @@
package org.antlr.v4.codegen.src.actions; package org.antlr.v4.codegen.src.actions;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** */ /** */
@ -11,12 +10,12 @@ public class SetDynScopeAttr_index extends SetDynScopeAttr {
this.indexChunks = indexChunks; this.indexChunks = indexChunks;
} }
@Override // @Override
public List<String> getChildren() { // public List<String> getChildren() {
final List<String> sup = super.getChildren(); // final List<String> sup = super.getChildren();
return new ArrayList<String>() {{ // return new ArrayList<String>() {{
if ( sup!=null ) addAll(sup); // if ( sup!=null ) addAll(sup);
add("indexChunks"); // add("indexChunks");
}}; // }};
} // }
} }

View File

@ -1,4 +1,4 @@
// $ANTLR ${project.version} ${buildNumber} ANTLRLexer.g 2010-05-19 15:07:23 // $ANTLR ${project.version} ${buildNumber} ANTLRLexer.g 2010-05-21 18:40:58
/* /*
[The "BSD licence"] [The "BSD licence"]
@ -264,7 +264,7 @@ public class ANTLRLexer extends Lexer {
if ( (( input.LA(2) != '/')) ) { if ( (( input.LA(2) != '/')) ) {
alt3=1; alt3=1;
} }
else if ( ((( true )||(( true )&&( !(input.LA(1) == '*' && input.LA(2) == '/') )))) ) { else if ( (((( true )&&( !(input.LA(1) == '*' && input.LA(2) == '/') ))||( true ))) ) {
alt3=2; alt3=2;
} }
else { else {

View File

@ -567,11 +567,11 @@ element
} }
@after { paraphrases.pop(); } @after { paraphrases.pop(); }
: labeledElement : labeledElement
( ebnfSuffix -> ^( ebnfSuffix ^(BLOCK<BlockAST>[$labeledElement.start,"BLOCK"] ^(ALT labeledElement ) )) ( ebnfSuffix -> ^( ebnfSuffix ^(BLOCK<BlockAST>[$labeledElement.start,"BLOCK"] ^(ALT<AltAST> labeledElement ) ))
| -> labeledElement | -> labeledElement
) )
| atom | atom
( ebnfSuffix -> ^( ebnfSuffix ^(BLOCK<BlockAST>[$atom.start,"BLOCK"] ^(ALT atom) ) ) ( ebnfSuffix -> ^( ebnfSuffix ^(BLOCK<BlockAST>[$atom.start,"BLOCK"] ^(ALT<AltAST> atom) ) )
| -> atom | -> atom
) )
| ebnf | ebnf
@ -581,7 +581,7 @@ element
| -> SEMPRED | -> SEMPRED
) )
| treeSpec | treeSpec
( ebnfSuffix -> ^( ebnfSuffix ^(BLOCK<BlockAST>[$treeSpec.start,"BLOCK"] ^(ALT treeSpec ) ) ) ( ebnfSuffix -> ^( ebnfSuffix ^(BLOCK<BlockAST>[$treeSpec.start,"BLOCK"] ^(ALT<AltAST> treeSpec ) ) )
| -> treeSpec | -> treeSpec
) )
; ;

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
// $ANTLR ${project.version} ${buildNumber} ASTVerifier.g 2010-05-19 15:07:27 // $ANTLR ${project.version} ${buildNumber} ASTVerifier.g 2010-05-21 18:41:01
/* /*
[The "BSD license"] [The "BSD license"]

View File

@ -1,4 +1,4 @@
// $ANTLR ${project.version} ${buildNumber} ActionSplitter.g 2010-05-19 15:07:26 // $ANTLR ${project.version} ${buildNumber} ActionSplitter.g 2010-05-21 18:41:01
package org.antlr.v4.parse; package org.antlr.v4.parse;
@ -2399,11 +2399,11 @@ public class ActionSplitter extends Lexer {
state.failed=false; state.failed=false;
return success; return success;
} }
public final boolean synpred15_ActionSplitter() { public final boolean synpred3_ActionSplitter() {
state.backtracking++; state.backtracking++;
int start = input.mark(); int start = input.mark();
try { try {
synpred15_ActionSplitter_fragment(); // can never throw exception synpred3_ActionSplitter_fragment(); // can never throw exception
} catch (RecognitionException re) { } catch (RecognitionException re) {
System.err.println("impossible: "+re); System.err.println("impossible: "+re);
} }
@ -2413,11 +2413,11 @@ public class ActionSplitter extends Lexer {
state.failed=false; state.failed=false;
return success; return success;
} }
public final boolean synpred3_ActionSplitter() { public final boolean synpred15_ActionSplitter() {
state.backtracking++; state.backtracking++;
int start = input.mark(); int start = input.mark();
try { try {
synpred3_ActionSplitter_fragment(); // can never throw exception synpred15_ActionSplitter_fragment(); // can never throw exception
} catch (RecognitionException re) { } catch (RecognitionException re) {
System.err.println("impossible: "+re); System.err.println("impossible: "+re);
} }
@ -2495,20 +2495,23 @@ public class ActionSplitter extends Lexer {
static final String DFA29_eofS = static final String DFA29_eofS =
"\32\uffff"; "\32\uffff";
static final String DFA29_minS = static final String DFA29_minS =
"\2\0\6\uffff\1\0\2\uffff\1\0\2\uffff\1\0\13\uffff"; "\2\0\2\uffff\1\0\7\uffff\1\0\2\uffff\1\0\12\uffff";
static final String DFA29_maxS = static final String DFA29_maxS =
"\1\uffff\1\0\6\uffff\1\0\2\uffff\1\0\2\uffff\1\0\13\uffff"; "\1\uffff\1\0\2\uffff\1\0\7\uffff\1\0\2\uffff\1\0\12\uffff";
static final String DFA29_acceptS = static final String DFA29_acceptS =
"\2\uffff\1\16\1\17\1\20\1\21\1\22\1\23\1\uffff\1\3\1\24\1\uffff"+ "\2\uffff\1\3\1\24\1\uffff\1\16\1\17\1\20\1\21\1\22\1\23\1\24\1\uffff"+
"\1\1\1\2\1\uffff\1\4\1\5\1\6\1\7\1\10\1\11\1\12\1\13\1\14\1\15\1"+ "\1\1\1\2\1\uffff\1\4\1\5\1\6\1\7\1\10\1\11\1\12\1\13\1\14\1\15";
"\24";
static final String DFA29_specialS = static final String DFA29_specialS =
"\1\0\1\1\6\uffff\1\2\2\uffff\1\3\2\uffff\1\4\13\uffff}>"; "\1\0\1\1\2\uffff\1\2\7\uffff\1\3\2\uffff\1\4\12\uffff}>";
static final String[] DFA29_transitionS = { static final String[] DFA29_transitionS = {
"\44\31\1\16\1\1\11\31\1\13\54\31\1\10\uffa3\31", "\44\13\1\17\1\4\11\13\1\14\54\13\1\1\uffa3\13",
"\1\uffff", "\1\uffff",
"", "",
"", "",
"\1\uffff",
"",
"",
"",
"", "",
"", "",
"", "",
@ -2519,10 +2522,6 @@ public class ActionSplitter extends Lexer {
"\1\uffff", "\1\uffff",
"", "",
"", "",
"\1\uffff",
"",
"",
"",
"", "",
"", "",
"", "",
@ -2573,15 +2572,15 @@ public class ActionSplitter extends Lexer {
int LA29_0 = input.LA(1); int LA29_0 = input.LA(1);
s = -1; s = -1;
if ( (LA29_0=='%') ) {s = 1;} if ( (LA29_0=='\\') ) {s = 1;}
else if ( (LA29_0=='\\') ) {s = 8;} else if ( (LA29_0=='%') ) {s = 4;}
else if ( (LA29_0=='/') ) {s = 11;} else if ( ((LA29_0>='\u0000' && LA29_0<='#')||(LA29_0>='&' && LA29_0<='.')||(LA29_0>='0' && LA29_0<='[')||(LA29_0>=']' && LA29_0<='\uFFFF')) ) {s = 11;}
else if ( (LA29_0=='$') ) {s = 14;} else if ( (LA29_0=='/') ) {s = 12;}
else if ( ((LA29_0>='\u0000' && LA29_0<='#')||(LA29_0>='&' && LA29_0<='.')||(LA29_0>='0' && LA29_0<='[')||(LA29_0>=']' && LA29_0<='\uFFFF')) ) {s = 25;} else if ( (LA29_0=='$') ) {s = 15;}
if ( s>=0 ) return s; if ( s>=0 ) return s;
break; break;
@ -2592,83 +2591,83 @@ public class ActionSplitter extends Lexer {
int index29_1 = input.index(); int index29_1 = input.index();
input.rewind(); input.rewind();
s = -1; s = -1;
if ( (synpred14_ActionSplitter()) ) {s = 2;} if ( (synpred3_ActionSplitter()) ) {s = 2;}
else if ( (synpred15_ActionSplitter()) ) {s = 3;} else if ( (true) ) {s = 3;}
else if ( (synpred16_ActionSplitter()) ) {s = 4;}
else if ( (synpred17_ActionSplitter()) ) {s = 5;}
else if ( (synpred18_ActionSplitter()) ) {s = 6;}
else if ( (synpred19_ActionSplitter()) ) {s = 7;}
input.seek(index29_1); input.seek(index29_1);
if ( s>=0 ) return s; if ( s>=0 ) return s;
break; break;
case 2 : case 2 :
int LA29_8 = input.LA(1); int LA29_4 = input.LA(1);
int index29_8 = input.index(); int index29_4 = input.index();
input.rewind(); input.rewind();
s = -1; s = -1;
if ( (synpred3_ActionSplitter()) ) {s = 9;} if ( (synpred14_ActionSplitter()) ) {s = 5;}
else if ( (true) ) {s = 10;} else if ( (synpred15_ActionSplitter()) ) {s = 6;}
else if ( (synpred16_ActionSplitter()) ) {s = 7;}
else if ( (synpred17_ActionSplitter()) ) {s = 8;}
else if ( (synpred18_ActionSplitter()) ) {s = 9;}
else if ( (synpred19_ActionSplitter()) ) {s = 10;}
input.seek(index29_8); input.seek(index29_4);
if ( s>=0 ) return s; if ( s>=0 ) return s;
break; break;
case 3 : case 3 :
int LA29_11 = input.LA(1); int LA29_12 = input.LA(1);
int index29_11 = input.index(); int index29_12 = input.index();
input.rewind(); input.rewind();
s = -1; s = -1;
if ( (synpred1_ActionSplitter()) ) {s = 12;} if ( (synpred1_ActionSplitter()) ) {s = 13;}
else if ( (synpred2_ActionSplitter()) ) {s = 13;} else if ( (synpred2_ActionSplitter()) ) {s = 14;}
else if ( (true) ) {s = 10;} else if ( (true) ) {s = 11;}
input.seek(index29_11); input.seek(index29_12);
if ( s>=0 ) return s; if ( s>=0 ) return s;
break; break;
case 4 : case 4 :
int LA29_14 = input.LA(1); int LA29_15 = input.LA(1);
int index29_14 = input.index(); int index29_15 = input.index();
input.rewind(); input.rewind();
s = -1; s = -1;
if ( (synpred4_ActionSplitter()) ) {s = 15;} if ( (synpred4_ActionSplitter()) ) {s = 16;}
else if ( (synpred5_ActionSplitter()) ) {s = 16;} else if ( (synpred5_ActionSplitter()) ) {s = 17;}
else if ( (synpred6_ActionSplitter()) ) {s = 17;} else if ( (synpred6_ActionSplitter()) ) {s = 18;}
else if ( (synpred7_ActionSplitter()) ) {s = 18;} else if ( (synpred7_ActionSplitter()) ) {s = 19;}
else if ( (synpred8_ActionSplitter()) ) {s = 19;} else if ( (synpred8_ActionSplitter()) ) {s = 20;}
else if ( (synpred9_ActionSplitter()) ) {s = 20;} else if ( (synpred9_ActionSplitter()) ) {s = 21;}
else if ( (synpred10_ActionSplitter()) ) {s = 21;} else if ( (synpred10_ActionSplitter()) ) {s = 22;}
else if ( (synpred11_ActionSplitter()) ) {s = 22;} else if ( (synpred11_ActionSplitter()) ) {s = 23;}
else if ( (synpred12_ActionSplitter()) ) {s = 23;} else if ( (synpred12_ActionSplitter()) ) {s = 24;}
else if ( (synpred13_ActionSplitter()) ) {s = 24;} else if ( (synpred13_ActionSplitter()) ) {s = 25;}
input.seek(index29_14); input.seek(index29_15);
if ( s>=0 ) return s; if ( s>=0 ) return s;
break; break;
} }

View File

@ -1,4 +1,4 @@
// $ANTLR ${project.version} ${buildNumber} NFABuilder.g 2010-05-19 15:07:26 // $ANTLR ${project.version} ${buildNumber} NFABuilder.g 2010-05-21 18:41:01
/* /*
[The "BSD license"] [The "BSD license"]

View File

@ -102,7 +102,7 @@ public class TestLinearApproximateLookahead extends BaseTest {
return; return;
} }
DecisionState blk = (DecisionState)s.transition(0).target; DecisionState blk = (DecisionState)s.transition(0).target;
LinearApproximator lin = new LinearApproximator(g, blk.decision); LinearApproximator lin = new LinearApproximator(g);
DFA dfa = lin.createDFA(blk); DFA dfa = lin.createDFA(blk);
String result = null; String result = null;
if ( dfa!=null ) result = dfa.toString(); if ( dfa!=null ) result = dfa.toString();