hacking with Oliver Z. Lots of fixes to code gen and sync/error handling/mode stuff.

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6894]
This commit is contained in:
parrt 2010-05-25 15:54:31 -08:00
parent 38ef035c06
commit ca8ea6feea
22 changed files with 213 additions and 151 deletions

View File

@ -119,6 +119,7 @@ public abstract class BaseRecognizer {
// like matchSet but w/o consume; error checking routine. // like matchSet but w/o consume; error checking routine.
public void sync(LABitSet expecting) { public void sync(LABitSet expecting) {
if ( expecting.member(state.input.LA(1)) ) return; if ( expecting.member(state.input.LA(1)) ) return;
System.out.println("failed sync to "+expecting);
LABitSet followSet = computeErrorRecoverySet(); LABitSet followSet = computeErrorRecoverySet();
followSet.orInPlace(expecting); followSet.orInPlace(expecting);
NoViableAltException e = new NoViableAltException(this, followSet); NoViableAltException e = new NoViableAltException(this, followSet);

View File

@ -40,6 +40,8 @@ import org.antlr.v4.runtime.pda.PDA;
*/ */
public abstract class Lexer /* extends BaseRecognizer */ implements TokenSource { public abstract class Lexer /* extends BaseRecognizer */ implements TokenSource {
public static final int DEFAULT_MODE = 0; public static final int DEFAULT_MODE = 0;
public static final int MORE = -2;
public static final int SKIP = -3;
public LexerSharedState state; public LexerSharedState state;
@ -80,6 +82,7 @@ public abstract class Lexer /* extends BaseRecognizer */ implements TokenSource
* stream. * stream.
*/ */
public Token nextToken() { public Token nextToken() {
outer:
while (true) { while (true) {
state.token = null; state.token = null;
state.channel = Token.DEFAULT_CHANNEL; state.channel = Token.DEFAULT_CHANNEL;
@ -87,6 +90,8 @@ public abstract class Lexer /* extends BaseRecognizer */ implements TokenSource
state.tokenStartCharPositionInLine = ((CharStream)state.input).getCharPositionInLine(); state.tokenStartCharPositionInLine = ((CharStream)state.input).getCharPositionInLine();
state.tokenStartLine = ((CharStream)state.input).getLine(); state.tokenStartLine = ((CharStream)state.input).getLine();
state.text = null; state.text = null;
do {
state.type = Token.INVALID_TOKEN_TYPE;
if ( state.input.LA(1)==CharStream.EOF ) { if ( state.input.LA(1)==CharStream.EOF ) {
Token eof = new CommonToken((CharStream)state.input,Token.EOF, Token eof = new CommonToken((CharStream)state.input,Token.EOF,
Token.DEFAULT_CHANNEL, Token.DEFAULT_CHANNEL,
@ -95,16 +100,17 @@ public abstract class Lexer /* extends BaseRecognizer */ implements TokenSource
eof.setCharPositionInLine(getCharPositionInLine()); eof.setCharPositionInLine(getCharPositionInLine());
return eof; return eof;
} }
{ int ttype = modeToPDA[_mode].execThompson(state.input);
state.type = modeToPDA[_mode].execThompson(state.input); if ( state.type == Token.INVALID_TOKEN_TYPE ) state.type = ttype;
if ( state.token==null ) { if ( state.type==SKIP ) {
continue outer;
}
// if ( state.token==null ) {
// emit();
// }
} while ( state.type==MORE );
emit(); emit();
}
else if ( state.token==Token.SKIP_TOKEN ) {
continue;
}
return state.token; return state.token;
}
// catch (NoViableAltException nva) { // catch (NoViableAltException nva) {
// reportError(nva); // reportError(nva);
// recover(nva); // throw out current char and try again // recover(nva); // throw out current char and try again

View File

@ -147,7 +147,6 @@ public class LABitSet implements Cloneable {
* @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;
@ -155,7 +154,6 @@ public class LABitSet implements Cloneable {
if ( EOF ) { buf.append("EOF"); havePrintedAnElement=true; } 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 ( havePrintedAnElement ) { if ( havePrintedAnElement ) {
buf.append(separator); buf.append(separator);

View File

@ -186,7 +186,7 @@ processOneChar:
input.consume(); input.consume();
} }
else if ( !accepted ) { else if ( !accepted ) {
System.out.println("!!!!! no match for char "+(char)c+" at "+input.index()); System.err.println("!!!!! no match for char "+(char)c+" at "+input.index());
input.consume(); input.consume();
} }
// else reach.size==0 && matched, don't consume: accepted // else reach.size==0 && matched, don't consume: accepted

View File

@ -15,7 +15,9 @@ javaTypeInitMap ::= [
ParserFile(file, parser, dfaDecls, bitSetDecls, namedActions) ::= << ParserFile(file, parser, dfaDecls, bitSetDecls, namedActions) ::= <<
// $ANTLR ANTLRVersion> <file.fileName> generatedTimestamp> // $ANTLR ANTLRVersion> <file.fileName> generatedTimestamp>
<namedActions.header> <namedActions.header>
import org.antlr.v4.runtime.NoViableAltException;
import org.antlr.v4.runtime.Parser; import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.EarlyExitException;
import org.antlr.v4.runtime.RecognizerSharedState; import org.antlr.v4.runtime.RecognizerSharedState;
import org.antlr.v4.runtime.RecognitionException; import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.ParserRuleContext;
@ -116,14 +118,12 @@ switch ( state.input.LA(1) ) {
// follow set included as choice by analysis // follow set included as choice by analysis
LL1OptionalBlock ::= LL1Choice LL1OptionalBlock ::= LL1Choice
LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error) ::= << LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error, followExpr) ::= <<
<preamble; separator="\n"> <preamble; separator="\n">
if ( <expr> ) { if ( <expr> ) {
<alts; separator="\n"> <alts; separator="\n">
} }
else { else if ( !(<followExpr>) ) <error>
<error>
}
>> >>
LL1StarBlock(choice, alts, sync) ::= << LL1StarBlock(choice, alts, sync) ::= <<
@ -149,7 +149,7 @@ while ( <expr> ) {
} }
>> >>
LL1PlusBlock(choice, alts, earlyExitError, sync) ::= << LL1PlusBlock(choice, alts, earlyExitError, sync, iterationSync) ::= <<
<sync> <sync>
int <choice.loopCounterVar> = 0; int <choice.loopCounterVar> = 0;
<choice.loopLabel>: <choice.loopLabel>:
@ -162,7 +162,8 @@ while (true) {
if ( <choice.loopCounterVar> >= 1 ) break <choice.loopLabel>; if ( <choice.loopCounterVar> >= 1 ) break <choice.loopLabel>;
else <earlyExitError> else <earlyExitError>
} }
<sync> <choice.loopCounterVar>++;
<iterationSync>
} }
>> >>
@ -180,8 +181,8 @@ do {
Sync(s) ::= "sync(<s.expecting.name>);" Sync(s) ::= "sync(<s.expecting.name>);"
ThrowNoViableAlt(t) ::= "throw new NoViableAlt(this, <t.expecting.name>);" ThrowNoViableAlt(t) ::= "throw new NoViableAltException(this, <t.expecting.name>);"
ThrowEarlyExitException(t) ::= "throw new ThrowEarlyExitException(this, <t.expecting.name>);" ThrowEarlyExitException(t) ::= "throw new EarlyExitException(this, <t.expecting.name>);"
TestSet(s) ::= << TestSet(s) ::= <<
<s.set.name>.member(state.input.LA(1)) <s.set.name>.member(state.input.LA(1))
@ -333,18 +334,18 @@ public static final int[] <name>_tokenTypeToAddr = {
public final class <name>_PDA extends PDA { public final class <name>_PDA extends PDA {
<if(actions)> <if(actions)>
public void action(int r, int a) { public void action(int r, int a) {
<actions:{a |
switch ( r ) { switch ( r ) {
case <i0> : <a.name>_actions(a); break; <actions:{a |
case <a.ruleIndex> : <a.name>_actions(a); break;
}> }>
} }
} }
<endif> <endif>
<if(sempreds)> <if(sempreds)>
public void sempred(int r, int a) { public void sempred(int r, int a) {
<sempreds:{p |
switch ( r ) { switch ( r ) {
case <i0> : return <p.name>_sempreds(a); <sempreds:{p |
case <p.ruleIndex> : return <p.name>_sempreds(a);
}> }>
} }
} }
@ -355,7 +356,7 @@ public final class <name>_PDA extends PDA {
}<\n> }<\n>
>> >>
actionMethod(name, actions) ::= << actionMethod(name, actions, ruleIndex) ::= <<
public void <name>_actions(int action) { public void <name>_actions(int action) {
switch ( action ) { switch ( action ) {
<actions:{a | <actions:{a |

View File

@ -33,6 +33,7 @@ public class LexerFactory {
actionST.add("name", r.name); actionST.add("name", r.name);
for (Token t : actionTokens) { for (Token t : actionTokens) {
actionST.add("actions", Misc.strip(t.getText(),1)); actionST.add("actions", Misc.strip(t.getText(),1));
actionST.add("ruleIndex", r.index);
} }
pdaST.add("actions", actionST); pdaST.add("actions", actionST);
lexerST.add("actions", actionST); lexerST.add("actions", actionST);
@ -41,6 +42,7 @@ public class LexerFactory {
Set<Token> sempredTokens = pda.ruleSempreds.keySet(r); Set<Token> sempredTokens = pda.ruleSempreds.keySet(r);
ST sempredST = gen.templates.getInstanceOf("sempredMethod"); ST sempredST = gen.templates.getInstanceOf("sempredMethod");
sempredST.add("name", r.name); sempredST.add("name", r.name);
sempredST.add("ruleIndex", r.index);
for (Token t : sempredTokens) { for (Token t : sempredTokens) {
sempredST.add("preds", t.getText()); sempredST.add("preds", t.getText());
} }

View File

@ -99,9 +99,10 @@ public abstract class OutputModelFactory {
return b; return b;
} }
public BitSetDecl createExpectingBitSet(GrammarAST ast, int decision, IntervalSet set) { public BitSetDecl createExpectingBitSet(GrammarAST ast, int decision, IntervalSet set, String position) {
String inRuleName = ast.nfaState.rule.name; String inRuleName = ast.nfaState.rule.name;
String name = "EXPECTING_in_"+inRuleName+"_"+decision; String name = "EXPECTING_in_"+inRuleName+"_"+position+"_"+decision;
//System.out.println("!!!!!!!! create "+name);
BitSetDecl b = new BitSetDecl(this, name, set); BitSetDecl b = new BitSetDecl(this, name, set);
return b; return b;
} }

View File

@ -6,11 +6,13 @@ import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.antlr.runtime.tree.TreeNodeStream; import org.antlr.runtime.tree.TreeNodeStream;
import org.antlr.v4.codegen.pda.*; import org.antlr.v4.codegen.pda.*;
import org.antlr.v4.misc.CharSupport; import org.antlr.v4.misc.CharSupport;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.parse.ANTLRParser; import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.parse.GrammarASTAdaptor; import org.antlr.v4.parse.GrammarASTAdaptor;
import org.antlr.v4.runtime.pda.Bytecode; import org.antlr.v4.runtime.pda.Bytecode;
import org.antlr.v4.runtime.pda.PDA; import org.antlr.v4.runtime.pda.PDA;
import org.antlr.v4.runtime.tree.TreeParser; import org.antlr.v4.runtime.tree.TreeParser;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.GrammarAST; import org.antlr.v4.tool.GrammarAST;
import org.antlr.v4.tool.LexerGrammar; import org.antlr.v4.tool.LexerGrammar;
import org.antlr.v4.tool.Rule; import org.antlr.v4.tool.Rule;
@ -19,6 +21,8 @@ import java.util.Map;
/** http://swtch.com/~rsc/regexp/regexp2.html */ /** http://swtch.com/~rsc/regexp/regexp2.html */
public class PDABytecodeGenerator extends TreeParser { public class PDABytecodeGenerator extends TreeParser {
public Grammar g;
public Rule currentRule; public Rule currentRule;
CompiledPDA pda = new CompiledPDA(); CompiledPDA pda = new CompiledPDA();
@ -71,13 +75,39 @@ public class PDABytecodeGenerator extends TreeParser {
return i; return i;
} }
public void emitString(Token t) { public void emitString(Token t, boolean not) {
String chars = CharSupport.getStringFromGrammarStringLiteral(t.getText()); String chars = CharSupport.getStringFromGrammarStringLiteral(t.getText());
if ( not && chars.length()==1 ) {
emitNotChar(t, chars);
return;
}
for (char c : chars.toCharArray()) { for (char c : chars.toCharArray()) {
emit(new MatchInstr(t, c)); emit(new MatchInstr(t, c));
} }
} }
public void emitNotChar(Token t, String chars) {
IntervalSet all = (IntervalSet)g.getTokenTypes();
int c = chars.charAt(0);
SplitInstr s = new SplitInstr(2);
RangeInstr left = new RangeInstr(t, t);
left.a = all.getMinElement();
left.b = c-1;
RangeInstr right = new RangeInstr(t, t);
right.a = c+1;
right.b = 127; // all.getMaxElement();
emit(s);
emit(left);
JumpInstr J = new JumpInstr();
emit(J);
emit(right);
s.addrs.add(left.addr);
s.addrs.add(right.addr);
int END = pda.ip;
J.target = END;
return;
}
public byte[] convertInstrsToBytecode() { public byte[] convertInstrsToBytecode() {
Instr last = pda.instrs.get(pda.instrs.size() - 1); Instr last = pda.instrs.get(pda.instrs.size() - 1);
int size = last.addr + last.nBytes(); int size = last.addr + last.nBytes();
@ -100,6 +130,7 @@ public class PDABytecodeGenerator extends TreeParser {
public static CompiledPDA compileLexerMode(LexerGrammar lg, String modeName) { public static CompiledPDA compileLexerMode(LexerGrammar lg, String modeName) {
GrammarASTAdaptor adaptor = new GrammarASTAdaptor(); GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
PDABytecodeTriggers gen = new PDABytecodeTriggers(null); PDABytecodeTriggers gen = new PDABytecodeTriggers(null);
gen.g = lg;
gen.pda.tokenTypeToAddr = new int[lg.getMaxTokenType()+1]; gen.pda.tokenTypeToAddr = new int[lg.getMaxTokenType()+1];
// add split for s0 to hook up rules (fill in operands as we gen rules) // add split for s0 to hook up rules (fill in operands as we gen rules)

View File

@ -133,16 +133,16 @@ atom
| ^(BANG notSet) | ^(BANG notSet)
| notSet | notSet
| range | range
| ^(DOT ID terminal) | ^(DOT ID terminal[false])
| ^(DOT ID ruleref) | ^(DOT ID ruleref)
| ^(WILDCARD .) {emit(new WildcardInstr($WILDCARD.token));} | ^(WILDCARD .) {emit(new WildcardInstr($WILDCARD.token));}
| WILDCARD {emit(new WildcardInstr($WILDCARD.token));} | WILDCARD {emit(new WildcardInstr($WILDCARD.token));}
| terminal | terminal[false]
| ruleref | ruleref
; ;
notSet notSet
: ^(NOT terminal) : ^(NOT terminal[true])
| ^(NOT block) | ^(NOT block)
; ;
@ -157,12 +157,12 @@ range
{emit(new RangeInstr($a.token, $b.token));} {emit(new RangeInstr($a.token, $b.token));}
; ;
terminal terminal[boolean not]
: ^(STRING_LITERAL .) {emitString($STRING_LITERAL.token);} : ^(STRING_LITERAL .) {emitString($STRING_LITERAL.token, $not);}
| STRING_LITERAL {emitString($STRING_LITERAL.token);} | STRING_LITERAL {emitString($STRING_LITERAL.token, $not);}
| ^(TOKEN_REF ARG_ACTION .) {emit(new CallInstr($TOKEN_REF.token));} | ^(TOKEN_REF ARG_ACTION .) {emit(new CallInstr($TOKEN_REF.token));}
| ^(TOKEN_REF .) {emit(new CallInstr($TOKEN_REF.token));} | ^(TOKEN_REF .) {emit(new CallInstr($TOKEN_REF.token));}
| TOKEN_REF {emit(new CallInstr($TOKEN_REF.token));} | TOKEN_REF {emit(new CallInstr($TOKEN_REF.token));}
| ^(ROOT terminal) | ^(ROOT terminal[false])
| ^(BANG terminal) | ^(BANG terminal[false])
; ;

View File

@ -1,4 +1,4 @@
// $ANTLR ${project.version} ${buildNumber} PDABytecodeTriggers.g 2010-05-17 12:41:45 // $ANTLR 3.2.1-SNAPSHOT May 24, 2010 15:02:05 PDABytecodeTriggers.g 2010-05-25 13:12:36
package org.antlr.v4.codegen; package org.antlr.v4.codegen;
@ -872,13 +872,13 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
// $ANTLR start "atom" // $ANTLR start "atom"
// PDABytecodeTriggers.g:129:1: atom : ( ^( ROOT range ) | ^( BANG range ) | ^( ROOT notSet ) | ^( BANG notSet ) | notSet | range | ^( DOT ID terminal ) | ^( DOT ID ruleref ) | ^( WILDCARD . ) | WILDCARD | terminal | ruleref ); // PDABytecodeTriggers.g:129:1: atom : ( ^( ROOT range ) | ^( BANG range ) | ^( ROOT notSet ) | ^( BANG notSet ) | notSet | range | ^( DOT ID terminal[false] ) | ^( DOT ID ruleref ) | ^( WILDCARD . ) | WILDCARD | terminal[false] | ruleref );
public final void atom() throws RecognitionException { public final void atom() throws RecognitionException {
GrammarAST WILDCARD5=null; GrammarAST WILDCARD5=null;
GrammarAST WILDCARD6=null; GrammarAST WILDCARD6=null;
try { try {
// PDABytecodeTriggers.g:130:2: ( ^( ROOT range ) | ^( BANG range ) | ^( ROOT notSet ) | ^( BANG notSet ) | notSet | range | ^( DOT ID terminal ) | ^( DOT ID ruleref ) | ^( WILDCARD . ) | WILDCARD | terminal | ruleref ) // PDABytecodeTriggers.g:130:2: ( ^( ROOT range ) | ^( BANG range ) | ^( ROOT notSet ) | ^( BANG notSet ) | notSet | range | ^( DOT ID terminal[false] ) | ^( DOT ID ruleref ) | ^( WILDCARD . ) | WILDCARD | terminal[false] | ruleref )
int alt10=12; int alt10=12;
alt10 = dfa10.predict(input); alt10 = dfa10.predict(input);
switch (alt10) { switch (alt10) {
@ -969,14 +969,14 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
} }
break; break;
case 7 : case 7 :
// PDABytecodeTriggers.g:136:4: ^( DOT ID terminal ) // PDABytecodeTriggers.g:136:4: ^( DOT ID terminal[false] )
{ {
match(input,DOT,FOLLOW_DOT_in_atom586); match(input,DOT,FOLLOW_DOT_in_atom586);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
match(input,ID,FOLLOW_ID_in_atom588); match(input,ID,FOLLOW_ID_in_atom588);
pushFollow(FOLLOW_terminal_in_atom590); pushFollow(FOLLOW_terminal_in_atom590);
terminal(); terminal(false);
state._fsp--; state._fsp--;
@ -988,11 +988,11 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 8 : case 8 :
// PDABytecodeTriggers.g:137:4: ^( DOT ID ruleref ) // PDABytecodeTriggers.g:137:4: ^( DOT ID ruleref )
{ {
match(input,DOT,FOLLOW_DOT_in_atom599); match(input,DOT,FOLLOW_DOT_in_atom600);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
match(input,ID,FOLLOW_ID_in_atom601); match(input,ID,FOLLOW_ID_in_atom602);
pushFollow(FOLLOW_ruleref_in_atom603); pushFollow(FOLLOW_ruleref_in_atom604);
ruleref(); ruleref();
state._fsp--; state._fsp--;
@ -1005,7 +1005,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 9 : case 9 :
// PDABytecodeTriggers.g:138:7: ^( WILDCARD . ) // PDABytecodeTriggers.g:138:7: ^( WILDCARD . )
{ {
WILDCARD5=(GrammarAST)match(input,WILDCARD,FOLLOW_WILDCARD_in_atom615); WILDCARD5=(GrammarAST)match(input,WILDCARD,FOLLOW_WILDCARD_in_atom616);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
matchAny(input); matchAny(input);
@ -1018,16 +1018,16 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 10 : case 10 :
// PDABytecodeTriggers.g:139:7: WILDCARD // PDABytecodeTriggers.g:139:7: WILDCARD
{ {
WILDCARD6=(GrammarAST)match(input,WILDCARD,FOLLOW_WILDCARD_in_atom631); WILDCARD6=(GrammarAST)match(input,WILDCARD,FOLLOW_WILDCARD_in_atom632);
emit(new WildcardInstr(WILDCARD6.token)); emit(new WildcardInstr(WILDCARD6.token));
} }
break; break;
case 11 : case 11 :
// PDABytecodeTriggers.g:140:9: terminal // PDABytecodeTriggers.g:140:9: terminal[false]
{ {
pushFollow(FOLLOW_terminal_in_atom646); pushFollow(FOLLOW_terminal_in_atom647);
terminal(); terminal(false);
state._fsp--; state._fsp--;
@ -1037,7 +1037,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 12 : case 12 :
// PDABytecodeTriggers.g:141:9: ruleref // PDABytecodeTriggers.g:141:9: ruleref
{ {
pushFollow(FOLLOW_ruleref_in_atom660); pushFollow(FOLLOW_ruleref_in_atom662);
ruleref(); ruleref();
state._fsp--; state._fsp--;
@ -1060,10 +1060,10 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
// $ANTLR start "notSet" // $ANTLR start "notSet"
// PDABytecodeTriggers.g:144:1: notSet : ( ^( NOT terminal ) | ^( NOT block ) ); // PDABytecodeTriggers.g:144:1: notSet : ( ^( NOT terminal[true] ) | ^( NOT block ) );
public final void notSet() throws RecognitionException { public final void notSet() throws RecognitionException {
try { try {
// PDABytecodeTriggers.g:145:5: ( ^( NOT terminal ) | ^( NOT block ) ) // PDABytecodeTriggers.g:145:5: ( ^( NOT terminal[true] ) | ^( NOT block ) )
int alt11=2; int alt11=2;
int LA11_0 = input.LA(1); int LA11_0 = input.LA(1);
@ -1101,13 +1101,13 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
} }
switch (alt11) { switch (alt11) {
case 1 : case 1 :
// PDABytecodeTriggers.g:145:7: ^( NOT terminal ) // PDABytecodeTriggers.g:145:7: ^( NOT terminal[true] )
{ {
match(input,NOT,FOLLOW_NOT_in_notSet683); match(input,NOT,FOLLOW_NOT_in_notSet685);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
pushFollow(FOLLOW_terminal_in_notSet685); pushFollow(FOLLOW_terminal_in_notSet687);
terminal(); terminal(true);
state._fsp--; state._fsp--;
@ -1119,10 +1119,10 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 2 : case 2 :
// PDABytecodeTriggers.g:146:7: ^( NOT block ) // PDABytecodeTriggers.g:146:7: ^( NOT block )
{ {
match(input,NOT,FOLLOW_NOT_in_notSet697); match(input,NOT,FOLLOW_NOT_in_notSet698);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
pushFollow(FOLLOW_block_in_notSet699); pushFollow(FOLLOW_block_in_notSet700);
block(); block();
state._fsp--; state._fsp--;
@ -1179,10 +1179,10 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 1 : case 1 :
// PDABytecodeTriggers.g:150:7: ^( ROOT ^( RULE_REF ( ARG_ACTION )? ) ) // PDABytecodeTriggers.g:150:7: ^( ROOT ^( RULE_REF ( ARG_ACTION )? ) )
{ {
match(input,ROOT,FOLLOW_ROOT_in_ruleref721); match(input,ROOT,FOLLOW_ROOT_in_ruleref722);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref724); match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref725);
if ( input.LA(1)==Token.DOWN ) { if ( input.LA(1)==Token.DOWN ) {
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
@ -1197,7 +1197,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 1 : case 1 :
// PDABytecodeTriggers.g:150:25: ARG_ACTION // PDABytecodeTriggers.g:150:25: ARG_ACTION
{ {
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref726); match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref727);
} }
break; break;
@ -1215,10 +1215,10 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 2 : case 2 :
// PDABytecodeTriggers.g:151:7: ^( BANG ^( RULE_REF ( ARG_ACTION )? ) ) // PDABytecodeTriggers.g:151:7: ^( BANG ^( RULE_REF ( ARG_ACTION )? ) )
{ {
match(input,BANG,FOLLOW_BANG_in_ruleref739); match(input,BANG,FOLLOW_BANG_in_ruleref740);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref742); match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref743);
if ( input.LA(1)==Token.DOWN ) { if ( input.LA(1)==Token.DOWN ) {
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
@ -1233,7 +1233,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 1 : case 1 :
// PDABytecodeTriggers.g:151:25: ARG_ACTION // PDABytecodeTriggers.g:151:25: ARG_ACTION
{ {
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref744); match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref745);
} }
break; break;
@ -1251,7 +1251,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 3 : case 3 :
// PDABytecodeTriggers.g:152:7: ^( RULE_REF ( ARG_ACTION )? ) // PDABytecodeTriggers.g:152:7: ^( RULE_REF ( ARG_ACTION )? )
{ {
match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref757); match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref758);
if ( input.LA(1)==Token.DOWN ) { if ( input.LA(1)==Token.DOWN ) {
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
@ -1266,7 +1266,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 1 : case 1 :
// PDABytecodeTriggers.g:152:18: ARG_ACTION // PDABytecodeTriggers.g:152:18: ARG_ACTION
{ {
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref759); match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref760);
} }
break; break;
@ -1303,11 +1303,11 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
// PDABytecodeTriggers.g:156:5: ( ^( RANGE a= STRING_LITERAL b= STRING_LITERAL ) ) // PDABytecodeTriggers.g:156:5: ( ^( RANGE a= STRING_LITERAL b= STRING_LITERAL ) )
// PDABytecodeTriggers.g:156:7: ^( RANGE a= STRING_LITERAL b= STRING_LITERAL ) // PDABytecodeTriggers.g:156:7: ^( RANGE a= STRING_LITERAL b= STRING_LITERAL )
{ {
match(input,RANGE,FOLLOW_RANGE_in_range782); match(input,RANGE,FOLLOW_RANGE_in_range783);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
a=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range786); a=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range787);
b=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range790); b=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range791);
match(input, Token.UP, null); match(input, Token.UP, null);
emit(new RangeInstr(a.token, b.token)); emit(new RangeInstr(a.token, b.token));
@ -1327,8 +1327,8 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
// $ANTLR start "terminal" // $ANTLR start "terminal"
// PDABytecodeTriggers.g:160:1: terminal : ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal ) | ^( BANG terminal ) ); // PDABytecodeTriggers.g:160:1: terminal[boolean not] : ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal[false] ) | ^( BANG terminal[false] ) );
public final void terminal() throws RecognitionException { public final void terminal(boolean not) throws RecognitionException {
GrammarAST STRING_LITERAL7=null; GrammarAST STRING_LITERAL7=null;
GrammarAST STRING_LITERAL8=null; GrammarAST STRING_LITERAL8=null;
GrammarAST TOKEN_REF9=null; GrammarAST TOKEN_REF9=null;
@ -1336,38 +1336,38 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
GrammarAST TOKEN_REF11=null; GrammarAST TOKEN_REF11=null;
try { try {
// PDABytecodeTriggers.g:161:5: ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal ) | ^( BANG terminal ) ) // PDABytecodeTriggers.g:161:5: ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal[false] ) | ^( BANG terminal[false] ) )
int alt16=7; int alt16=7;
alt16 = dfa16.predict(input); alt16 = dfa16.predict(input);
switch (alt16) { switch (alt16) {
case 1 : case 1 :
// PDABytecodeTriggers.g:161:8: ^( STRING_LITERAL . ) // PDABytecodeTriggers.g:161:8: ^( STRING_LITERAL . )
{ {
STRING_LITERAL7=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal817); STRING_LITERAL7=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal819);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
matchAny(input); matchAny(input);
match(input, Token.UP, null); match(input, Token.UP, null);
emitString(STRING_LITERAL7.token); emitString(STRING_LITERAL7.token, not);
} }
break; break;
case 2 : case 2 :
// PDABytecodeTriggers.g:162:7: STRING_LITERAL // PDABytecodeTriggers.g:162:7: STRING_LITERAL
{ {
STRING_LITERAL8=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal832); STRING_LITERAL8=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal834);
emitString(STRING_LITERAL8.token); emitString(STRING_LITERAL8.token, not);
} }
break; break;
case 3 : case 3 :
// PDABytecodeTriggers.g:163:7: ^( TOKEN_REF ARG_ACTION . ) // PDABytecodeTriggers.g:163:7: ^( TOKEN_REF ARG_ACTION . )
{ {
TOKEN_REF9=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal846); TOKEN_REF9=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal848);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_terminal848); match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_terminal850);
matchAny(input); matchAny(input);
match(input, Token.UP, null); match(input, Token.UP, null);
@ -1378,7 +1378,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 4 : case 4 :
// PDABytecodeTriggers.g:164:7: ^( TOKEN_REF . ) // PDABytecodeTriggers.g:164:7: ^( TOKEN_REF . )
{ {
TOKEN_REF10=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal862); TOKEN_REF10=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal864);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
matchAny(input); matchAny(input);
@ -1391,19 +1391,19 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
case 5 : case 5 :
// PDABytecodeTriggers.g:165:7: TOKEN_REF // PDABytecodeTriggers.g:165:7: TOKEN_REF
{ {
TOKEN_REF11=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal878); TOKEN_REF11=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal880);
emit(new CallInstr(TOKEN_REF11.token)); emit(new CallInstr(TOKEN_REF11.token));
} }
break; break;
case 6 : case 6 :
// PDABytecodeTriggers.g:166:7: ^( ROOT terminal ) // PDABytecodeTriggers.g:166:7: ^( ROOT terminal[false] )
{ {
match(input,ROOT,FOLLOW_ROOT_in_terminal893); match(input,ROOT,FOLLOW_ROOT_in_terminal895);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
pushFollow(FOLLOW_terminal_in_terminal895); pushFollow(FOLLOW_terminal_in_terminal897);
terminal(); terminal(false);
state._fsp--; state._fsp--;
@ -1413,13 +1413,13 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
} }
break; break;
case 7 : case 7 :
// PDABytecodeTriggers.g:167:7: ^( BANG terminal ) // PDABytecodeTriggers.g:167:7: ^( BANG terminal[false] )
{ {
match(input,BANG,FOLLOW_BANG_in_terminal908); match(input,BANG,FOLLOW_BANG_in_terminal911);
match(input, Token.DOWN, null); match(input, Token.DOWN, null);
pushFollow(FOLLOW_terminal_in_terminal910); pushFollow(FOLLOW_terminal_in_terminal913);
terminal(); terminal(false);
state._fsp--; state._fsp--;
@ -1653,7 +1653,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
this.transition = DFA10_transition; this.transition = DFA10_transition;
} }
public String getDescription() { public String getDescription() {
return "129:1: atom : ( ^( ROOT range ) | ^( BANG range ) | ^( ROOT notSet ) | ^( BANG notSet ) | notSet | range | ^( DOT ID terminal ) | ^( DOT ID ruleref ) | ^( WILDCARD . ) | WILDCARD | terminal | ruleref );"; return "129:1: atom : ( ^( ROOT range ) | ^( BANG range ) | ^( ROOT notSet ) | ^( BANG notSet ) | notSet | range | ^( DOT ID terminal[false] ) | ^( DOT ID ruleref ) | ^( WILDCARD . ) | WILDCARD | terminal[false] | ruleref );";
} }
} }
static final String DFA16_eotS = static final String DFA16_eotS =
@ -1719,7 +1719,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
this.transition = DFA16_transition; this.transition = DFA16_transition;
} }
public String getDescription() { public String getDescription() {
return "160:1: terminal : ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal ) | ^( BANG terminal ) );"; return "160:1: terminal[boolean not] : ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal[false] ) | ^( BANG terminal[false] ) );";
} }
} }
@ -1777,37 +1777,37 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
public static final BitSet FOLLOW_DOT_in_atom586 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_DOT_in_atom586 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_atom588 = new BitSet(new long[]{0x8021000000000000L,0x0000000000000010L}); public static final BitSet FOLLOW_ID_in_atom588 = new BitSet(new long[]{0x8021000000000000L,0x0000000000000010L});
public static final BitSet FOLLOW_terminal_in_atom590 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_terminal_in_atom590 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_DOT_in_atom599 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_DOT_in_atom600 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_atom601 = new BitSet(new long[]{0xA1A1000000000000L,0x0000000200000011L}); public static final BitSet FOLLOW_ID_in_atom602 = new BitSet(new long[]{0xA1A1000000000000L,0x0000000200000011L});
public static final BitSet FOLLOW_ruleref_in_atom603 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_ruleref_in_atom604 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_WILDCARD_in_atom615 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_WILDCARD_in_atom616 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_WILDCARD_in_atom631 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_WILDCARD_in_atom632 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_terminal_in_atom646 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_terminal_in_atom647 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ruleref_in_atom660 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_ruleref_in_atom662 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_NOT_in_notSet683 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_NOT_in_notSet685 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_terminal_in_notSet685 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_terminal_in_notSet687 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_NOT_in_notSet697 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_NOT_in_notSet698 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_block_in_notSet699 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_block_in_notSet700 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ROOT_in_ruleref721 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_ROOT_in_ruleref722 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_RULE_REF_in_ruleref724 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_RULE_REF_in_ruleref725 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref726 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_ARG_ACTION_in_ruleref727 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_BANG_in_ruleref739 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_BANG_in_ruleref740 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_RULE_REF_in_ruleref742 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_RULE_REF_in_ruleref743 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref744 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_ARG_ACTION_in_ruleref745 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_RULE_REF_in_ruleref757 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_RULE_REF_in_ruleref758 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref759 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_ARG_ACTION_in_ruleref760 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_RANGE_in_range782 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_RANGE_in_range783 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_STRING_LITERAL_in_range786 = new BitSet(new long[]{0x0000000000000000L,0x0000000000000010L}); public static final BitSet FOLLOW_STRING_LITERAL_in_range787 = new BitSet(new long[]{0x0000000000000000L,0x0000000000000010L});
public static final BitSet FOLLOW_STRING_LITERAL_in_range790 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_STRING_LITERAL_in_range791 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_STRING_LITERAL_in_terminal817 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_STRING_LITERAL_in_terminal819 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_STRING_LITERAL_in_terminal832 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_STRING_LITERAL_in_terminal834 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal846 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_TOKEN_REF_in_terminal848 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_terminal848 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF0L,0x0000007FFFFFFFFFL}); public static final BitSet FOLLOW_ARG_ACTION_in_terminal850 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF0L,0x0000007FFFFFFFFFL});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal862 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_TOKEN_REF_in_terminal864 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal878 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_TOKEN_REF_in_terminal880 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ROOT_in_terminal893 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_ROOT_in_terminal895 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_terminal_in_terminal895 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_terminal_in_terminal897 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_BANG_in_terminal908 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_BANG_in_terminal911 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_terminal_in_terminal910 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_terminal_in_terminal913 = new BitSet(new long[]{0x0000000000000008L});
} }

View File

@ -1,4 +1,4 @@
// $ANTLR ${project.version} ${buildNumber} SourceGenTriggers.g 2010-05-19 15:23:17 // $ANTLR 3.2.1-SNAPSHOT May 24, 2010 15:02:05 SourceGenTriggers.g 2010-05-25 13:12:36
package org.antlr.v4.codegen; package org.antlr.v4.codegen;

View File

@ -11,14 +11,19 @@ import java.util.List;
/** */ /** */
public abstract class Choice extends SrcOp { public abstract class Choice extends SrcOp {
public int decision; public int decision = -1;
public List<CodeBlock> alts; public List<CodeBlock> alts;
public List<SrcOp> preamble; public List<SrcOp> preamble;
public IntervalSet expecting; public IntervalSet expecting;
public Choice(OutputModelFactory factory, GrammarAST blkOrEbnfRootAST, List<CodeBlock> alts) { public Choice(OutputModelFactory factory,
GrammarAST blkOrEbnfRootAST,
List<CodeBlock> alts,
int decision)
{
super(factory, blkOrEbnfRootAST); super(factory, blkOrEbnfRootAST);
this.alts = alts; this.alts = alts;
this.decision = decision;
// TODO: use existing lookahead! don't compute // TODO: use existing lookahead! don't compute
LinearApproximator approx = new LinearApproximator(factory.g, decision); LinearApproximator approx = new LinearApproximator(factory.g, decision);

View File

@ -16,8 +16,7 @@ public class LL1Choice extends Choice {
public ThrowNoViableAlt error; public ThrowNoViableAlt error;
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, ((DecisionState)blkAST.nfaState).decision);
this.decision = ((DecisionState)blkAST.nfaState).decision;
DFA dfa = factory.g.decisionDFAs.get(decision); DFA dfa = factory.g.decisionDFAs.get(decision);
/** Lookahead for each alt 1..n */ /** Lookahead for each alt 1..n */
IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa); IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa);

View File

@ -13,9 +13,13 @@ public abstract class LL1Loop extends Choice {
public List<SrcOp> iteration; public List<SrcOp> iteration;
public Sync sync; public Sync sync;
public LL1Loop(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) { public LL1Loop(OutputModelFactory factory,
super(factory, blkAST, alts); GrammarAST blkAST,
this.sync = new Sync(factory, blkAST, expecting); List<CodeBlock> alts,
int decision)
{
super(factory, blkAST, alts, decision);
this.sync = new Sync(factory, blkAST, expecting, decision, "enter");
} }
public void addIterationOp(SrcOp op) { public void addIterationOp(SrcOp op) {

View File

@ -11,13 +11,15 @@ import java.util.List;
/** */ /** */
public class LL1OptionalBlockSingleAlt extends LL1Choice { public class LL1OptionalBlockSingleAlt extends LL1Choice {
public Object expr; public OutputModelObject expr;
public OutputModelObject followExpr;
public LL1OptionalBlockSingleAlt(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) { public LL1OptionalBlockSingleAlt(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
super(factory, blkAST, alts); super(factory, blkAST, alts);
DFA dfa = factory.g.decisionDFAs.get(((BlockStartState)blkAST.nfaState).decision); DFA dfa = factory.g.decisionDFAs.get(((BlockStartState)blkAST.nfaState).decision);
/** Lookahead for each alt 1..n */ /** Lookahead for each alt 1..n */
IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa); IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa);
IntervalSet look = altLookSets[1]; IntervalSet look = altLookSets[1];
IntervalSet followLook = altLookSets[2];
expr = factory.getLL1Test(look, blkAST); expr = factory.getLL1Test(look, blkAST);
if ( expr instanceof TestSetInline ) { if ( expr instanceof TestSetInline ) {
TestSetInline e = (TestSetInline)expr; TestSetInline e = (TestSetInline)expr;
@ -26,5 +28,6 @@ public class LL1OptionalBlockSingleAlt extends LL1Choice {
CaptureNextTokenType nextType = new CaptureNextTokenType(e.varName); CaptureNextTokenType nextType = new CaptureNextTokenType(e.varName);
addPreambleOp(nextType); addPreambleOp(nextType);
} }
followExpr = factory.getLL1Test(followLook, blkAST);
} }
} }

View File

@ -15,13 +15,14 @@ public class LL1PlusBlock extends LL1Loop {
/** Token names for each alt 0..n-1 */ /** Token names for each alt 0..n-1 */
public List<String[]> altLook; public List<String[]> altLook;
public Sync iterationSync;
public String loopLabel; public String loopLabel;
public String loopCounterVar; public String loopCounterVar;
public String[] exitLook; public String[] exitLook;
public ThrowEarlyExitException earlyExitError; 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, ((BlockStartState)blkAST.nfaState.transition(0).target).decision);
PlusBlockStartState plus = (PlusBlockStartState)blkAST.nfaState; PlusBlockStartState plus = (PlusBlockStartState)blkAST.nfaState;
BlockStartState blkStart = (BlockStartState)plus.transition(0).target; BlockStartState blkStart = (BlockStartState)plus.transition(0).target;
@ -32,11 +33,15 @@ public class LL1PlusBlock extends LL1Loop {
dfa = factory.g.decisionDFAs.get(plus.loopBackState.decision); dfa = factory.g.decisionDFAs.get(plus.loopBackState.decision);
IntervalSet exitLook = dfa.startState.edge(0).label; IntervalSet exitLook = dfa.startState.edge(0).label;
IntervalSet loopbackLook = dfa.startState.edge(1).label;
this.exitLook = factory.gen.target.getTokenTypesAsTargetLabels(factory.g, exitLook.toArray()); this.exitLook = factory.gen.target.getTokenTypesAsTargetLabels(factory.g, exitLook.toArray());
loopLabel = factory.gen.target.getLoopLabel(blkAST); loopLabel = factory.gen.target.getLoopLabel(blkAST);
loopCounterVar = factory.gen.target.getLoopCounter(blkAST); loopCounterVar = factory.gen.target.getLoopCounter(blkAST);
IntervalSet iterationExpected = (IntervalSet) loopbackLook.or(exitLook);
this.iterationSync = new Sync(factory, blkAST, iterationExpected, decision, "iter");
this.earlyExitError = new ThrowEarlyExitException(factory, blkAST, expecting); this.earlyExitError = new ThrowEarlyExitException(factory, blkAST, expecting);
} }
} }

View File

@ -14,7 +14,7 @@ public class LL1PlusBlockSingleAlt extends LL1Loop {
public ThrowEarlyExitException earlyExitError; 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, ((PlusBlockStartState)blkAST.nfaState).loopBackState.decision);
PlusBlockStartState plus = (PlusBlockStartState)blkAST.nfaState; PlusBlockStartState plus = (PlusBlockStartState)blkAST.nfaState;
DFA dfa = factory.g.decisionDFAs.get(plus.loopBackState.decision); DFA dfa = factory.g.decisionDFAs.get(plus.loopBackState.decision);
IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa); IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa);

View File

@ -19,7 +19,10 @@ public class LL1StarBlock extends LL1Loop {
public String[] exitLook; public String[] exitLook;
public LL1StarBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) { public LL1StarBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
// point at choice block inside outermost enter-exit choice // point at choice block inside outermost enter-exit choice
super(factory, ((StarBlockStartState)blkAST.nfaState).transition(0).target.ast, alts); super(factory,
((StarBlockStartState)blkAST.nfaState).transition(0).target.ast,
alts,
((StarBlockStartState) blkAST.nfaState).decision);
StarBlockStartState star = (StarBlockStartState)blkAST.nfaState; StarBlockStartState star = (StarBlockStartState)blkAST.nfaState;
int enterExitDecision = star.decision; int enterExitDecision = star.decision;
BlockStartState blkStart = (BlockStartState)star.transition(0).target; BlockStartState blkStart = (BlockStartState)star.transition(0).target;

View File

@ -12,11 +12,11 @@ import java.util.List;
/** */ /** */
public class LL1StarBlockSingleAlt extends LL1Loop { public class LL1StarBlockSingleAlt extends LL1Loop {
public LL1StarBlockSingleAlt(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) { public LL1StarBlockSingleAlt(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
super(factory, blkAST, alts); super(factory, blkAST, alts, ((StarBlockStartState)blkAST.nfaState).loopBackState.decision);
StarBlockStartState star = (StarBlockStartState)blkAST.nfaState; StarBlockStartState star = (StarBlockStartState)blkAST.nfaState;
DFA dfa = factory.g.decisionDFAs.get(star.loopBackState.decision); DFA dfa = factory.g.decisionDFAs.get(star.loopBackState.decision);
IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa); IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa);
IntervalSet look = altLookSets[1]; IntervalSet look = altLookSets[2];
addCodeForLookaheadTempVar(look); addCodeForLookaheadTempVar(look);
} }
} }

View File

@ -8,6 +8,6 @@ import java.util.List;
/** */ /** */
public abstract class OptionalBlock extends Choice { public abstract class OptionalBlock extends Choice {
public OptionalBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) { public OptionalBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
super(factory, blkAST, alts); super(factory, blkAST, alts, -999);
} }
} }

View File

@ -8,12 +8,15 @@ import org.antlr.v4.tool.GrammarAST;
public class Sync extends SrcOp { public class Sync extends SrcOp {
public int decision; public int decision;
public BitSetDecl expecting; public BitSetDecl expecting;
public Sync(OutputModelFactory factory, GrammarAST blkOrEbnfRootAST, public Sync(OutputModelFactory factory,
IntervalSet expecting) GrammarAST blkOrEbnfRootAST,
IntervalSet expecting,
int decision,
String position)
{ {
super(factory, blkOrEbnfRootAST); super(factory, blkOrEbnfRootAST);
// this.decision = ((BlockStartState)blkOrEbnfRootAST.nfaState).decision; this.decision = decision;
this.expecting = factory.createExpectingBitSet(ast, decision, expecting); this.expecting = factory.createExpectingBitSet(ast, decision, expecting, position);
factory.defineBitSet(this.expecting); factory.defineBitSet(this.expecting);
} }
} }

View File

@ -18,7 +18,7 @@ public class ThrowRecognitionException extends SrcOp {
grammarLine = ast.getLine(); grammarLine = ast.getLine();
grammarLine = ast.getCharPositionInLine(); grammarLine = ast.getCharPositionInLine();
grammarFile = factory.g.fileName; grammarFile = factory.g.fileName;
this.expecting = factory.createExpectingBitSet(ast, decision, expecting); this.expecting = factory.createExpectingBitSet(ast, decision, expecting, "error");
factory.defineBitSet(this.expecting); factory.defineBitSet(this.expecting);
} }
} }