forked from jasder/antlr
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:
parent
38ef035c06
commit
ca8ea6feea
|
@ -119,6 +119,7 @@ public abstract class BaseRecognizer {
|
|||
// like matchSet but w/o consume; error checking routine.
|
||||
public void sync(LABitSet expecting) {
|
||||
if ( expecting.member(state.input.LA(1)) ) return;
|
||||
System.out.println("failed sync to "+expecting);
|
||||
LABitSet followSet = computeErrorRecoverySet();
|
||||
followSet.orInPlace(expecting);
|
||||
NoViableAltException e = new NoViableAltException(this, followSet);
|
||||
|
|
|
@ -40,6 +40,8 @@ import org.antlr.v4.runtime.pda.PDA;
|
|||
*/
|
||||
public abstract class Lexer /* extends BaseRecognizer */ implements TokenSource {
|
||||
public static final int DEFAULT_MODE = 0;
|
||||
public static final int MORE = -2;
|
||||
public static final int SKIP = -3;
|
||||
|
||||
public LexerSharedState state;
|
||||
|
||||
|
@ -80,6 +82,7 @@ public abstract class Lexer /* extends BaseRecognizer */ implements TokenSource
|
|||
* stream.
|
||||
*/
|
||||
public Token nextToken() {
|
||||
outer:
|
||||
while (true) {
|
||||
state.token = null;
|
||||
state.channel = Token.DEFAULT_CHANNEL;
|
||||
|
@ -87,24 +90,27 @@ public abstract class Lexer /* extends BaseRecognizer */ implements TokenSource
|
|||
state.tokenStartCharPositionInLine = ((CharStream)state.input).getCharPositionInLine();
|
||||
state.tokenStartLine = ((CharStream)state.input).getLine();
|
||||
state.text = null;
|
||||
if ( state.input.LA(1)==CharStream.EOF ) {
|
||||
Token eof = new CommonToken((CharStream)state.input,Token.EOF,
|
||||
Token.DEFAULT_CHANNEL,
|
||||
state.input.index(),state.input.index());
|
||||
eof.setLine(getLine());
|
||||
eof.setCharPositionInLine(getCharPositionInLine());
|
||||
return eof;
|
||||
}
|
||||
{
|
||||
state.type = modeToPDA[_mode].execThompson(state.input);
|
||||
if ( state.token==null ) {
|
||||
emit();
|
||||
do {
|
||||
state.type = Token.INVALID_TOKEN_TYPE;
|
||||
if ( state.input.LA(1)==CharStream.EOF ) {
|
||||
Token eof = new CommonToken((CharStream)state.input,Token.EOF,
|
||||
Token.DEFAULT_CHANNEL,
|
||||
state.input.index(),state.input.index());
|
||||
eof.setLine(getLine());
|
||||
eof.setCharPositionInLine(getCharPositionInLine());
|
||||
return eof;
|
||||
}
|
||||
else if ( state.token==Token.SKIP_TOKEN ) {
|
||||
continue;
|
||||
int ttype = modeToPDA[_mode].execThompson(state.input);
|
||||
if ( state.type == Token.INVALID_TOKEN_TYPE ) state.type = ttype;
|
||||
if ( state.type==SKIP ) {
|
||||
continue outer;
|
||||
}
|
||||
return state.token;
|
||||
}
|
||||
// if ( state.token==null ) {
|
||||
// emit();
|
||||
// }
|
||||
} while ( state.type==MORE );
|
||||
emit();
|
||||
return state.token;
|
||||
// catch (NoViableAltException nva) {
|
||||
// reportError(nva);
|
||||
// recover(nva); // throw out current char and try again
|
||||
|
|
|
@ -147,7 +147,6 @@ public class LABitSet implements Cloneable {
|
|||
* @return A commma-separated list of values
|
||||
*/
|
||||
public String toString() {
|
||||
System.out.println("toStr");
|
||||
StringBuffer buf = new StringBuffer();
|
||||
String separator = ",";
|
||||
boolean havePrintedAnElement = false;
|
||||
|
@ -155,7 +154,6 @@ public class LABitSet implements Cloneable {
|
|||
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 ( havePrintedAnElement ) {
|
||||
buf.append(separator);
|
||||
|
|
|
@ -185,8 +185,8 @@ processOneChar:
|
|||
if ( reach.size()>0 ) { // if we reached other states, consume and process them
|
||||
input.consume();
|
||||
}
|
||||
else if ( !accepted) {
|
||||
System.out.println("!!!!! no match for char "+(char)c+" at "+input.index());
|
||||
else if ( !accepted ) {
|
||||
System.err.println("!!!!! no match for char "+(char)c+" at "+input.index());
|
||||
input.consume();
|
||||
}
|
||||
// else reach.size==0 && matched, don't consume: accepted
|
||||
|
|
|
@ -15,7 +15,9 @@ javaTypeInitMap ::= [
|
|||
ParserFile(file, parser, dfaDecls, bitSetDecls, namedActions) ::= <<
|
||||
// $ANTLR ANTLRVersion> <file.fileName> generatedTimestamp>
|
||||
<namedActions.header>
|
||||
import org.antlr.v4.runtime.NoViableAltException;
|
||||
import org.antlr.v4.runtime.Parser;
|
||||
import org.antlr.v4.runtime.EarlyExitException;
|
||||
import org.antlr.v4.runtime.RecognizerSharedState;
|
||||
import org.antlr.v4.runtime.RecognitionException;
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
|
@ -116,14 +118,12 @@ switch ( state.input.LA(1) ) {
|
|||
// follow set included as choice by analysis
|
||||
LL1OptionalBlock ::= LL1Choice
|
||||
|
||||
LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error) ::= <<
|
||||
LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error, followExpr) ::= <<
|
||||
<preamble; separator="\n">
|
||||
if ( <expr> ) {
|
||||
<alts; separator="\n">
|
||||
}
|
||||
else {
|
||||
<error>
|
||||
}
|
||||
else if ( !(<followExpr>) ) <error>
|
||||
>>
|
||||
|
||||
LL1StarBlock(choice, alts, sync) ::= <<
|
||||
|
@ -149,7 +149,7 @@ while ( <expr> ) {
|
|||
}
|
||||
>>
|
||||
|
||||
LL1PlusBlock(choice, alts, earlyExitError, sync) ::= <<
|
||||
LL1PlusBlock(choice, alts, earlyExitError, sync, iterationSync) ::= <<
|
||||
<sync>
|
||||
int <choice.loopCounterVar> = 0;
|
||||
<choice.loopLabel>:
|
||||
|
@ -162,7 +162,8 @@ while (true) {
|
|||
if ( <choice.loopCounterVar> >= 1 ) break <choice.loopLabel>;
|
||||
else <earlyExitError>
|
||||
}
|
||||
<sync>
|
||||
<choice.loopCounterVar>++;
|
||||
<iterationSync>
|
||||
}
|
||||
>>
|
||||
|
||||
|
@ -180,8 +181,8 @@ do {
|
|||
|
||||
Sync(s) ::= "sync(<s.expecting.name>);"
|
||||
|
||||
ThrowNoViableAlt(t) ::= "throw new NoViableAlt(this, <t.expecting.name>);"
|
||||
ThrowEarlyExitException(t) ::= "throw new ThrowEarlyExitException(this, <t.expecting.name>);"
|
||||
ThrowNoViableAlt(t) ::= "throw new NoViableAltException(this, <t.expecting.name>);"
|
||||
ThrowEarlyExitException(t) ::= "throw new EarlyExitException(this, <t.expecting.name>);"
|
||||
|
||||
TestSet(s) ::= <<
|
||||
<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 {
|
||||
<if(actions)>
|
||||
public void action(int r, int a) {
|
||||
<actions:{a |
|
||||
switch ( r ) {
|
||||
case <i0> : <a.name>_actions(a); break;
|
||||
<actions:{a |
|
||||
case <a.ruleIndex> : <a.name>_actions(a); break;
|
||||
}>
|
||||
}
|
||||
}
|
||||
<endif>
|
||||
<if(sempreds)>
|
||||
public void sempred(int r, int a) {
|
||||
<sempreds:{p |
|
||||
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>
|
||||
>>
|
||||
|
||||
actionMethod(name, actions) ::= <<
|
||||
actionMethod(name, actions, ruleIndex) ::= <<
|
||||
public void <name>_actions(int action) {
|
||||
switch ( action ) {
|
||||
<actions:{a |
|
||||
|
|
|
@ -33,6 +33,7 @@ public class LexerFactory {
|
|||
actionST.add("name", r.name);
|
||||
for (Token t : actionTokens) {
|
||||
actionST.add("actions", Misc.strip(t.getText(),1));
|
||||
actionST.add("ruleIndex", r.index);
|
||||
}
|
||||
pdaST.add("actions", actionST);
|
||||
lexerST.add("actions", actionST);
|
||||
|
@ -41,6 +42,7 @@ public class LexerFactory {
|
|||
Set<Token> sempredTokens = pda.ruleSempreds.keySet(r);
|
||||
ST sempredST = gen.templates.getInstanceOf("sempredMethod");
|
||||
sempredST.add("name", r.name);
|
||||
sempredST.add("ruleIndex", r.index);
|
||||
for (Token t : sempredTokens) {
|
||||
sempredST.add("preds", t.getText());
|
||||
}
|
||||
|
|
|
@ -99,9 +99,10 @@ public abstract class OutputModelFactory {
|
|||
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 name = "EXPECTING_in_"+inRuleName+"_"+decision;
|
||||
String name = "EXPECTING_in_"+inRuleName+"_"+position+"_"+decision;
|
||||
//System.out.println("!!!!!!!! create "+name);
|
||||
BitSetDecl b = new BitSetDecl(this, name, set);
|
||||
return b;
|
||||
}
|
||||
|
|
|
@ -6,11 +6,13 @@ import org.antlr.runtime.tree.CommonTreeNodeStream;
|
|||
import org.antlr.runtime.tree.TreeNodeStream;
|
||||
import org.antlr.v4.codegen.pda.*;
|
||||
import org.antlr.v4.misc.CharSupport;
|
||||
import org.antlr.v4.misc.IntervalSet;
|
||||
import org.antlr.v4.parse.ANTLRParser;
|
||||
import org.antlr.v4.parse.GrammarASTAdaptor;
|
||||
import org.antlr.v4.runtime.pda.Bytecode;
|
||||
import org.antlr.v4.runtime.pda.PDA;
|
||||
import org.antlr.v4.runtime.tree.TreeParser;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.GrammarAST;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.antlr.v4.tool.Rule;
|
||||
|
@ -19,6 +21,8 @@ import java.util.Map;
|
|||
|
||||
/** http://swtch.com/~rsc/regexp/regexp2.html */
|
||||
public class PDABytecodeGenerator extends TreeParser {
|
||||
public Grammar g;
|
||||
|
||||
public Rule currentRule;
|
||||
|
||||
CompiledPDA pda = new CompiledPDA();
|
||||
|
@ -71,13 +75,39 @@ public class PDABytecodeGenerator extends TreeParser {
|
|||
return i;
|
||||
}
|
||||
|
||||
public void emitString(Token t) {
|
||||
public void emitString(Token t, boolean not) {
|
||||
String chars = CharSupport.getStringFromGrammarStringLiteral(t.getText());
|
||||
if ( not && chars.length()==1 ) {
|
||||
emitNotChar(t, chars);
|
||||
return;
|
||||
}
|
||||
for (char c : chars.toCharArray()) {
|
||||
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() {
|
||||
Instr last = pda.instrs.get(pda.instrs.size() - 1);
|
||||
int size = last.addr + last.nBytes();
|
||||
|
@ -100,6 +130,7 @@ public class PDABytecodeGenerator extends TreeParser {
|
|||
public static CompiledPDA compileLexerMode(LexerGrammar lg, String modeName) {
|
||||
GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
|
||||
PDABytecodeTriggers gen = new PDABytecodeTriggers(null);
|
||||
gen.g = lg;
|
||||
gen.pda.tokenTypeToAddr = new int[lg.getMaxTokenType()+1];
|
||||
|
||||
// add split for s0 to hook up rules (fill in operands as we gen rules)
|
||||
|
|
|
@ -133,16 +133,16 @@ atom
|
|||
| ^(BANG notSet)
|
||||
| notSet
|
||||
| range
|
||||
| ^(DOT ID terminal)
|
||||
| ^(DOT ID terminal[false])
|
||||
| ^(DOT ID ruleref)
|
||||
| ^(WILDCARD .) {emit(new WildcardInstr($WILDCARD.token));}
|
||||
| WILDCARD {emit(new WildcardInstr($WILDCARD.token));}
|
||||
| terminal
|
||||
| terminal[false]
|
||||
| ruleref
|
||||
;
|
||||
|
||||
notSet
|
||||
: ^(NOT terminal)
|
||||
: ^(NOT terminal[true])
|
||||
| ^(NOT block)
|
||||
;
|
||||
|
||||
|
@ -157,12 +157,12 @@ range
|
|||
{emit(new RangeInstr($a.token, $b.token));}
|
||||
;
|
||||
|
||||
terminal
|
||||
: ^(STRING_LITERAL .) {emitString($STRING_LITERAL.token);}
|
||||
| STRING_LITERAL {emitString($STRING_LITERAL.token);}
|
||||
terminal[boolean not]
|
||||
: ^(STRING_LITERAL .) {emitString($STRING_LITERAL.token, $not);}
|
||||
| STRING_LITERAL {emitString($STRING_LITERAL.token, $not);}
|
||||
| ^(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));}
|
||||
| ^(ROOT terminal)
|
||||
| ^(BANG terminal)
|
||||
| ^(ROOT terminal[false])
|
||||
| ^(BANG terminal[false])
|
||||
;
|
|
@ -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;
|
||||
|
||||
|
@ -872,13 +872,13 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
|
||||
|
||||
// $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 {
|
||||
GrammarAST WILDCARD5=null;
|
||||
GrammarAST WILDCARD6=null;
|
||||
|
||||
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;
|
||||
alt10 = dfa10.predict(input);
|
||||
switch (alt10) {
|
||||
|
@ -969,14 +969,14 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
}
|
||||
break;
|
||||
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, Token.DOWN, null);
|
||||
match(input,ID,FOLLOW_ID_in_atom588);
|
||||
pushFollow(FOLLOW_terminal_in_atom590);
|
||||
terminal();
|
||||
terminal(false);
|
||||
|
||||
state._fsp--;
|
||||
|
||||
|
@ -988,11 +988,11 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 8 :
|
||||
// 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,ID,FOLLOW_ID_in_atom601);
|
||||
pushFollow(FOLLOW_ruleref_in_atom603);
|
||||
match(input,ID,FOLLOW_ID_in_atom602);
|
||||
pushFollow(FOLLOW_ruleref_in_atom604);
|
||||
ruleref();
|
||||
|
||||
state._fsp--;
|
||||
|
@ -1005,7 +1005,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 9 :
|
||||
// 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);
|
||||
matchAny(input);
|
||||
|
@ -1018,16 +1018,16 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 10 :
|
||||
// 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));
|
||||
|
||||
}
|
||||
break;
|
||||
case 11 :
|
||||
// PDABytecodeTriggers.g:140:9: terminal
|
||||
// PDABytecodeTriggers.g:140:9: terminal[false]
|
||||
{
|
||||
pushFollow(FOLLOW_terminal_in_atom646);
|
||||
terminal();
|
||||
pushFollow(FOLLOW_terminal_in_atom647);
|
||||
terminal(false);
|
||||
|
||||
state._fsp--;
|
||||
|
||||
|
@ -1037,7 +1037,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 12 :
|
||||
// PDABytecodeTriggers.g:141:9: ruleref
|
||||
{
|
||||
pushFollow(FOLLOW_ruleref_in_atom660);
|
||||
pushFollow(FOLLOW_ruleref_in_atom662);
|
||||
ruleref();
|
||||
|
||||
state._fsp--;
|
||||
|
@ -1060,10 +1060,10 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
|
||||
|
||||
// $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 {
|
||||
try {
|
||||
// PDABytecodeTriggers.g:145:5: ( ^( NOT terminal ) | ^( NOT block ) )
|
||||
// PDABytecodeTriggers.g:145:5: ( ^( NOT terminal[true] ) | ^( NOT block ) )
|
||||
int alt11=2;
|
||||
int LA11_0 = input.LA(1);
|
||||
|
||||
|
@ -1101,13 +1101,13 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
}
|
||||
switch (alt11) {
|
||||
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);
|
||||
pushFollow(FOLLOW_terminal_in_notSet685);
|
||||
terminal();
|
||||
pushFollow(FOLLOW_terminal_in_notSet687);
|
||||
terminal(true);
|
||||
|
||||
state._fsp--;
|
||||
|
||||
|
@ -1119,10 +1119,10 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 2 :
|
||||
// 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);
|
||||
pushFollow(FOLLOW_block_in_notSet699);
|
||||
pushFollow(FOLLOW_block_in_notSet700);
|
||||
block();
|
||||
|
||||
state._fsp--;
|
||||
|
@ -1179,10 +1179,10 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 1 :
|
||||
// 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,RULE_REF,FOLLOW_RULE_REF_in_ruleref724);
|
||||
match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref725);
|
||||
|
||||
if ( input.LA(1)==Token.DOWN ) {
|
||||
match(input, Token.DOWN, null);
|
||||
|
@ -1197,7 +1197,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 1 :
|
||||
// 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;
|
||||
|
@ -1215,10 +1215,10 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 2 :
|
||||
// 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,RULE_REF,FOLLOW_RULE_REF_in_ruleref742);
|
||||
match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref743);
|
||||
|
||||
if ( input.LA(1)==Token.DOWN ) {
|
||||
match(input, Token.DOWN, null);
|
||||
|
@ -1233,7 +1233,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 1 :
|
||||
// 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;
|
||||
|
@ -1251,7 +1251,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 3 :
|
||||
// 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 ) {
|
||||
match(input, Token.DOWN, null);
|
||||
|
@ -1266,7 +1266,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 1 :
|
||||
// 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;
|
||||
|
@ -1303,11 +1303,11 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
// PDABytecodeTriggers.g:156:5: ( ^( 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);
|
||||
a=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range786);
|
||||
b=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range790);
|
||||
a=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range787);
|
||||
b=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range791);
|
||||
|
||||
match(input, Token.UP, null);
|
||||
emit(new RangeInstr(a.token, b.token));
|
||||
|
@ -1327,8 +1327,8 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
|
||||
|
||||
// $ANTLR start "terminal"
|
||||
// PDABytecodeTriggers.g:160:1: terminal : ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal ) | ^( BANG terminal ) );
|
||||
public final void terminal() throws RecognitionException {
|
||||
// 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(boolean not) throws RecognitionException {
|
||||
GrammarAST STRING_LITERAL7=null;
|
||||
GrammarAST STRING_LITERAL8=null;
|
||||
GrammarAST TOKEN_REF9=null;
|
||||
|
@ -1336,38 +1336,38 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
GrammarAST TOKEN_REF11=null;
|
||||
|
||||
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;
|
||||
alt16 = dfa16.predict(input);
|
||||
switch (alt16) {
|
||||
case 1 :
|
||||
// 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);
|
||||
matchAny(input);
|
||||
|
||||
match(input, Token.UP, null);
|
||||
emitString(STRING_LITERAL7.token);
|
||||
emitString(STRING_LITERAL7.token, not);
|
||||
|
||||
}
|
||||
break;
|
||||
case 2 :
|
||||
// PDABytecodeTriggers.g:162:7: STRING_LITERAL
|
||||
{
|
||||
STRING_LITERAL8=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal832);
|
||||
emitString(STRING_LITERAL8.token);
|
||||
STRING_LITERAL8=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal834);
|
||||
emitString(STRING_LITERAL8.token, not);
|
||||
|
||||
}
|
||||
break;
|
||||
case 3 :
|
||||
// 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,ARG_ACTION,FOLLOW_ARG_ACTION_in_terminal848);
|
||||
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_terminal850);
|
||||
matchAny(input);
|
||||
|
||||
match(input, Token.UP, null);
|
||||
|
@ -1378,7 +1378,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 4 :
|
||||
// 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);
|
||||
matchAny(input);
|
||||
|
@ -1391,19 +1391,19 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
case 5 :
|
||||
// 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));
|
||||
|
||||
}
|
||||
break;
|
||||
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);
|
||||
pushFollow(FOLLOW_terminal_in_terminal895);
|
||||
terminal();
|
||||
pushFollow(FOLLOW_terminal_in_terminal897);
|
||||
terminal(false);
|
||||
|
||||
state._fsp--;
|
||||
|
||||
|
@ -1413,13 +1413,13 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
}
|
||||
break;
|
||||
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);
|
||||
pushFollow(FOLLOW_terminal_in_terminal910);
|
||||
terminal();
|
||||
pushFollow(FOLLOW_terminal_in_terminal913);
|
||||
terminal(false);
|
||||
|
||||
state._fsp--;
|
||||
|
||||
|
@ -1653,7 +1653,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
this.transition = DFA10_transition;
|
||||
}
|
||||
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 =
|
||||
|
@ -1719,7 +1719,7 @@ public class PDABytecodeTriggers extends PDABytecodeGenerator {
|
|||
this.transition = DFA16_transition;
|
||||
}
|
||||
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_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_DOT_in_atom599 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_ID_in_atom601 = new BitSet(new long[]{0xA1A1000000000000L,0x0000000200000011L});
|
||||
public static final BitSet FOLLOW_ruleref_in_atom603 = 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_atom631 = new BitSet(new long[]{0x0000000000000002L});
|
||||
public static final BitSet FOLLOW_terminal_in_atom646 = new BitSet(new long[]{0x0000000000000002L});
|
||||
public static final BitSet FOLLOW_ruleref_in_atom660 = new BitSet(new long[]{0x0000000000000002L});
|
||||
public static final BitSet FOLLOW_NOT_in_notSet683 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_terminal_in_notSet685 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_NOT_in_notSet697 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_block_in_notSet699 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_ROOT_in_ruleref721 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_RULE_REF_in_ruleref724 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref726 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_BANG_in_ruleref739 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_RULE_REF_in_ruleref742 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref744 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_RULE_REF_in_ruleref757 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref759 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_RANGE_in_range782 = 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_range790 = 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_terminal832 = new BitSet(new long[]{0x0000000000000002L});
|
||||
public static final BitSet FOLLOW_TOKEN_REF_in_terminal846 = 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_TOKEN_REF_in_terminal862 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_TOKEN_REF_in_terminal878 = new BitSet(new long[]{0x0000000000000002L});
|
||||
public static final BitSet FOLLOW_ROOT_in_terminal893 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_terminal_in_terminal895 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_BANG_in_terminal908 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_terminal_in_terminal910 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_DOT_in_atom600 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_ID_in_atom602 = new BitSet(new long[]{0xA1A1000000000000L,0x0000000200000011L});
|
||||
public static final BitSet FOLLOW_ruleref_in_atom604 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_WILDCARD_in_atom616 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_WILDCARD_in_atom632 = 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_atom662 = new BitSet(new long[]{0x0000000000000002L});
|
||||
public static final BitSet FOLLOW_NOT_in_notSet685 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_terminal_in_notSet687 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_NOT_in_notSet698 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_block_in_notSet700 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_ROOT_in_ruleref722 = 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_ruleref727 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_BANG_in_ruleref740 = 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_ruleref745 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_RULE_REF_in_ruleref758 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref760 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_RANGE_in_range783 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_STRING_LITERAL_in_range787 = new BitSet(new long[]{0x0000000000000000L,0x0000000000000010L});
|
||||
public static final BitSet FOLLOW_STRING_LITERAL_in_range791 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_STRING_LITERAL_in_terminal819 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_STRING_LITERAL_in_terminal834 = new BitSet(new long[]{0x0000000000000002L});
|
||||
public static final BitSet FOLLOW_TOKEN_REF_in_terminal848 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_ARG_ACTION_in_terminal850 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF0L,0x0000007FFFFFFFFFL});
|
||||
public static final BitSet FOLLOW_TOKEN_REF_in_terminal864 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_TOKEN_REF_in_terminal880 = new BitSet(new long[]{0x0000000000000002L});
|
||||
public static final BitSet FOLLOW_ROOT_in_terminal895 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_terminal_in_terminal897 = new BitSet(new long[]{0x0000000000000008L});
|
||||
public static final BitSet FOLLOW_BANG_in_terminal911 = new BitSet(new long[]{0x0000000000000004L});
|
||||
public static final BitSet FOLLOW_terminal_in_terminal913 = new BitSet(new long[]{0x0000000000000008L});
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -11,14 +11,19 @@ import java.util.List;
|
|||
|
||||
/** */
|
||||
public abstract class Choice extends SrcOp {
|
||||
public int decision;
|
||||
public int decision = -1;
|
||||
public List<CodeBlock> alts;
|
||||
public List<SrcOp> preamble;
|
||||
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);
|
||||
this.alts = alts;
|
||||
this.decision = decision;
|
||||
|
||||
// TODO: use existing lookahead! don't compute
|
||||
LinearApproximator approx = new LinearApproximator(factory.g, decision);
|
||||
|
|
|
@ -16,8 +16,7 @@ public class LL1Choice extends Choice {
|
|||
public ThrowNoViableAlt error;
|
||||
|
||||
public LL1Choice(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
|
||||
super(factory, blkAST, alts);
|
||||
this.decision = ((DecisionState)blkAST.nfaState).decision;
|
||||
super(factory, blkAST, alts, ((DecisionState)blkAST.nfaState).decision);
|
||||
DFA dfa = factory.g.decisionDFAs.get(decision);
|
||||
/** Lookahead for each alt 1..n */
|
||||
IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa);
|
||||
|
|
|
@ -13,9 +13,13 @@ public abstract class LL1Loop extends Choice {
|
|||
public List<SrcOp> iteration;
|
||||
public Sync sync;
|
||||
|
||||
public LL1Loop(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
|
||||
super(factory, blkAST, alts);
|
||||
this.sync = new Sync(factory, blkAST, expecting);
|
||||
public LL1Loop(OutputModelFactory factory,
|
||||
GrammarAST blkAST,
|
||||
List<CodeBlock> alts,
|
||||
int decision)
|
||||
{
|
||||
super(factory, blkAST, alts, decision);
|
||||
this.sync = new Sync(factory, blkAST, expecting, decision, "enter");
|
||||
}
|
||||
|
||||
public void addIterationOp(SrcOp op) {
|
||||
|
|
|
@ -11,13 +11,15 @@ import java.util.List;
|
|||
|
||||
/** */
|
||||
public class LL1OptionalBlockSingleAlt extends LL1Choice {
|
||||
public Object expr;
|
||||
public OutputModelObject expr;
|
||||
public OutputModelObject followExpr;
|
||||
public LL1OptionalBlockSingleAlt(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
|
||||
super(factory, blkAST, alts);
|
||||
DFA dfa = factory.g.decisionDFAs.get(((BlockStartState)blkAST.nfaState).decision);
|
||||
/** Lookahead for each alt 1..n */
|
||||
IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa);
|
||||
IntervalSet look = altLookSets[1];
|
||||
IntervalSet followLook = altLookSets[2];
|
||||
expr = factory.getLL1Test(look, blkAST);
|
||||
if ( expr instanceof TestSetInline ) {
|
||||
TestSetInline e = (TestSetInline)expr;
|
||||
|
@ -26,5 +28,6 @@ public class LL1OptionalBlockSingleAlt extends LL1Choice {
|
|||
CaptureNextTokenType nextType = new CaptureNextTokenType(e.varName);
|
||||
addPreambleOp(nextType);
|
||||
}
|
||||
followExpr = factory.getLL1Test(followLook, blkAST);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,14 @@ public class LL1PlusBlock extends LL1Loop {
|
|||
/** Token names for each alt 0..n-1 */
|
||||
public List<String[]> altLook;
|
||||
|
||||
public Sync iterationSync;
|
||||
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);
|
||||
super(factory, blkAST, alts, ((BlockStartState)blkAST.nfaState.transition(0).target).decision);
|
||||
PlusBlockStartState plus = (PlusBlockStartState)blkAST.nfaState;
|
||||
BlockStartState blkStart = (BlockStartState)plus.transition(0).target;
|
||||
|
||||
|
@ -32,11 +33,15 @@ public class LL1PlusBlock extends LL1Loop {
|
|||
|
||||
dfa = factory.g.decisionDFAs.get(plus.loopBackState.decision);
|
||||
IntervalSet exitLook = dfa.startState.edge(0).label;
|
||||
IntervalSet loopbackLook = dfa.startState.edge(1).label;
|
||||
this.exitLook = factory.gen.target.getTokenTypesAsTargetLabels(factory.g, exitLook.toArray());
|
||||
|
||||
loopLabel = factory.gen.target.getLoopLabel(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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public class LL1PlusBlockSingleAlt extends LL1Loop {
|
|||
public ThrowEarlyExitException earlyExitError;
|
||||
|
||||
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;
|
||||
DFA dfa = factory.g.decisionDFAs.get(plus.loopBackState.decision);
|
||||
IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa);
|
||||
|
|
|
@ -19,7 +19,10 @@ public class LL1StarBlock extends LL1Loop {
|
|||
public String[] exitLook;
|
||||
public LL1StarBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
|
||||
// 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;
|
||||
int enterExitDecision = star.decision;
|
||||
BlockStartState blkStart = (BlockStartState)star.transition(0).target;
|
||||
|
|
|
@ -12,11 +12,11 @@ import java.util.List;
|
|||
/** */
|
||||
public class LL1StarBlockSingleAlt extends LL1Loop {
|
||||
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;
|
||||
DFA dfa = factory.g.decisionDFAs.get(star.loopBackState.decision);
|
||||
IntervalSet[] altLookSets = LinearApproximator.getLL1LookaheadSets(dfa);
|
||||
IntervalSet look = altLookSets[1];
|
||||
IntervalSet look = altLookSets[2];
|
||||
addCodeForLookaheadTempVar(look);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@ import java.util.List;
|
|||
/** */
|
||||
public abstract class OptionalBlock extends Choice {
|
||||
public OptionalBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlock> alts) {
|
||||
super(factory, blkAST, alts);
|
||||
super(factory, blkAST, alts, -999);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,15 @@ import org.antlr.v4.tool.GrammarAST;
|
|||
public class Sync extends SrcOp {
|
||||
public int decision;
|
||||
public BitSetDecl expecting;
|
||||
public Sync(OutputModelFactory factory, GrammarAST blkOrEbnfRootAST,
|
||||
IntervalSet expecting)
|
||||
public Sync(OutputModelFactory factory,
|
||||
GrammarAST blkOrEbnfRootAST,
|
||||
IntervalSet expecting,
|
||||
int decision,
|
||||
String position)
|
||||
{
|
||||
super(factory, blkOrEbnfRootAST);
|
||||
// this.decision = ((BlockStartState)blkOrEbnfRootAST.nfaState).decision;
|
||||
this.expecting = factory.createExpectingBitSet(ast, decision, expecting);
|
||||
this.decision = decision;
|
||||
this.expecting = factory.createExpectingBitSet(ast, decision, expecting, position);
|
||||
factory.defineBitSet(this.expecting);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class ThrowRecognitionException extends SrcOp {
|
|||
grammarLine = ast.getLine();
|
||||
grammarLine = ast.getCharPositionInLine();
|
||||
grammarFile = factory.g.fileName;
|
||||
this.expecting = factory.createExpectingBitSet(ast, decision, expecting);
|
||||
this.expecting = factory.createExpectingBitSet(ast, decision, expecting, "error");
|
||||
factory.defineBitSet(this.expecting);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue