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:
parent
bf92a4bc73
commit
03d9f0ba32
|
@ -106,11 +106,12 @@ public abstract class BaseRecognizer {
|
|||
state.failed = false;
|
||||
return matchedSymbol;
|
||||
}
|
||||
if ( state.backtracking>0 ) {
|
||||
state.failed = true;
|
||||
return matchedSymbol;
|
||||
}
|
||||
// if ( state.backtracking>0 ) {
|
||||
// state.failed = true;
|
||||
// return matchedSymbol;
|
||||
// }
|
||||
matchedSymbol = recoverFromMismatchedToken(ttype, follow);
|
||||
System.out.println("rsync'd to "+matchedSymbol);
|
||||
return matchedSymbol;
|
||||
}
|
||||
|
||||
|
@ -205,16 +206,16 @@ public abstract class BaseRecognizer {
|
|||
* exception types.
|
||||
*/
|
||||
public String getErrorMessage(RecognitionException e) {
|
||||
String[] tokenNames = getTokenNames();
|
||||
String[] tokenNames = getTokenNames();
|
||||
String msg = e.getMessage();
|
||||
if ( e instanceof UnwantedTokenException ) {
|
||||
UnwantedTokenException ute = (UnwantedTokenException)e;
|
||||
String tokenName="<unknown>";
|
||||
if ( ute.expecting== Token.EOF ) {
|
||||
if ( ute.expecting.member(Token.EOF) ) {
|
||||
tokenName = "EOF";
|
||||
}
|
||||
else {
|
||||
tokenName = tokenNames[ute.expecting];
|
||||
tokenName = tokenNames[ute.expecting.getSingleElement()];
|
||||
}
|
||||
msg = "extraneous input "+getTokenErrorDisplay(ute.getUnexpectedToken())+
|
||||
" expecting "+tokenName;
|
||||
|
@ -222,22 +223,22 @@ public abstract class BaseRecognizer {
|
|||
else if ( e instanceof MissingTokenException ) {
|
||||
MissingTokenException mte = (MissingTokenException)e;
|
||||
String tokenName="<unknown>";
|
||||
if ( mte.expecting== Token.EOF ) {
|
||||
if ( mte.expecting.member(Token.EOF) ) {
|
||||
tokenName = "EOF";
|
||||
}
|
||||
else {
|
||||
tokenName = tokenNames[mte.expecting];
|
||||
tokenName = tokenNames[mte.expecting.getSingleElement()];
|
||||
}
|
||||
msg = "missing "+tokenName+" at "+getTokenErrorDisplay(e.token);
|
||||
}
|
||||
else if ( e instanceof MismatchedTokenException ) {
|
||||
MismatchedTokenException mte = (MismatchedTokenException)e;
|
||||
String tokenName="<unknown>";
|
||||
if ( mte.expecting== Token.EOF ) {
|
||||
if ( mte.expecting.member(Token.EOF) ) {
|
||||
tokenName = "EOF";
|
||||
}
|
||||
else {
|
||||
tokenName = tokenNames[mte.expecting];
|
||||
tokenName = tokenNames[mte.expecting.getSingleElement()];
|
||||
}
|
||||
msg = "mismatched input "+getTokenErrorDisplay(e.token)+
|
||||
" expecting "+tokenName;
|
||||
|
@ -245,11 +246,11 @@ public abstract class BaseRecognizer {
|
|||
else if ( e instanceof MismatchedTreeNodeException ) {
|
||||
MismatchedTreeNodeException mtne = (MismatchedTreeNodeException)e;
|
||||
String tokenName="<unknown>";
|
||||
if ( mtne.expecting==Token.EOF ) {
|
||||
if ( mtne.expecting.member(Token.EOF) ) {
|
||||
tokenName = "EOF";
|
||||
}
|
||||
else {
|
||||
tokenName = tokenNames[mtne.expecting];
|
||||
tokenName = tokenNames[mtne.expecting.getSingleElement()];
|
||||
}
|
||||
msg = "mismatched tree node: "+mtne.node+
|
||||
" expecting "+tokenName;
|
||||
|
@ -310,6 +311,7 @@ public abstract class BaseRecognizer {
|
|||
* so that it creates a new Java type.
|
||||
*/
|
||||
public String getTokenErrorDisplay(Token t) {
|
||||
System.err.println("mmmm3");
|
||||
String s = t.getText();
|
||||
if ( s==null ) {
|
||||
if ( t.getType()==Token.EOF ) {
|
||||
|
@ -331,7 +333,7 @@ public abstract class BaseRecognizer {
|
|||
* handle mismatched symbol exceptions but there could be a mismatched
|
||||
* token that the match() routine could not recover from.
|
||||
*/
|
||||
public void recover(RecognitionException re) {
|
||||
public void recover() {
|
||||
if ( state.lastErrorIndex==state.input.index() ) {
|
||||
// uh oh, another error at same token index; must be a case
|
||||
// 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);
|
||||
/*
|
||||
System.err.println("recoverFromMismatchedToken deleting "+
|
||||
((TokenStream)input).LT(1)+
|
||||
" since "+((TokenStream)input).LT(2)+" is what we want");
|
||||
*/
|
||||
((TokenStream)state.input).LT(1)+
|
||||
" since "+((TokenStream)state.input).LT(2)+" is what we want");
|
||||
*/
|
||||
beginResync();
|
||||
state.input.consume(); // simply delete extra token
|
||||
endResync();
|
||||
|
|
|
@ -27,15 +27,14 @@
|
|||
*/
|
||||
package org.antlr.v4.runtime;
|
||||
|
||||
import org.antlr.v4.runtime.misc.LABitSet;
|
||||
|
||||
/** The recognizer did not match anything for a (..)+ loop. */
|
||||
public class EarlyExitException extends RecognitionException {
|
||||
public int decisionNumber;
|
||||
|
||||
/** Used for remote debugger deserialization */
|
||||
public EarlyExitException() {;}
|
||||
|
||||
public EarlyExitException(BaseRecognizer recognizer, int decisionNumber) {
|
||||
super(recognizer);
|
||||
this.decisionNumber = decisionNumber;
|
||||
public EarlyExitException(BaseRecognizer recognizer, LABitSet expecting) {
|
||||
super(recognizer, expecting);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -227,7 +227,8 @@ public abstract class Lexer /* extends BaseRecognizer */ implements TokenSource
|
|||
String msg = null;
|
||||
if ( e instanceof MismatchedTokenException ) {
|
||||
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 ) {
|
||||
NoViableAltException nvae = (NoViableAltException)e;
|
||||
|
|
|
@ -30,14 +30,11 @@ package org.antlr.v4.runtime;
|
|||
import org.antlr.v4.runtime.misc.LABitSet;
|
||||
|
||||
public class MismatchedSetException extends RecognitionException {
|
||||
public LABitSet expecting;
|
||||
|
||||
/** Used for remote debugger deserialization */
|
||||
public MismatchedSetException() {;}
|
||||
|
||||
public MismatchedSetException(BaseRecognizer recognizer, LABitSet expecting) {
|
||||
super(recognizer);
|
||||
this.expecting = expecting;
|
||||
super(recognizer, expecting);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
|
|
@ -27,18 +27,15 @@
|
|||
*/
|
||||
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 */
|
||||
public class MismatchedTokenException extends RecognitionException {
|
||||
public int expecting = Token.INVALID_TOKEN_TYPE;
|
||||
|
||||
/** Used for remote debugger deserialization */
|
||||
public MismatchedTokenException() {;}
|
||||
|
||||
public MismatchedTokenException(BaseRecognizer recognizer, int expecting) {
|
||||
super(recognizer);
|
||||
this.expecting = expecting;
|
||||
super(recognizer, LABitSet.of(expecting));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
|
|
@ -27,19 +27,18 @@
|
|||
*/
|
||||
package org.antlr.v4.runtime;
|
||||
|
||||
import org.antlr.v4.runtime.misc.LABitSet;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class MismatchedTreeNodeException extends RecognitionException {
|
||||
public int expecting;
|
||||
|
||||
public MismatchedTreeNodeException() {
|
||||
}
|
||||
|
||||
public MismatchedTreeNodeException(BaseRecognizer recognizer,
|
||||
int expecting)
|
||||
{
|
||||
super(recognizer);
|
||||
this.expecting = expecting;
|
||||
super(recognizer, LABitSet.of(expecting));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
|
|
@ -41,7 +41,7 @@ public class MissingTokenException extends MismatchedTokenException {
|
|||
}
|
||||
|
||||
public int getMissingType() {
|
||||
return expecting;
|
||||
return expecting.getSingleElement();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
|
|
@ -28,32 +28,24 @@
|
|||
package org.antlr.v4.runtime;
|
||||
|
||||
import org.antlr.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.misc.LABitSet;
|
||||
|
||||
public class NoViableAltException extends RecognitionException {
|
||||
public String grammarDecisionDescription;
|
||||
public int decisionNumber;
|
||||
public int stateNumber;
|
||||
|
||||
/** Used for remote debugger deserialization */
|
||||
public NoViableAltException() {;}
|
||||
|
||||
public NoViableAltException(BaseRecognizer recognizer,
|
||||
String grammarDecisionDescription,
|
||||
int decisionNumber,
|
||||
int stateNumber)
|
||||
LABitSet expecting)
|
||||
{
|
||||
super(recognizer);
|
||||
this.grammarDecisionDescription = grammarDecisionDescription;
|
||||
this.decisionNumber = decisionNumber;
|
||||
this.stateNumber = stateNumber;
|
||||
super(recognizer, expecting);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if ( recognizer.state.input instanceof CharStream) {
|
||||
return "NoViableAltException('"+(char)getUnexpectedType()+"'@["+grammarDecisionDescription+"])";
|
||||
return "NoViableAltException('"+(char)getUnexpectedType()+", expecting "+expecting+")";
|
||||
}
|
||||
else {
|
||||
return "NoViableAltException("+getUnexpectedType()+"@["+grammarDecisionDescription+"])";
|
||||
return "NoViableAltException('"+getUnexpectedType()+", expecting "+expecting+")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.antlr.runtime.tree.CommonTree;
|
|||
import org.antlr.runtime.tree.Tree;
|
||||
import org.antlr.runtime.tree.TreeAdaptor;
|
||||
import org.antlr.runtime.tree.TreeNodeStream;
|
||||
import org.antlr.v4.runtime.misc.LABitSet;
|
||||
|
||||
/** The root of the ANTLR exception hierarchy.
|
||||
*
|
||||
|
@ -70,8 +71,7 @@ public class RecognitionException extends RuntimeException {
|
|||
/** Who threw the exception? */
|
||||
public BaseRecognizer recognizer;
|
||||
|
||||
/** What input stream did the error occur in? */
|
||||
//public transient IntStream input;
|
||||
public LABitSet expecting;
|
||||
|
||||
/** What is index of token/char were we looking at when the error occurred? */
|
||||
public int index;
|
||||
|
@ -110,7 +110,12 @@ public class RecognitionException extends RuntimeException {
|
|||
}
|
||||
|
||||
public RecognitionException(BaseRecognizer recognizer) {
|
||||
this(recognizer, null);
|
||||
}
|
||||
|
||||
public RecognitionException(BaseRecognizer recognizer, LABitSet expecting) {
|
||||
this.recognizer = recognizer;
|
||||
this.expecting = expecting;
|
||||
IntStream input = recognizer.state.input;
|
||||
this.index = input.index();
|
||||
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) {
|
||||
TreeNodeStream nodes = (TreeNodeStream)input;
|
||||
this.node = nodes.LT(1);
|
||||
|
|
|
@ -44,9 +44,6 @@ public class UnwantedTokenException extends MismatchedTokenException {
|
|||
|
||||
public String toString() {
|
||||
String exp = ", expected "+expecting;
|
||||
if ( expecting==Token.INVALID_TOKEN_TYPE ) {
|
||||
exp = "";
|
||||
}
|
||||
if ( token==null ) {
|
||||
return "UnwantedTokenException(found="+null+exp+")";
|
||||
}
|
||||
|
|
|
@ -43,6 +43,12 @@ public class LABitSet {
|
|||
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) */
|
||||
public void add(int el) {
|
||||
//System.out.println("add("+el+")");
|
||||
|
@ -57,7 +63,7 @@ public class LABitSet {
|
|||
}
|
||||
|
||||
public boolean member(int el) {
|
||||
if ( el == Token.EOF && EOF ) return true;
|
||||
if ( el == Token.EOF ) return EOF;
|
||||
int n = wordNumber(el);
|
||||
if (n >= bits.length) return false;
|
||||
return (bits[n] & bitMask(el)) != 0;
|
||||
|
@ -123,24 +129,35 @@ public class LABitSet {
|
|||
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
|
||||
* separator The string to put in between elements
|
||||
* @return A commma-separated list of values
|
||||
*/
|
||||
public String toString() {
|
||||
System.out.println("toStr");
|
||||
StringBuffer buf = new StringBuffer();
|
||||
String separator = ",";
|
||||
boolean havePrintedAnElement = false;
|
||||
buf.append('{');
|
||||
if ( EOF ) { buf.append("EOF"); havePrintedAnElement=true; }
|
||||
|
||||
for (int i = 0; i < (bits.length << LOG_BITS); i++) {
|
||||
System.out.println("i="+i);
|
||||
if (member(i)) {
|
||||
if (i > 0 && havePrintedAnElement ) {
|
||||
if ( havePrintedAnElement ) {
|
||||
buf.append(separator);
|
||||
}
|
||||
else {
|
||||
buf.append(i);
|
||||
}
|
||||
buf.append(i);
|
||||
havePrintedAnElement = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,6 +80,10 @@ RuleFunction(f,code,decls,context,scope,namedActions,finallyAction) ::= <<
|
|||
try {
|
||||
<code>
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
reportError(re);
|
||||
recover();
|
||||
}
|
||||
finally {
|
||||
<namedActions.after>
|
||||
<f.globalScopesUsed:{s | <s>_stack.pop();}; separator="\n">
|
||||
|
@ -94,45 +98,45 @@ CodeBlock(c, ops) ::= <<
|
|||
<ops; separator="\n">
|
||||
>>
|
||||
|
||||
LL1Choice(choice, alts) ::= <<
|
||||
switch ( input.LA(1) ) {
|
||||
LL1Choice(choice, alts, error) ::= <<
|
||||
switch ( state.input.LA(1) ) {
|
||||
<choice.altLook,alts:{look,alt| <cases(ttypes=look)>
|
||||
<alt>
|
||||
break;}; separator="\n">
|
||||
default :
|
||||
error
|
||||
<error>
|
||||
}
|
||||
>>
|
||||
|
||||
// follow set included as choice by analysis
|
||||
LL1OptionalBlock ::= LL1Choice
|
||||
|
||||
LL1OptionalBlockSingleAlt(choice, expr, alts, preamble) ::= <<
|
||||
LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error) ::= <<
|
||||
<preamble; separator="\n">
|
||||
if ( <expr> ) {
|
||||
<alts; separator="\n">
|
||||
}
|
||||
else {
|
||||
NoViableAltException nvae = new NoViableAltException("", 4, 0, input);
|
||||
<error>
|
||||
}
|
||||
>>
|
||||
|
||||
LL1StarBlock(choice, alts) ::= <<
|
||||
LL1StarBlock(choice, alts, error) ::= <<
|
||||
<choice.loopLabel>:
|
||||
while (true) {
|
||||
switch ( input.LA(1) ) {
|
||||
switch ( state.input.LA(1) ) {
|
||||
<choice.altLook,alts:{look,alt| <cases(ttypes=look)>
|
||||
<alt>
|
||||
break;}; separator="\n">
|
||||
<cases(ttypes=choice.exitLook)>
|
||||
break <choice.loopLabel>;
|
||||
default :
|
||||
error
|
||||
<error>
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
LL1StarBlockSingleAlt(choice, expr, alts, preamble, iteration) ::= <<
|
||||
LL1StarBlockSingleAlt(choice, expr, alts, preamble, iteration, error) ::= <<
|
||||
<preamble; separator="\n">
|
||||
while ( <expr> ) {
|
||||
<alts; separator="\n">
|
||||
|
@ -140,24 +144,26 @@ while ( <expr> ) {
|
|||
}
|
||||
>>
|
||||
|
||||
LL1PlusBlock(choice, alts) ::= <<
|
||||
LL1PlusBlock(choice, alts, error, earlyExitError) ::= <<
|
||||
int <choice.loopCounterVar> = 0;
|
||||
<choice.loopLabel>:
|
||||
while (true) {
|
||||
switch ( input.LA(1) ) {
|
||||
switch ( state.input.LA(1) ) {
|
||||
<choice.altLook,alts:{look,alt| <cases(ttypes=look)>
|
||||
<alt>
|
||||
break;}; separator="\n">
|
||||
<cases(ttypes=choice.exitLook)>
|
||||
if ( <choice.loopCounterVar> >= 1 ) break <choice.loopLabel>;
|
||||
else error
|
||||
else <earlyExitError>
|
||||
default :
|
||||
error
|
||||
<error>
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
LL1PlusBlockSingleAlt(choice, expr, alts, preamble, iteration) ::= <<
|
||||
LL1PlusBlockSingleAlt(choice, expr, alts, preamble, iteration,
|
||||
error, earlyExitError) ::=
|
||||
<<
|
||||
<preamble; separator="\n">
|
||||
do {
|
||||
<alts; separator="\n">
|
||||
|
@ -165,8 +171,11 @@ do {
|
|||
} while ( <expr> );
|
||||
>>
|
||||
|
||||
ThrowNoViableAlt(t) ::= "throw new NoViableAlt(this, <t.expecting.name>);"
|
||||
ThrowEarlyExitException(t) ::= "throw new ThrowEarlyExitException(this, <t.expecting.name>);"
|
||||
|
||||
TestSet(s) ::= <<
|
||||
<s.set.name>.member(input.LA(1))
|
||||
<s.set.name>.member(state.input.LA(1))
|
||||
>>
|
||||
|
||||
TestSetInline(s) ::= <<
|
||||
|
@ -190,7 +199,7 @@ MatchToken(m) ::= <<
|
|||
Action(a, chunks) ::= "<chunks>"
|
||||
|
||||
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>"
|
||||
|
@ -236,7 +245,7 @@ TokenDecl(t) ::= "Token <t.name>;"
|
|||
TokenListDecl(t) ::= "List\<Token> <t.name> = new ArrayList\<Token>();"
|
||||
RuleContextDecl(r) ::= "<r.ctxName> <r.name>;"
|
||||
|
||||
CaptureNextToken(d) ::= "<d.varName> = input.LA(1);"
|
||||
CaptureNextToken(d) ::= "<d.varName> = state.input.LA(1);"
|
||||
|
||||
StructDecl(s,attrs) ::= <<
|
||||
public static class <s.name> extends ParserRuleContext {
|
||||
|
|
|
@ -51,7 +51,7 @@ public class AnalysisPipeline {
|
|||
System.out.println("\nDECISION "+s.decision);
|
||||
|
||||
// TRY LINEAR APPROX FIXED LOOKAHEAD FIRST
|
||||
LinearApproximator lin = new LinearApproximator(g, s.decision);
|
||||
LinearApproximator lin = new LinearApproximator(g);
|
||||
DFA dfa = lin.createDFA(s);
|
||||
|
||||
// IF NOT LINEAR APPROX, TRY NFA TO DFA CONVERSION
|
||||
|
|
|
@ -65,13 +65,13 @@ public class LinearApproximator {
|
|||
*/
|
||||
OrderedHashSet<NFAConfig>[] configs;
|
||||
|
||||
public LinearApproximator(Grammar g, int decision) {
|
||||
public LinearApproximator(Grammar g) {
|
||||
this.g = g;
|
||||
this.decision = decision;
|
||||
}
|
||||
|
||||
public LinearApproximator(Grammar g, int decision, int k) {
|
||||
this(g,decision);
|
||||
public LinearApproximator(Grammar g, int k) {
|
||||
this(g);
|
||||
max_k = k;
|
||||
}
|
||||
|
||||
|
|
|
@ -105,4 +105,11 @@ public abstract class OutputModelFactory {
|
|||
BitSetDecl b = new BitSetDecl(this, name, set);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,18 +11,32 @@ import org.stringtemplate.v4.misc.BlankST;
|
|||
import java.lang.reflect.Field;
|
||||
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 {
|
||||
Tool tool;
|
||||
STGroup templates;
|
||||
//Map<Class, String> modelToTemplateMap;
|
||||
|
||||
public OutputModelWalker(Tool tool,
|
||||
STGroup templates)
|
||||
{
|
||||
this.tool = tool;
|
||||
this.templates = templates;
|
||||
//this.modelToTemplateMap = modelToTemplateMap;
|
||||
}
|
||||
|
||||
public ST walk(OutputModelObject omo) {
|
||||
|
@ -42,28 +56,17 @@ public class OutputModelWalker {
|
|||
return st;
|
||||
}
|
||||
|
||||
List<String> kids = omo.getChildren();
|
||||
|
||||
LinkedHashMap<String,FormalArgument> formalArgs = st.impl.formalArguments;
|
||||
Set<String> argNames = formalArgs.keySet();
|
||||
Iterator<String> it = argNames.iterator();
|
||||
Iterator<String> arg_it = argNames.iterator();
|
||||
|
||||
// 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);
|
||||
|
||||
// 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
|
||||
if ( kids!=null ) for (String fieldName : kids) {
|
||||
if ( !argNames.contains(fieldName) ) continue; // they won't use so don't compute
|
||||
while ( arg_it.hasNext() ) {
|
||||
String fieldName = arg_it.next();
|
||||
//System.out.println("computing ST for field "+fieldName+" of "+omo.getClass());
|
||||
try {
|
||||
Field fi = omo.getClass().getField(fieldName);
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.antlr.v4.codegen.src.actions.ActionChunk;
|
|||
import org.antlr.v4.tool.ActionAST;
|
||||
import org.antlr.v4.tool.GrammarAST;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** */
|
||||
|
@ -20,13 +19,13 @@ public class Action extends SrcOp {
|
|||
System.out.println("actions="+chunks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{
|
||||
if ( sup!=null ) addAll(sup);
|
||||
add("chunks");
|
||||
}};
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{
|
||||
// if ( sup!=null ) addAll(sup);
|
||||
// add("chunks");
|
||||
// }};
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,11 @@ package org.antlr.v4.codegen.src;
|
|||
|
||||
import org.antlr.v4.codegen.OutputModelFactory;
|
||||
import org.antlr.v4.misc.IntervalSet;
|
||||
import org.antlr.v4.runtime.misc.LABitSet;
|
||||
|
||||
/** */
|
||||
public class BitSetDecl extends Decl {
|
||||
public Object fset; // runtime bitset
|
||||
public LABitSet fset; // runtime bitset
|
||||
public BitSetDecl(OutputModelFactory factory, String name, IntervalSet fset) {
|
||||
super(factory, name);
|
||||
this.fset = fset.toRuntimeBitSet();
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package org.antlr.v4.codegen.src;
|
||||
|
||||
import org.antlr.v4.analysis.LinearApproximator;
|
||||
import org.antlr.v4.automata.BlockStartState;
|
||||
import org.antlr.v4.automata.NFAState;
|
||||
import org.antlr.v4.codegen.OutputModelFactory;
|
||||
import org.antlr.v4.misc.IntervalSet;
|
||||
import org.antlr.v4.tool.GrammarAST;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -12,12 +15,20 @@ public abstract class Choice extends SrcOp {
|
|||
public int decision;
|
||||
public List<CodeBlock> alts;
|
||||
public List<SrcOp> preamble;
|
||||
public IntervalSet expecting;
|
||||
public ThrowNoViableAlt error;
|
||||
|
||||
public Choice(OutputModelFactory factory, GrammarAST blkOrEbnfRootAST, List<CodeBlock> alts) {
|
||||
this.factory = factory;
|
||||
this.ast = blkOrEbnfRootAST;
|
||||
super(factory, blkOrEbnfRootAST);
|
||||
this.alts = alts;
|
||||
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) {
|
||||
|
@ -25,9 +36,10 @@ public abstract class Choice extends SrcOp {
|
|||
preamble.add(op);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("alts"); add("preamble"); }};
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup);
|
||||
// add("alts"); add("preamble"); add("error"); }};
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -20,9 +20,9 @@ public class CodeBlock extends SrcOp {
|
|||
this(factory, new ArrayList<SrcOp>() {{ add(elem); }});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("ops"); }};
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("ops"); }};
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class InvokeRule extends SrcOp implements LabeledOp {
|
|||
}
|
||||
|
||||
// compute follow
|
||||
LinearApproximator approx = new LinearApproximator(factory.g, -1);
|
||||
LinearApproximator approx = new LinearApproximator(factory.g);
|
||||
IntervalSet fset = approx.LOOK(ast.nfaState.transition(0).target);
|
||||
System.out.println("follow="+follow);
|
||||
follow = factory.createFollowBitSet(ast, fset);
|
||||
|
|
|
@ -15,6 +15,7 @@ public class LL1Choice extends Choice {
|
|||
public List<String[]> altLook;
|
||||
/** Lookahead for each alt 1..n */
|
||||
public IntervalSet[] altLookSets;
|
||||
|
||||
public LL1Choice(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
|
||||
super(factory, blkAST, alts);
|
||||
DFA dfa = factory.g.decisionDFAs.get(decision);
|
||||
|
|
|
@ -35,12 +35,12 @@ public abstract class LL1Loop extends LL1Choice {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{
|
||||
if ( sup!=null ) addAll(sup); add("expr"); add("iteration");
|
||||
}};
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{
|
||||
// if ( sup!=null ) addAll(sup); add("expr"); add("iteration");
|
||||
// }};
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.antlr.v4.codegen.OutputModelFactory;
|
|||
import org.antlr.v4.misc.IntervalSet;
|
||||
import org.antlr.v4.tool.GrammarAST;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** */
|
||||
|
@ -21,9 +20,9 @@ public class LL1OptionalBlockSingleAlt extends LL1Choice {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("expr"); }};
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("expr"); }};
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ public class LL1PlusBlock extends LL1Loop {
|
|||
public String loopLabel;
|
||||
public String loopCounterVar;
|
||||
public String[] exitLook;
|
||||
public ThrowEarlyExitException earlyExitError;
|
||||
|
||||
public LL1PlusBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
|
||||
super(factory, blkAST, alts);
|
||||
PlusBlockStartState plusStart = (PlusBlockStartState)blkAST.nfaState;
|
||||
|
@ -24,5 +26,15 @@ public class LL1PlusBlock extends LL1Loop {
|
|||
|
||||
loopLabel = factory.gen.target.getLoopLabel(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");
|
||||
// }};
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -8,10 +8,18 @@ import java.util.List;
|
|||
|
||||
/** */
|
||||
public class LL1PlusBlockSingleAlt extends LL1Loop {
|
||||
public ThrowEarlyExitException earlyExitError;
|
||||
public LL1PlusBlockSingleAlt(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
|
||||
super(factory, blkAST, alts);
|
||||
IntervalSet loopBackLook = altLookSets[2]; // loop exit is alt 1
|
||||
addLookaheadTempVar(loopBackLook);
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{
|
||||
// if ( sup!=null ) addAll(sup); add("earlyExitError");
|
||||
// }};
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class MatchToken extends SrcOp implements LabeledOp {
|
|||
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);
|
||||
System.out.println("follow="+fset);
|
||||
follow = factory.createFollowBitSet(ast, fset);
|
||||
|
|
|
@ -3,8 +3,6 @@ package org.antlr.v4.codegen.src;
|
|||
import org.antlr.v4.codegen.OutputModelFactory;
|
||||
import org.antlr.v4.tool.GrammarAST;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** */
|
||||
public abstract class OutputModelObject {
|
||||
public OutputModelFactory factory;
|
||||
|
@ -27,7 +25,7 @@ public abstract class OutputModelObject {
|
|||
* of type OutputModelObject that should be walked to complete model.
|
||||
*/
|
||||
// TODO: make list of Fields to avoid repeated look up
|
||||
public List<String> getChildren() {
|
||||
return null;
|
||||
}
|
||||
// public List<String> getChildren() {
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@ public class Parser extends OutputModelObject {
|
|||
for (Rule r : factory.g.rules.values()) funcs.add( new RuleFunction(factory, r) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("funcs"); add("scopes"); }};
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("funcs"); add("scopes"); }};
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -36,15 +36,15 @@ public class ParserFile extends OutputModelObject {
|
|||
bitSetDecls.add(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{
|
||||
if ( sup!=null ) addAll(sup);
|
||||
add("parser");
|
||||
add("dfaDecls");
|
||||
add("namedActions");
|
||||
add("bitSetDecls");
|
||||
}};
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{
|
||||
// if ( sup!=null ) addAll(sup);
|
||||
// add("parser");
|
||||
// add("dfaDecls");
|
||||
// add("namedActions");
|
||||
// add("bitSetDecls");
|
||||
// }};
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -105,13 +105,13 @@ public class RuleFunction extends OutputModelObject {
|
|||
decls.add(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{
|
||||
if ( sup!=null ) addAll(sup);
|
||||
add("context"); add("scope"); add("decls"); add("code");
|
||||
add("finallyAction"); add("namedActions");
|
||||
}};
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{
|
||||
// if ( sup!=null ) addAll(sup);
|
||||
// add("context"); add("scope"); add("decls"); add("code");
|
||||
// add("finallyAction"); add("namedActions");
|
||||
// }};
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@ public class StructDecl extends Decl {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{
|
||||
if ( sup!=null ) addAll(sup); add("attrs");
|
||||
}};
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{
|
||||
// if ( sup!=null ) addAll(sup); add("attrs");
|
||||
// }};
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package org.antlr.v4.codegen.src.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** */
|
||||
|
@ -11,12 +10,12 @@ public class DynScopeAttrRef_index extends DynScopeAttrRef {
|
|||
this.indexChunks = indexChunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{
|
||||
if ( sup!=null ) addAll(sup);
|
||||
add("indexChunks");
|
||||
}};
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{
|
||||
// if ( sup!=null ) addAll(sup);
|
||||
// add("indexChunks");
|
||||
// }};
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.antlr.v4.codegen.src.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** */
|
||||
|
@ -13,12 +12,12 @@ public class SetAttr extends ActionChunk {
|
|||
this.rhsChunks = rhsChunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{
|
||||
if ( sup!=null ) addAll(sup);
|
||||
add("rhsChunks");
|
||||
}};
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{
|
||||
// if ( sup!=null ) addAll(sup);
|
||||
// add("rhsChunks");
|
||||
// }};
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.antlr.v4.codegen.src.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** */
|
||||
|
@ -14,13 +13,13 @@ public class SetDynScopeAttr extends ActionChunk {
|
|||
this.attr = attr;
|
||||
this.rhsChunks = rhsChunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{
|
||||
if ( sup!=null ) addAll(sup);
|
||||
add("rhsChunks");
|
||||
}};
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{
|
||||
// if ( sup!=null ) addAll(sup);
|
||||
// add("rhsChunks");
|
||||
// }};
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.antlr.v4.codegen.src.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** */
|
||||
|
@ -11,12 +10,12 @@ public class SetDynScopeAttr_index extends SetDynScopeAttr {
|
|||
this.indexChunks = indexChunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{
|
||||
if ( sup!=null ) addAll(sup);
|
||||
add("indexChunks");
|
||||
}};
|
||||
}
|
||||
// @Override
|
||||
// public List<String> getChildren() {
|
||||
// final List<String> sup = super.getChildren();
|
||||
// return new ArrayList<String>() {{
|
||||
// if ( sup!=null ) addAll(sup);
|
||||
// add("indexChunks");
|
||||
// }};
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -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"]
|
||||
|
@ -264,7 +264,7 @@ public class ANTLRLexer extends Lexer {
|
|||
if ( (( input.LA(2) != '/')) ) {
|
||||
alt3=1;
|
||||
}
|
||||
else if ( ((( true )||(( true )&&( !(input.LA(1) == '*' && input.LA(2) == '/') )))) ) {
|
||||
else if ( (((( true )&&( !(input.LA(1) == '*' && input.LA(2) == '/') ))||( true ))) ) {
|
||||
alt3=2;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -567,11 +567,11 @@ element
|
|||
}
|
||||
@after { paraphrases.pop(); }
|
||||
: labeledElement
|
||||
( ebnfSuffix -> ^( ebnfSuffix ^(BLOCK<BlockAST>[$labeledElement.start,"BLOCK"] ^(ALT labeledElement ) ))
|
||||
( ebnfSuffix -> ^( ebnfSuffix ^(BLOCK<BlockAST>[$labeledElement.start,"BLOCK"] ^(ALT<AltAST> labeledElement ) ))
|
||||
| -> labeledElement
|
||||
)
|
||||
| atom
|
||||
( ebnfSuffix -> ^( ebnfSuffix ^(BLOCK<BlockAST>[$atom.start,"BLOCK"] ^(ALT atom) ) )
|
||||
( ebnfSuffix -> ^( ebnfSuffix ^(BLOCK<BlockAST>[$atom.start,"BLOCK"] ^(ALT<AltAST> atom) ) )
|
||||
| -> atom
|
||||
)
|
||||
| ebnf
|
||||
|
@ -581,7 +581,7 @@ element
|
|||
| -> SEMPRED
|
||||
)
|
||||
| treeSpec
|
||||
( ebnfSuffix -> ^( ebnfSuffix ^(BLOCK<BlockAST>[$treeSpec.start,"BLOCK"] ^(ALT treeSpec ) ) )
|
||||
( ebnfSuffix -> ^( ebnfSuffix ^(BLOCK<BlockAST>[$treeSpec.start,"BLOCK"] ^(ALT<AltAST> treeSpec ) ) )
|
||||
| -> treeSpec
|
||||
)
|
||||
;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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"]
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -2399,11 +2399,11 @@ public class ActionSplitter extends Lexer {
|
|||
state.failed=false;
|
||||
return success;
|
||||
}
|
||||
public final boolean synpred15_ActionSplitter() {
|
||||
public final boolean synpred3_ActionSplitter() {
|
||||
state.backtracking++;
|
||||
int start = input.mark();
|
||||
try {
|
||||
synpred15_ActionSplitter_fragment(); // can never throw exception
|
||||
synpred3_ActionSplitter_fragment(); // can never throw exception
|
||||
} catch (RecognitionException re) {
|
||||
System.err.println("impossible: "+re);
|
||||
}
|
||||
|
@ -2413,11 +2413,11 @@ public class ActionSplitter extends Lexer {
|
|||
state.failed=false;
|
||||
return success;
|
||||
}
|
||||
public final boolean synpred3_ActionSplitter() {
|
||||
public final boolean synpred15_ActionSplitter() {
|
||||
state.backtracking++;
|
||||
int start = input.mark();
|
||||
try {
|
||||
synpred3_ActionSplitter_fragment(); // can never throw exception
|
||||
synpred15_ActionSplitter_fragment(); // can never throw exception
|
||||
} catch (RecognitionException re) {
|
||||
System.err.println("impossible: "+re);
|
||||
}
|
||||
|
@ -2495,20 +2495,23 @@ public class ActionSplitter extends Lexer {
|
|||
static final String DFA29_eofS =
|
||||
"\32\uffff";
|
||||
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 =
|
||||
"\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 =
|
||||
"\2\uffff\1\16\1\17\1\20\1\21\1\22\1\23\1\uffff\1\3\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"+
|
||||
"\24";
|
||||
"\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";
|
||||
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 = {
|
||||
"\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",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
|
@ -2519,10 +2522,6 @@ public class ActionSplitter extends Lexer {
|
|||
"\1\uffff",
|
||||
"",
|
||||
"",
|
||||
"\1\uffff",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
|
@ -2573,15 +2572,15 @@ public class ActionSplitter extends Lexer {
|
|||
int LA29_0 = input.LA(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;
|
||||
break;
|
||||
|
@ -2592,83 +2591,83 @@ public class ActionSplitter extends Lexer {
|
|||
int index29_1 = input.index();
|
||||
input.rewind();
|
||||
s = -1;
|
||||
if ( (synpred14_ActionSplitter()) ) {s = 2;}
|
||||
if ( (synpred3_ActionSplitter()) ) {s = 2;}
|
||||
|
||||
else if ( (synpred15_ActionSplitter()) ) {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;}
|
||||
else if ( (true) ) {s = 3;}
|
||||
|
||||
|
||||
input.seek(index29_1);
|
||||
if ( s>=0 ) return s;
|
||||
break;
|
||||
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();
|
||||
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;
|
||||
break;
|
||||
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();
|
||||
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;
|
||||
break;
|
||||
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();
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -102,7 +102,7 @@ public class TestLinearApproximateLookahead extends BaseTest {
|
|||
return;
|
||||
}
|
||||
DecisionState blk = (DecisionState)s.transition(0).target;
|
||||
LinearApproximator lin = new LinearApproximator(g, blk.decision);
|
||||
LinearApproximator lin = new LinearApproximator(g);
|
||||
DFA dfa = lin.createDFA(blk);
|
||||
String result = null;
|
||||
if ( dfa!=null ) result = dfa.toString();
|
||||
|
|
Loading…
Reference in New Issue