From 883a00a4b0545398c8a982b63d05d87a497aa0f9 Mon Sep 17 00:00:00 2001 From: parrt Date: Sun, 9 May 2010 16:15:08 -0800 Subject: [PATCH] got simple LL1 (..) and (..)? in; added Decl concept [git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6851] --- .../v4/tool/templates/codegen/Java/Java.stg | 48 +- .../antlr/v4/analysis/LinearApproximator.java | 10 + .../antlr/v4/automata/ParserNFAFactory.java | 2 +- .../org/antlr/v4/codegen/CodeGenerator.java | 50 +- .../antlr/v4/codegen/OutputModelWalker.java | 9 +- .../org/antlr/v4/codegen/SourceGenTriggers.g | 95 +- .../antlr/v4/codegen/SourceGenTriggers.java | 1843 +++++++++++++++++ tool/src/org/antlr/v4/codegen/Target.java | 9 + tool/src/org/antlr/v4/codegen/src/Choice.java | 12 +- .../org/antlr/v4/codegen/src/CodeBlock.java | 3 +- tool/src/org/antlr/v4/codegen/src/Decl.java | 7 + .../org/antlr/v4/codegen/src/InvokeRule.java | 24 +- .../org/antlr/v4/codegen/src/LL1Choice.java | 22 +- .../v4/codegen/src/LL1OptionalBlock.java | 7 +- .../src/LL1OptionalBlockSingleAlt.java | 25 +- .../v4/codegen/src/LLStarOptionalBlock.java | 7 +- .../v4/codegen/src/LLkOptionalBlock.java | 5 +- .../org/antlr/v4/codegen/src/MatchToken.java | 7 +- .../antlr/v4/codegen/src/NextTokenDecl.java | 6 + .../antlr/v4/codegen/src/OptionalBlock.java | 12 +- tool/src/org/antlr/v4/codegen/src/Parser.java | 3 +- .../org/antlr/v4/codegen/src/ParserFile.java | 2 + .../antlr/v4/codegen/src/RuleFunction.java | 7 +- .../src/org/antlr/v4/codegen/src/TestSet.java | 13 + .../antlr/v4/codegen/src/TestSetInline.java | 13 + 25 files changed, 2139 insertions(+), 102 deletions(-) create mode 100644 tool/src/org/antlr/v4/codegen/SourceGenTriggers.java create mode 100644 tool/src/org/antlr/v4/codegen/src/Decl.java create mode 100644 tool/src/org/antlr/v4/codegen/src/NextTokenDecl.java create mode 100644 tool/src/org/antlr/v4/codegen/src/TestSet.java create mode 100644 tool/src/org/antlr/v4/codegen/src/TestSetInline.java diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg index 93ce70477..95291aad6 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg @@ -32,17 +32,55 @@ CodeBlock(c, ops) ::= << >> -LL1Choice(c, alts) ::= << +LL1Choice(choice, alts) ::= << switch ( input.LA(1) ) { - + }; separator="\n"> + default : + error } >> -MatchToken(m) ::= << -match(, ); +LL1OptionalBlock(choice, expr, alts) ::= << +switch ( ) { + }; separator="\n"> +} >> +LL1OptionalBlockSingleAlt(choice, expr, alts, decls) ::= << + +if ( ) { + +} +else { + NoViableAltException nvae = new NoViableAltException("", 4, 0, input); +} +>> + +TestSet(s) ::= << +.member(input.LA(1)) +>> + +TestSetInline(s) ::= << +==}; separator=" || "> +>> + +cases(look) ::= << +:<\n>}> +>> + +InvokeRule(r) ::= << +pushFollow(); + = (); +state._fsp--; +>> + +MatchToken(m) ::= << + = match(, ); +>> + +NextTokenDecl(d) ::= "Token = input.LA(1);" + codeFileExtension() ::= ".java" true() ::= "true" -false() ::= "false" +false() ::= "false" \ No newline at end of file diff --git a/tool/src/org/antlr/v4/analysis/LinearApproximator.java b/tool/src/org/antlr/v4/analysis/LinearApproximator.java index 6ef7ca3f6..74af12e75 100644 --- a/tool/src/org/antlr/v4/analysis/LinearApproximator.java +++ b/tool/src/org/antlr/v4/analysis/LinearApproximator.java @@ -154,6 +154,16 @@ public class LinearApproximator { return dfa; } + /** From linear approximate LL(1) DFA, get lookahead per alt; 1..n */ + public static IntervalSet[] getLL1LookaheadSets(DFA dfa) { + IntervalSet[] look = new IntervalSet[dfa.nAlts+1]; + DFAState s0 = dfa.startState; + for (int a=1; a<=dfa.nAlts; a++) { + look[a] = s0.edges.get(a-1).label; + } + return look; + } + /** From an NFA state, s, find the set of all labels reachable from s at * depth k. */ diff --git a/tool/src/org/antlr/v4/automata/ParserNFAFactory.java b/tool/src/org/antlr/v4/automata/ParserNFAFactory.java index 7be7372bc..ff4e61ec2 100644 --- a/tool/src/org/antlr/v4/automata/ParserNFAFactory.java +++ b/tool/src/org/antlr/v4/automata/ParserNFAFactory.java @@ -241,7 +241,7 @@ public class ParserNFAFactory implements NFAFactory { Handle first = els.get(0); Handle last = els.get(els.size()-1); if ( first==null || last==null ) { - System.out.println("huh?"); + g.tool.errMgr.toolError(ErrorType.INTERNAL_ERROR, "alt Handle has first|last == null"); } return new Handle(first.left, last.right); } diff --git a/tool/src/org/antlr/v4/codegen/CodeGenerator.java b/tool/src/org/antlr/v4/codegen/CodeGenerator.java index 4e2b7fd1b..e66a4299f 100644 --- a/tool/src/org/antlr/v4/codegen/CodeGenerator.java +++ b/tool/src/org/antlr/v4/codegen/CodeGenerator.java @@ -1,10 +1,10 @@ package org.antlr.v4.codegen; -import org.antlr.v4.codegen.src.BitSetDef; -import org.antlr.v4.codegen.src.OutputModelObject; -import org.antlr.v4.codegen.src.ParserFile; +import org.antlr.v4.automata.DFA; +import org.antlr.v4.codegen.src.*; import org.antlr.v4.misc.IntSet; import org.antlr.v4.parse.ANTLRParser; +import org.antlr.v4.tool.BlockAST; import org.antlr.v4.tool.ErrorType; import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.GrammarAST; @@ -12,6 +12,7 @@ import org.stringtemplate.v4.*; import java.io.IOException; import java.io.Writer; +import java.util.List; /** */ public abstract class CodeGenerator { @@ -105,6 +106,27 @@ public abstract class CodeGenerator { } } + public Choice getChoiceBlock(BlockAST blkAST, GrammarAST ebnfRoot, List alts) { + // TODO: assumes LL1 + int ebnf = 0; + if ( ebnfRoot!=null ) ebnf = ebnfRoot.getType(); + Choice c = null; + switch ( ebnf ) { + case ANTLRParser.OPTIONAL : + if ( alts.size()==1 ) c = new LL1OptionalBlockSingleAlt(this, ebnfRoot, alts); + else c = new LL1OptionalBlock(this, ebnfRoot, alts); + break; + case ANTLRParser.CLOSURE : + break; + case ANTLRParser.POSITIVE_CLOSURE : + break; + default : + c = new LL1Choice(this, blkAST, alts); + break; + } + return c; + } + public void write(ST code, String fileName) throws IOException { long start = System.currentTimeMillis(); Writer w = g.tool.getOutputFile(g, fileName); @@ -136,14 +158,28 @@ public abstract class CodeGenerator { return g.name+VOCAB_FILE_EXTENSION; } - public BitSetDef defineBitSet(GrammarAST ast, IntSet follow) { + public DFADef defineDFA(GrammarAST ast, DFA dfa) { + return null; +// DFADef d = new DFADef(name, dfa); +// outputModel.dfaDefs.add(d); + } + + public BitSetDef defineFollowBitSet(GrammarAST ast, IntSet set) { String inRuleName = ast.nfaState.rule.name; String elementName = ast.getText(); // assume rule ref if ( ast.getType() == ANTLRParser.TOKEN_REF ) { - target.getTokenTypeAsTargetLabel(g, ast.getType() ); + elementName = target.getTokenTypeAsTargetLabel(g, g.tokenNameToTypeMap.get(elementName)); } - String name = "FOLLOW_"+elementName+"_in_"+inRuleName+ast.token.getTokenIndex(); - BitSetDef b = new BitSetDef(this, name, follow); + String name = "FOLLOW_"+elementName+"_in_"+inRuleName+"_"+ast.token.getTokenIndex(); + BitSetDef b = new BitSetDef(this, name, set); + outputModel.bitSetDefs.add(b); + return b; + } + + public BitSetDef defineTestBitSet(GrammarAST ast, IntSet set) { + String inRuleName = ast.nfaState.rule.name; + String name = "LOOK_in_"+inRuleName+"_"+ast.token.getTokenIndex(); + BitSetDef b = new BitSetDef(this, name, set); outputModel.bitSetDefs.add(b); return b; } diff --git a/tool/src/org/antlr/v4/codegen/OutputModelWalker.java b/tool/src/org/antlr/v4/codegen/OutputModelWalker.java index adf6ed8fa..8bbc166d7 100644 --- a/tool/src/org/antlr/v4/codegen/OutputModelWalker.java +++ b/tool/src/org/antlr/v4/codegen/OutputModelWalker.java @@ -73,9 +73,16 @@ public class OutputModelWalker { ST nestedST = walk(nestedOmo); st.add(fieldName, nestedST); } - else if ( o instanceof Collection ) { // LIST OF MODEL OBJECTS? + else if ( o instanceof Collection || o instanceof OutputModelObject[] ) { + // LIST OF MODEL OBJECTS? + if ( o instanceof OutputModelObject[] ) { + o = Arrays.asList((OutputModelObject[])o); + } Collection nestedOmos = (Collection)o; for (OutputModelObject nestedOmo : nestedOmos) { + if ( nestedOmo==null ) { + System.out.println("collection has nulls: "+nestedOmos); + } ST nestedST = walk(nestedOmo); st.add(fieldName, nestedST); } diff --git a/tool/src/org/antlr/v4/codegen/SourceGenTriggers.g b/tool/src/org/antlr/v4/codegen/SourceGenTriggers.g index dfaa9a3b7..022daade7 100644 --- a/tool/src/org/antlr/v4/codegen/SourceGenTriggers.g +++ b/tool/src/org/antlr/v4/codegen/SourceGenTriggers.g @@ -24,14 +24,14 @@ import java.util.HashMap; } } -block returns [CodeBlock omo] - : ^( BLOCK (^(OPTIONS .+))? +block[GrammarAST label, GrammarAST ebnfRoot] returns [SrcOp omo] + : ^( blk=BLOCK (^(OPTIONS .+))? {List alts = new ArrayList();} ( alternative {alts.add($alternative.omo);} )+ ) { - Choice c = new LL1Choice(gen, alts); // TODO: assumes LL1 - $omo = new CodeBlock(gen, c); + if ( alts.size()==1 && ebnfRoot==null) return alts.get(0); + $omo = gen.getChoiceBlock((BlockAST)$blk, $ebnfRoot, alts); } ; @@ -43,9 +43,9 @@ alternative returns [CodeBlock omo] ; element returns [SrcOp omo] - : labeledElement - | atom {$omo = $atom.omo;} - | ebnf + : labeledElement {$omo = $labeledElement.omo;} + | atom[null] {$omo = $atom.omo;} + | ebnf {$omo = $ebnf.omo;} | ACTION | SEMPRED | GATED_SEMPRED @@ -53,10 +53,10 @@ element returns [SrcOp omo] ; labeledElement returns [SrcOp omo] - : ^(ASSIGN ID atom ) - | ^(ASSIGN ID block) - | ^(PLUS_ASSIGN ID atom) - | ^(PLUS_ASSIGN ID block) + : ^(ASSIGN ID atom[$ID] ) {$omo = $atom.omo;} + | ^(ASSIGN ID block[$ID,null]) {$omo = $block.omo;} + | ^(PLUS_ASSIGN ID atom[$ID]) {$omo = $atom.omo;} + | ^(PLUS_ASSIGN ID block[$ID,null]) {$omo = $block.omo;} ; treeSpec returns [SrcOp omo] @@ -64,14 +64,12 @@ treeSpec returns [SrcOp omo] ; ebnf returns [SrcOp omo] - : ^(astBlockSuffix block) - | ^(OPTIONAL block) - - | ^(CLOSURE block) - - | ^(POSITIVE_CLOSURE block) - - | block + : ^(astBlockSuffix block[null,null]) + | ^(OPTIONAL block[null,$OPTIONAL]) {$omo = $block.omo;} + | ^(CLOSURE block[null,$CLOSURE]) {$omo = $block.omo;} + | ^(POSITIVE_CLOSURE block[null,$POSITIVE_CLOSURE]) + {$omo = $block.omo;} + | block[null, null] {$omo = $block.omo;} ; astBlockSuffix @@ -80,43 +78,44 @@ astBlockSuffix | BANG ; -atom returns [SrcOp omo] - : ^(ROOT range) - | ^(BANG range) - | ^(ROOT notSet) - | ^(BANG notSet) - | notSet - | range - | ^(DOT ID terminal) - | ^(DOT ID ruleref) +// TODO: combine ROOT/BANG into one then just make new op ref'ing return value of atom/terminal... +// TODO: same for NOT +atom[GrammarAST label] returns [SrcOp omo] + : ^(ROOT range[label]) + | ^(BANG range[label]) {$omo = $range.omo;} + | ^(ROOT notSet[label]) + | ^(BANG notSet[label]) {$omo = $notSet.omo;} + | notSet[label] + | range[label] {$omo = $range.omo;} + | ^(DOT ID terminal[label]) + | ^(DOT ID ruleref[label]) | ^(WILDCARD .) | WILDCARD - | terminal {$omo = $terminal.omo;} - | ruleref {$omo = $ruleref.omo;} + | terminal[label] {$omo = $terminal.omo;} + | ruleref[label] {$omo = $ruleref.omo;} ; -notSet returns [SrcOp omo] - : ^(NOT terminal) - | ^(NOT block) +notSet[GrammarAST label] returns [SrcOp omo] + : ^(NOT terminal[label]) + | ^(NOT block[label,null]) ; -ruleref returns [SrcOp omo] - : ^(ROOT ^(RULE_REF ARG_ACTION?)) - | ^(BANG ^(RULE_REF ARG_ACTION?)) - | ^(RULE_REF ARG_ACTION?) +ruleref[GrammarAST label] returns [SrcOp omo] + : ^(ROOT ^(RULE_REF ARG_ACTION?)) + | ^(BANG ^(RULE_REF ARG_ACTION?)) {$omo = new InvokeRule(gen, $RULE_REF, $label);} + | ^(RULE_REF ARG_ACTION?) {$omo = new InvokeRule(gen, $RULE_REF, $label);} ; -range returns [SrcOp omo] - : ^(RANGE a=STRING_LITERAL b=STRING_LITERAL) - +range[GrammarAST label] returns [SrcOp omo] + : ^(RANGE a=STRING_LITERAL b=STRING_LITERAL) ; -terminal returns [MatchToken omo] - : ^(STRING_LITERAL .) - | STRING_LITERAL - | ^(TOKEN_REF ARG_ACTION .) - | ^(TOKEN_REF .) - | TOKEN_REF {$omo = new MatchToken(gen, (TerminalAST)$TOKEN_REF);} - | ^(ROOT terminal) - | ^(BANG terminal) +terminal[GrammarAST label] returns [MatchToken omo] + : ^(STRING_LITERAL .) {$omo = new MatchToken(gen, (TerminalAST)$STRING_LITERAL, $label);} + | STRING_LITERAL {$omo = new MatchToken(gen, (TerminalAST)$STRING_LITERAL, $label);} + | ^(TOKEN_REF ARG_ACTION .) {$omo = new MatchToken(gen, (TerminalAST)$TOKEN_REF, $label);} + | ^(TOKEN_REF .) {$omo = new MatchToken(gen, (TerminalAST)$TOKEN_REF, $label);} + | TOKEN_REF {$omo = new MatchToken(gen, (TerminalAST)$TOKEN_REF, $label);} + | ^(ROOT terminal[label]) + | ^(BANG terminal[label]) ; diff --git a/tool/src/org/antlr/v4/codegen/SourceGenTriggers.java b/tool/src/org/antlr/v4/codegen/SourceGenTriggers.java new file mode 100644 index 000000000..48c3c0604 --- /dev/null +++ b/tool/src/org/antlr/v4/codegen/SourceGenTriggers.java @@ -0,0 +1,1843 @@ +// $ANTLR ${project.version} ${buildNumber} SourceGenTriggers.g 2010-05-09 16:47:55 + +package org.antlr.v4.codegen; + +import org.antlr.runtime.*; +import org.antlr.runtime.tree.TreeNodeStream; +import org.antlr.runtime.tree.TreeParser; +import org.antlr.v4.codegen.src.CodeBlock; +import org.antlr.v4.codegen.src.InvokeRule; +import org.antlr.v4.codegen.src.MatchToken; +import org.antlr.v4.codegen.src.SrcOp; +import org.antlr.v4.tool.BlockAST; +import org.antlr.v4.tool.GrammarAST; +import org.antlr.v4.tool.TerminalAST; + +import java.util.ArrayList; +import java.util.List; + +public class SourceGenTriggers extends TreeParser { + public static final String[] tokenNames = new String[] { + "", "", "", "", "SEMPRED", "FORCED_ACTION", "DOC_COMMENT", "SRC", "NLCHARS", "COMMENT", "DOUBLE_QUOTE_STRING_LITERAL", "DOUBLE_ANGLE_STRING_LITERAL", "ACTION_STRING_LITERAL", "ACTION_CHAR_LITERAL", "ARG_ACTION", "NESTED_ACTION", "ACTION", "ACTION_ESC", "WSNLCHARS", "OPTIONS", "TOKENS", "SCOPE", "IMPORT", "FRAGMENT", "LEXER", "PARSER", "TREE", "GRAMMAR", "PROTECTED", "PUBLIC", "PRIVATE", "RETURNS", "THROWS", "CATCH", "FINALLY", "TEMPLATE", "MODE", "COLON", "COLONCOLON", "COMMA", "SEMI", "LPAREN", "RPAREN", "IMPLIES", "LT", "GT", "ASSIGN", "QUESTION", "BANG", "STAR", "PLUS", "PLUS_ASSIGN", "OR", "ROOT", "DOLLAR", "DOT", "RANGE", "ETC", "RARROW", "TREE_BEGIN", "AT", "NOT", "RBRACE", "TOKEN_REF", "RULE_REF", "INT", "WSCHARS", "ESC_SEQ", "STRING_LITERAL", "HEX_DIGIT", "UNICODE_ESC", "WS", "ERRCHAR", "RULE", "RULES", "RULEMODIFIERS", "RULEACTIONS", "BLOCK", "REWRITE_BLOCK", "OPTIONAL", "CLOSURE", "POSITIVE_CLOSURE", "SYNPRED", "CHAR_RANGE", "EPSILON", "ALT", "ALTLIST", "ID", "ARG", "ARGLIST", "RET", "COMBINED", "INITACTION", "LABEL", "GATED_SEMPRED", "SYN_SEMPRED", "BACKTRACK_SEMPRED", "WILDCARD", "LIST", "ELEMENT_OPTIONS", "ST_RESULT", "RESULT", "ALT_REWRITE" + }; + public static final int COMBINED=91; + public static final int LT=44; + public static final int STAR=49; + public static final int BACKTRACK_SEMPRED=96; + public static final int DOUBLE_ANGLE_STRING_LITERAL=11; + public static final int FORCED_ACTION=5; + public static final int ARGLIST=89; + public static final int ALTLIST=86; + public static final int NOT=61; + public static final int EOF=-1; + public static final int SEMPRED=4; + public static final int ACTION=16; + public static final int TOKEN_REF=63; + public static final int RULEMODIFIERS=75; + public static final int ST_RESULT=100; + public static final int RPAREN=42; + public static final int RET=90; + public static final int IMPORT=22; + public static final int STRING_LITERAL=68; + public static final int ARG=88; + public static final int ARG_ACTION=14; + public static final int DOUBLE_QUOTE_STRING_LITERAL=10; + public static final int COMMENT=9; + public static final int ACTION_CHAR_LITERAL=13; + public static final int GRAMMAR=27; + public static final int RULEACTIONS=76; + public static final int WSCHARS=66; + public static final int INITACTION=92; + public static final int ALT_REWRITE=102; + public static final int IMPLIES=43; + public static final int RULE=73; + public static final int RBRACE=62; + public static final int ACTION_ESC=17; + public static final int PRIVATE=30; + public static final int SRC=7; + public static final int THROWS=32; + public static final int CHAR_RANGE=83; + public static final int INT=65; + public static final int EPSILON=84; + public static final int LIST=98; + public static final int COLONCOLON=38; + public static final int WSNLCHARS=18; + public static final int WS=71; + public static final int LEXER=24; + public static final int OR=52; + public static final int GT=45; + public static final int CATCH=33; + public static final int CLOSURE=80; + public static final int PARSER=25; + public static final int DOLLAR=54; + public static final int PROTECTED=28; + public static final int ELEMENT_OPTIONS=99; + public static final int NESTED_ACTION=15; + public static final int FRAGMENT=23; + public static final int ID=87; + public static final int TREE_BEGIN=59; + public static final int LPAREN=41; + public static final int AT=60; + public static final int ESC_SEQ=67; + public static final int ALT=85; + public static final int TREE=26; + public static final int SCOPE=21; + public static final int ETC=57; + public static final int COMMA=39; + public static final int WILDCARD=97; + public static final int DOC_COMMENT=6; + public static final int PLUS=50; + public static final int REWRITE_BLOCK=78; + public static final int DOT=55; + public static final int MODE=36; + public static final int RETURNS=31; + public static final int RULES=74; + public static final int RARROW=58; + public static final int UNICODE_ESC=70; + public static final int HEX_DIGIT=69; + public static final int RANGE=56; + public static final int TOKENS=20; + public static final int RESULT=101; + public static final int GATED_SEMPRED=94; + public static final int BANG=48; + public static final int ACTION_STRING_LITERAL=12; + public static final int ROOT=53; + public static final int SEMI=40; + public static final int RULE_REF=64; + public static final int NLCHARS=8; + public static final int OPTIONAL=79; + public static final int SYNPRED=82; + public static final int COLON=37; + public static final int QUESTION=47; + public static final int FINALLY=34; + public static final int TEMPLATE=35; + public static final int LABEL=93; + public static final int SYN_SEMPRED=95; + public static final int ERRCHAR=72; + public static final int BLOCK=77; + public static final int ASSIGN=46; + public static final int PLUS_ASSIGN=51; + public static final int PUBLIC=29; + public static final int POSITIVE_CLOSURE=81; + public static final int OPTIONS=19; + + // delegates + // delegators + + + public SourceGenTriggers(TreeNodeStream input) { + this(input, new RecognizerSharedState()); + } + public SourceGenTriggers(TreeNodeStream input, RecognizerSharedState state) { + super(input, state); + + } + + + public String[] getTokenNames() { return SourceGenTriggers.tokenNames; } + public String getGrammarFileName() { return "SourceGenTriggers.g"; } + + + // TODO: identical grammar to NFABytecodeTriggers; would be nice to combine + public CodeGenerator gen; + public SourceGenTriggers(TreeNodeStream input, CodeGenerator gen) { + this(input); + this.gen = gen; + } + + + + // $ANTLR start "block" + // SourceGenTriggers.g:27:1: block[GrammarAST label, GrammarAST ebnfRoot] returns [SrcOp omo] : ^(blk= BLOCK ( ^( OPTIONS ( . )+ ) )? ( alternative )+ ) ; + public final SrcOp block(GrammarAST label, GrammarAST ebnfRoot) throws RecognitionException { + SrcOp omo = null; + + GrammarAST blk=null; + CodeBlock alternative1 = null; + + + try { + // SourceGenTriggers.g:28:5: ( ^(blk= BLOCK ( ^( OPTIONS ( . )+ ) )? ( alternative )+ ) ) + // SourceGenTriggers.g:28:7: ^(blk= BLOCK ( ^( OPTIONS ( . )+ ) )? ( alternative )+ ) + { + blk=(GrammarAST)match(input,BLOCK,FOLLOW_BLOCK_in_block72); + + match(input, Token.DOWN, null); + // SourceGenTriggers.g:28:20: ( ^( OPTIONS ( . )+ ) )? + int alt2=2; + int LA2_0 = input.LA(1); + + if ( (LA2_0==OPTIONS) ) { + alt2=1; + } + switch (alt2) { + case 1 : + // SourceGenTriggers.g:28:21: ^( OPTIONS ( . )+ ) + { + match(input,OPTIONS,FOLLOW_OPTIONS_in_block76); + + match(input, Token.DOWN, null); + // SourceGenTriggers.g:28:31: ( . )+ + int cnt1=0; + loop1: + do { + int alt1=2; + int LA1_0 = input.LA(1); + + if ( ((LA1_0>=SEMPRED && LA1_0<=ALT_REWRITE)) ) { + alt1=1; + } + else if ( (LA1_0==UP) ) { + alt1=2; + } + + + switch (alt1) { + case 1 : + // SourceGenTriggers.g:28:31: . + { + matchAny(input); + + } + break; + + default : + if ( cnt1 >= 1 ) break loop1; + EarlyExitException eee = + new EarlyExitException(1, input); + throw eee; + } + cnt1++; + } while (true); + + + match(input, Token.UP, null); + + } + break; + + } + + List alts = new ArrayList(); + // SourceGenTriggers.g:30:7: ( alternative )+ + int cnt3=0; + loop3: + do { + int alt3=2; + int LA3_0 = input.LA(1); + + if ( (LA3_0==ALT||LA3_0==ALT_REWRITE) ) { + alt3=1; + } + + + switch (alt3) { + case 1 : + // SourceGenTriggers.g:30:9: alternative + { + pushFollow(FOLLOW_alternative_in_block96); + alternative1=alternative(); + + state._fsp--; + + alts.add(alternative1); + + } + break; + + default : + if ( cnt3 >= 1 ) break loop3; + EarlyExitException eee = + new EarlyExitException(3, input); + throw eee; + } + cnt3++; + } while (true); + + + match(input, Token.UP, null); + + if ( alts.size()==1 && ebnfRoot==null) return alts.get(0); + omo = gen.getChoiceBlock((BlockAST)blk, ebnfRoot, alts); + + + } + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + } + return omo; + } + // $ANTLR end "block" + + + // $ANTLR start "alternative" + // SourceGenTriggers.g:38:1: alternative returns [CodeBlock omo] : ( ^( ALT_REWRITE a= alternative . ) | ^( ALT EPSILON ) | ^( ALT ( element )+ ) ); + public final CodeBlock alternative() throws RecognitionException { + CodeBlock omo = null; + + CodeBlock a = null; + + SrcOp element2 = null; + + + List elems = new ArrayList(); + try { + // SourceGenTriggers.g:40:5: ( ^( ALT_REWRITE a= alternative . ) | ^( ALT EPSILON ) | ^( ALT ( element )+ ) ) + int alt5=3; + int LA5_0 = input.LA(1); + + if ( (LA5_0==ALT_REWRITE) ) { + alt5=1; + } + else if ( (LA5_0==ALT) ) { + int LA5_2 = input.LA(2); + + if ( (LA5_2==DOWN) ) { + int LA5_3 = input.LA(3); + + if ( (LA5_3==EPSILON) ) { + alt5=2; + } + else if ( (LA5_3==SEMPRED||LA5_3==ACTION||LA5_3==IMPLIES||LA5_3==ASSIGN||LA5_3==BANG||LA5_3==PLUS_ASSIGN||LA5_3==ROOT||(LA5_3>=DOT && LA5_3<=RANGE)||LA5_3==TREE_BEGIN||LA5_3==NOT||(LA5_3>=TOKEN_REF && LA5_3<=RULE_REF)||LA5_3==STRING_LITERAL||LA5_3==BLOCK||(LA5_3>=OPTIONAL && LA5_3<=POSITIVE_CLOSURE)||LA5_3==GATED_SEMPRED||LA5_3==WILDCARD) ) { + alt5=3; + } + else { + NoViableAltException nvae = + new NoViableAltException("", 5, 3, input); + + throw nvae; + } + } + else { + NoViableAltException nvae = + new NoViableAltException("", 5, 2, input); + + throw nvae; + } + } + else { + NoViableAltException nvae = + new NoViableAltException("", 5, 0, input); + + throw nvae; + } + switch (alt5) { + case 1 : + // SourceGenTriggers.g:40:7: ^( ALT_REWRITE a= alternative . ) + { + match(input,ALT_REWRITE,FOLLOW_ALT_REWRITE_in_alternative142); + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_alternative_in_alternative146); + a=alternative(); + + state._fsp--; + + matchAny(input); + + match(input, Token.UP, null); + + } + break; + case 2 : + // SourceGenTriggers.g:41:7: ^( ALT EPSILON ) + { + match(input,ALT,FOLLOW_ALT_in_alternative159); + + match(input, Token.DOWN, null); + match(input,EPSILON,FOLLOW_EPSILON_in_alternative161); + + match(input, Token.UP, null); + omo = new CodeBlock(gen); + + } + break; + case 3 : + // SourceGenTriggers.g:42:9: ^( ALT ( element )+ ) + { + match(input,ALT,FOLLOW_ALT_in_alternative176); + + match(input, Token.DOWN, null); + // SourceGenTriggers.g:42:16: ( element )+ + int cnt4=0; + loop4: + do { + int alt4=2; + int LA4_0 = input.LA(1); + + if ( (LA4_0==SEMPRED||LA4_0==ACTION||LA4_0==IMPLIES||LA4_0==ASSIGN||LA4_0==BANG||LA4_0==PLUS_ASSIGN||LA4_0==ROOT||(LA4_0>=DOT && LA4_0<=RANGE)||LA4_0==TREE_BEGIN||LA4_0==NOT||(LA4_0>=TOKEN_REF && LA4_0<=RULE_REF)||LA4_0==STRING_LITERAL||LA4_0==BLOCK||(LA4_0>=OPTIONAL && LA4_0<=POSITIVE_CLOSURE)||LA4_0==GATED_SEMPRED||LA4_0==WILDCARD) ) { + alt4=1; + } + + + switch (alt4) { + case 1 : + // SourceGenTriggers.g:42:18: element + { + pushFollow(FOLLOW_element_in_alternative180); + element2=element(); + + state._fsp--; + + elems.add(element2); + + } + break; + + default : + if ( cnt4 >= 1 ) break loop4; + EarlyExitException eee = + new EarlyExitException(4, input); + throw eee; + } + cnt4++; + } while (true); + + + match(input, Token.UP, null); + omo = new CodeBlock(gen, elems); + + } + break; + + } + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + } + return omo; + } + // $ANTLR end "alternative" + + + // $ANTLR start "element" + // SourceGenTriggers.g:45:1: element returns [SrcOp omo] : ( labeledElement | atom[null] | ebnf | ACTION | SEMPRED | GATED_SEMPRED | treeSpec ); + public final SrcOp element() throws RecognitionException { + SrcOp omo = null; + + SrcOp labeledElement3 = null; + + SrcOp atom4 = null; + + SrcOp ebnf5 = null; + + + try { + // SourceGenTriggers.g:46:2: ( labeledElement | atom[null] | ebnf | ACTION | SEMPRED | GATED_SEMPRED | treeSpec ) + int alt6=7; + alt6 = dfa6.predict(input); + switch (alt6) { + case 1 : + // SourceGenTriggers.g:46:4: labeledElement + { + pushFollow(FOLLOW_labeledElement_in_element207); + labeledElement3=labeledElement(); + + state._fsp--; + + omo = labeledElement3; + + } + break; + case 2 : + // SourceGenTriggers.g:47:4: atom[null] + { + pushFollow(FOLLOW_atom_in_element218); + atom4=atom(null); + + state._fsp--; + + omo = atom4; + + } + break; + case 3 : + // SourceGenTriggers.g:48:4: ebnf + { + pushFollow(FOLLOW_ebnf_in_element231); + ebnf5=ebnf(); + + state._fsp--; + + omo = ebnf5; + + } + break; + case 4 : + // SourceGenTriggers.g:49:6: ACTION + { + match(input,ACTION,FOLLOW_ACTION_in_element252); + + } + break; + case 5 : + // SourceGenTriggers.g:50:6: SEMPRED + { + match(input,SEMPRED,FOLLOW_SEMPRED_in_element265); + + } + break; + case 6 : + // SourceGenTriggers.g:51:4: GATED_SEMPRED + { + match(input,GATED_SEMPRED,FOLLOW_GATED_SEMPRED_in_element275); + + } + break; + case 7 : + // SourceGenTriggers.g:52:4: treeSpec + { + pushFollow(FOLLOW_treeSpec_in_element281); + treeSpec(); + + state._fsp--; + + + } + break; + + } + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + } + return omo; + } + // $ANTLR end "element" + + + // $ANTLR start "labeledElement" + // SourceGenTriggers.g:55:1: labeledElement returns [SrcOp omo] : ( ^( ASSIGN ID atom[$ID] ) | ^( ASSIGN ID block[$ID,null] ) | ^( PLUS_ASSIGN ID atom[$ID] ) | ^( PLUS_ASSIGN ID block[$ID,null] ) ); + public final SrcOp labeledElement() throws RecognitionException { + SrcOp omo = null; + + GrammarAST ID6=null; + GrammarAST ID8=null; + GrammarAST ID10=null; + GrammarAST ID12=null; + SrcOp atom7 = null; + + SrcOp block9 = null; + + SrcOp atom11 = null; + + SrcOp block13 = null; + + + try { + // SourceGenTriggers.g:56:2: ( ^( ASSIGN ID atom[$ID] ) | ^( ASSIGN ID block[$ID,null] ) | ^( PLUS_ASSIGN ID atom[$ID] ) | ^( PLUS_ASSIGN ID block[$ID,null] ) ) + int alt7=4; + alt7 = dfa7.predict(input); + switch (alt7) { + case 1 : + // SourceGenTriggers.g:56:4: ^( ASSIGN ID atom[$ID] ) + { + match(input,ASSIGN,FOLLOW_ASSIGN_in_labeledElement303); + + match(input, Token.DOWN, null); + ID6=(GrammarAST)match(input,ID,FOLLOW_ID_in_labeledElement305); + pushFollow(FOLLOW_atom_in_labeledElement307); + atom7=atom(ID6); + + state._fsp--; + + + match(input, Token.UP, null); + omo = atom7; + + } + break; + case 2 : + // SourceGenTriggers.g:57:4: ^( ASSIGN ID block[$ID,null] ) + { + match(input,ASSIGN,FOLLOW_ASSIGN_in_labeledElement321); + + match(input, Token.DOWN, null); + ID8=(GrammarAST)match(input,ID,FOLLOW_ID_in_labeledElement323); + pushFollow(FOLLOW_block_in_labeledElement325); + block9=block(ID8, null); + + state._fsp--; + + + match(input, Token.UP, null); + omo = block9; + + } + break; + case 3 : + // SourceGenTriggers.g:58:4: ^( PLUS_ASSIGN ID atom[$ID] ) + { + match(input,PLUS_ASSIGN,FOLLOW_PLUS_ASSIGN_in_labeledElement336); + + match(input, Token.DOWN, null); + ID10=(GrammarAST)match(input,ID,FOLLOW_ID_in_labeledElement338); + pushFollow(FOLLOW_atom_in_labeledElement340); + atom11=atom(ID10); + + state._fsp--; + + + match(input, Token.UP, null); + omo = atom11; + + } + break; + case 4 : + // SourceGenTriggers.g:59:4: ^( PLUS_ASSIGN ID block[$ID,null] ) + { + match(input,PLUS_ASSIGN,FOLLOW_PLUS_ASSIGN_in_labeledElement352); + + match(input, Token.DOWN, null); + ID12=(GrammarAST)match(input,ID,FOLLOW_ID_in_labeledElement354); + pushFollow(FOLLOW_block_in_labeledElement356); + block13=block(ID12, null); + + state._fsp--; + + + match(input, Token.UP, null); + omo = block13; + + } + break; + + } + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + } + return omo; + } + // $ANTLR end "labeledElement" + + + // $ANTLR start "treeSpec" + // SourceGenTriggers.g:62:1: treeSpec returns [SrcOp omo] : ^( TREE_BEGIN (e= element )+ ) ; + public final SrcOp treeSpec() throws RecognitionException { + SrcOp omo = null; + + SrcOp e = null; + + + try { + // SourceGenTriggers.g:63:5: ( ^( TREE_BEGIN (e= element )+ ) ) + // SourceGenTriggers.g:63:7: ^( TREE_BEGIN (e= element )+ ) + { + match(input,TREE_BEGIN,FOLLOW_TREE_BEGIN_in_treeSpec380); + + match(input, Token.DOWN, null); + // SourceGenTriggers.g:63:21: (e= element )+ + int cnt8=0; + loop8: + do { + int alt8=2; + int LA8_0 = input.LA(1); + + if ( (LA8_0==SEMPRED||LA8_0==ACTION||LA8_0==IMPLIES||LA8_0==ASSIGN||LA8_0==BANG||LA8_0==PLUS_ASSIGN||LA8_0==ROOT||(LA8_0>=DOT && LA8_0<=RANGE)||LA8_0==TREE_BEGIN||LA8_0==NOT||(LA8_0>=TOKEN_REF && LA8_0<=RULE_REF)||LA8_0==STRING_LITERAL||LA8_0==BLOCK||(LA8_0>=OPTIONAL && LA8_0<=POSITIVE_CLOSURE)||LA8_0==GATED_SEMPRED||LA8_0==WILDCARD) ) { + alt8=1; + } + + + switch (alt8) { + case 1 : + // SourceGenTriggers.g:63:22: e= element + { + pushFollow(FOLLOW_element_in_treeSpec386); + e=element(); + + state._fsp--; + + + } + break; + + default : + if ( cnt8 >= 1 ) break loop8; + EarlyExitException eee = + new EarlyExitException(8, input); + throw eee; + } + cnt8++; + } while (true); + + + match(input, Token.UP, null); + + } + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + } + return omo; + } + // $ANTLR end "treeSpec" + + + // $ANTLR start "ebnf" + // SourceGenTriggers.g:66:1: ebnf returns [SrcOp omo] : ( ^( astBlockSuffix block[null,null] ) | ^( OPTIONAL block[null,$OPTIONAL] ) | ^( CLOSURE block[null,$CLOSURE] ) | ^( POSITIVE_CLOSURE block[null,$POSITIVE_CLOSURE] ) | block[null, null] ); + public final SrcOp ebnf() throws RecognitionException { + SrcOp omo = null; + + GrammarAST OPTIONAL14=null; + GrammarAST CLOSURE16=null; + GrammarAST POSITIVE_CLOSURE18=null; + SrcOp block15 = null; + + SrcOp block17 = null; + + SrcOp block19 = null; + + SrcOp block20 = null; + + + try { + // SourceGenTriggers.g:67:2: ( ^( astBlockSuffix block[null,null] ) | ^( OPTIONAL block[null,$OPTIONAL] ) | ^( CLOSURE block[null,$CLOSURE] ) | ^( POSITIVE_CLOSURE block[null,$POSITIVE_CLOSURE] ) | block[null, null] ) + int alt9=5; + switch ( input.LA(1) ) { + case IMPLIES: + case BANG: + case ROOT: + { + alt9=1; + } + break; + case OPTIONAL: + { + alt9=2; + } + break; + case CLOSURE: + { + alt9=3; + } + break; + case POSITIVE_CLOSURE: + { + alt9=4; + } + break; + case BLOCK: + { + alt9=5; + } + break; + default: + NoViableAltException nvae = + new NoViableAltException("", 9, 0, input); + + throw nvae; + } + + switch (alt9) { + case 1 : + // SourceGenTriggers.g:67:4: ^( astBlockSuffix block[null,null] ) + { + pushFollow(FOLLOW_astBlockSuffix_in_ebnf410); + astBlockSuffix(); + + state._fsp--; + + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_block_in_ebnf412); + block(null, null); + + state._fsp--; + + + match(input, Token.UP, null); + + } + break; + case 2 : + // SourceGenTriggers.g:68:4: ^( OPTIONAL block[null,$OPTIONAL] ) + { + OPTIONAL14=(GrammarAST)match(input,OPTIONAL,FOLLOW_OPTIONAL_in_ebnf422); + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_block_in_ebnf424); + block15=block(null, OPTIONAL14); + + state._fsp--; + + + match(input, Token.UP, null); + omo = block15; + + } + break; + case 3 : + // SourceGenTriggers.g:69:4: ^( CLOSURE block[null,$CLOSURE] ) + { + CLOSURE16=(GrammarAST)match(input,CLOSURE,FOLLOW_CLOSURE_in_ebnf436); + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_block_in_ebnf438); + block17=block(null, CLOSURE16); + + state._fsp--; + + + match(input, Token.UP, null); + omo = block17; + + } + break; + case 4 : + // SourceGenTriggers.g:70:4: ^( POSITIVE_CLOSURE block[null,$POSITIVE_CLOSURE] ) + { + POSITIVE_CLOSURE18=(GrammarAST)match(input,POSITIVE_CLOSURE,FOLLOW_POSITIVE_CLOSURE_in_ebnf451); + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_block_in_ebnf453); + block19=block(null, POSITIVE_CLOSURE18); + + state._fsp--; + + + match(input, Token.UP, null); + omo = block19; + + } + break; + case 5 : + // SourceGenTriggers.g:72:5: block[null, null] + { + pushFollow(FOLLOW_block_in_ebnf477); + block20=block(null, null); + + state._fsp--; + + omo = block20; + + } + break; + + } + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + } + return omo; + } + // $ANTLR end "ebnf" + + + // $ANTLR start "astBlockSuffix" + // SourceGenTriggers.g:75:1: astBlockSuffix : ( ROOT | IMPLIES | BANG ); + public final void astBlockSuffix() throws RecognitionException { + try { + // SourceGenTriggers.g:76:5: ( ROOT | IMPLIES | BANG ) + // SourceGenTriggers.g: + { + if ( input.LA(1)==IMPLIES||input.LA(1)==BANG||input.LA(1)==ROOT ) { + input.consume(); + state.errorRecovery=false; + } + else { + MismatchedSetException mse = new MismatchedSetException(null,input); + throw mse; + } + + + } + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + } + return ; + } + // $ANTLR end "astBlockSuffix" + + + // $ANTLR start "atom" + // SourceGenTriggers.g:83:1: atom[GrammarAST label] returns [SrcOp omo] : ( ^( ROOT range[label] ) | ^( BANG range[label] ) | ^( ROOT notSet[label] ) | ^( BANG notSet[label] ) | notSet[label] | range[label] | ^( DOT ID terminal[label] ) | ^( DOT ID ruleref[label] ) | ^( WILDCARD . ) | WILDCARD | terminal[label] | ruleref[label] ); + public final SrcOp atom(GrammarAST label) throws RecognitionException { + SrcOp omo = null; + + SrcOp range21 = null; + + SrcOp notSet22 = null; + + SrcOp range23 = null; + + MatchToken terminal24 = null; + + SrcOp ruleref25 = null; + + + try { + // SourceGenTriggers.g:84:2: ( ^( ROOT range[label] ) | ^( BANG range[label] ) | ^( ROOT notSet[label] ) | ^( BANG notSet[label] ) | notSet[label] | range[label] | ^( DOT ID terminal[label] ) | ^( DOT ID ruleref[label] ) | ^( WILDCARD . ) | WILDCARD | terminal[label] | ruleref[label] ) + int alt10=12; + alt10 = dfa10.predict(input); + switch (alt10) { + case 1 : + // SourceGenTriggers.g:84:4: ^( ROOT range[label] ) + { + match(input,ROOT,FOLLOW_ROOT_in_atom539); + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_range_in_atom541); + range(label); + + state._fsp--; + + + match(input, Token.UP, null); + + } + break; + case 2 : + // SourceGenTriggers.g:85:4: ^( BANG range[label] ) + { + match(input,BANG,FOLLOW_BANG_in_atom552); + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_range_in_atom554); + range21=range(label); + + state._fsp--; + + + match(input, Token.UP, null); + omo = range21; + + } + break; + case 3 : + // SourceGenTriggers.g:86:4: ^( ROOT notSet[label] ) + { + match(input,ROOT,FOLLOW_ROOT_in_atom566); + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_notSet_in_atom568); + notSet(label); + + state._fsp--; + + + match(input, Token.UP, null); + + } + break; + case 4 : + // SourceGenTriggers.g:87:4: ^( BANG notSet[label] ) + { + match(input,BANG,FOLLOW_BANG_in_atom579); + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_notSet_in_atom581); + notSet22=notSet(label); + + state._fsp--; + + + match(input, Token.UP, null); + omo = notSet22; + + } + break; + case 5 : + // SourceGenTriggers.g:88:4: notSet[label] + { + pushFollow(FOLLOW_notSet_in_atom592); + notSet(label); + + state._fsp--; + + + } + break; + case 6 : + // SourceGenTriggers.g:89:4: range[label] + { + pushFollow(FOLLOW_range_in_atom603); + range23=range(label); + + state._fsp--; + + omo = range23; + + } + break; + case 7 : + // SourceGenTriggers.g:90:4: ^( DOT ID terminal[label] ) + { + match(input,DOT,FOLLOW_DOT_in_atom616); + + match(input, Token.DOWN, null); + match(input,ID,FOLLOW_ID_in_atom618); + pushFollow(FOLLOW_terminal_in_atom620); + terminal(label); + + state._fsp--; + + + match(input, Token.UP, null); + + } + break; + case 8 : + // SourceGenTriggers.g:91:4: ^( DOT ID ruleref[label] ) + { + match(input,DOT,FOLLOW_DOT_in_atom628); + + match(input, Token.DOWN, null); + match(input,ID,FOLLOW_ID_in_atom630); + pushFollow(FOLLOW_ruleref_in_atom632); + ruleref(label); + + state._fsp--; + + + match(input, Token.UP, null); + + } + break; + case 9 : + // SourceGenTriggers.g:92:7: ^( WILDCARD . ) + { + match(input,WILDCARD,FOLLOW_WILDCARD_in_atom643); + + match(input, Token.DOWN, null); + matchAny(input); + + match(input, Token.UP, null); + + } + break; + case 10 : + // SourceGenTriggers.g:93:7: WILDCARD + { + match(input,WILDCARD,FOLLOW_WILDCARD_in_atom658); + + } + break; + case 11 : + // SourceGenTriggers.g:94:9: terminal[label] + { + pushFollow(FOLLOW_terminal_in_atom672); + terminal24=terminal(label); + + state._fsp--; + + omo = terminal24; + + } + break; + case 12 : + // SourceGenTriggers.g:95:9: ruleref[label] + { + pushFollow(FOLLOW_ruleref_in_atom688); + ruleref25=ruleref(label); + + state._fsp--; + + omo = ruleref25; + + } + break; + + } + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + } + return omo; + } + // $ANTLR end "atom" + + + // $ANTLR start "notSet" + // SourceGenTriggers.g:98:1: notSet[GrammarAST label] returns [SrcOp omo] : ( ^( NOT terminal[label] ) | ^( NOT block[label,null] ) ); + public final SrcOp notSet(GrammarAST label) throws RecognitionException { + SrcOp omo = null; + + try { + // SourceGenTriggers.g:99:5: ( ^( NOT terminal[label] ) | ^( NOT block[label,null] ) ) + int alt11=2; + int LA11_0 = input.LA(1); + + if ( (LA11_0==NOT) ) { + int LA11_1 = input.LA(2); + + if ( (LA11_1==DOWN) ) { + int LA11_2 = input.LA(3); + + if ( (LA11_2==BLOCK) ) { + alt11=2; + } + else if ( (LA11_2==BANG||LA11_2==ROOT||LA11_2==TOKEN_REF||LA11_2==STRING_LITERAL) ) { + alt11=1; + } + else { + NoViableAltException nvae = + new NoViableAltException("", 11, 2, input); + + throw nvae; + } + } + else { + NoViableAltException nvae = + new NoViableAltException("", 11, 1, input); + + throw nvae; + } + } + else { + NoViableAltException nvae = + new NoViableAltException("", 11, 0, input); + + throw nvae; + } + switch (alt11) { + case 1 : + // SourceGenTriggers.g:99:7: ^( NOT terminal[label] ) + { + match(input,NOT,FOLLOW_NOT_in_notSet717); + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_terminal_in_notSet719); + terminal(label); + + state._fsp--; + + + match(input, Token.UP, null); + + } + break; + case 2 : + // SourceGenTriggers.g:100:7: ^( NOT block[label,null] ) + { + match(input,NOT,FOLLOW_NOT_in_notSet732); + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_block_in_notSet734); + block(label, null); + + state._fsp--; + + + match(input, Token.UP, null); + + } + break; + + } + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + } + return omo; + } + // $ANTLR end "notSet" + + + // $ANTLR start "ruleref" + // SourceGenTriggers.g:103:1: ruleref[GrammarAST label] returns [SrcOp omo] : ( ^( ROOT ^( RULE_REF ( ARG_ACTION )? ) ) | ^( BANG ^( RULE_REF ( ARG_ACTION )? ) ) | ^( RULE_REF ( ARG_ACTION )? ) ); + public final SrcOp ruleref(GrammarAST label) throws RecognitionException { + SrcOp omo = null; + + GrammarAST RULE_REF26=null; + GrammarAST RULE_REF27=null; + + try { + // SourceGenTriggers.g:104:5: ( ^( ROOT ^( RULE_REF ( ARG_ACTION )? ) ) | ^( BANG ^( RULE_REF ( ARG_ACTION )? ) ) | ^( RULE_REF ( ARG_ACTION )? ) ) + int alt15=3; + switch ( input.LA(1) ) { + case ROOT: + { + alt15=1; + } + break; + case BANG: + { + alt15=2; + } + break; + case RULE_REF: + { + alt15=3; + } + break; + default: + NoViableAltException nvae = + new NoViableAltException("", 15, 0, input); + + throw nvae; + } + + switch (alt15) { + case 1 : + // SourceGenTriggers.g:104:7: ^( ROOT ^( RULE_REF ( ARG_ACTION )? ) ) + { + match(input,ROOT,FOLLOW_ROOT_in_ruleref762); + + match(input, Token.DOWN, null); + match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref765); + + if ( input.LA(1)==Token.DOWN ) { + match(input, Token.DOWN, null); + // SourceGenTriggers.g:104:25: ( ARG_ACTION )? + int alt12=2; + int LA12_0 = input.LA(1); + + if ( (LA12_0==ARG_ACTION) ) { + alt12=1; + } + switch (alt12) { + case 1 : + // SourceGenTriggers.g:104:25: ARG_ACTION + { + match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref767); + + } + break; + + } + + + match(input, Token.UP, null); + } + + match(input, Token.UP, null); + + } + break; + case 2 : + // SourceGenTriggers.g:105:7: ^( BANG ^( RULE_REF ( ARG_ACTION )? ) ) + { + match(input,BANG,FOLLOW_BANG_in_ruleref779); + + match(input, Token.DOWN, null); + RULE_REF26=(GrammarAST)match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref782); + + if ( input.LA(1)==Token.DOWN ) { + match(input, Token.DOWN, null); + // SourceGenTriggers.g:105:25: ( ARG_ACTION )? + int alt13=2; + int LA13_0 = input.LA(1); + + if ( (LA13_0==ARG_ACTION) ) { + alt13=1; + } + switch (alt13) { + case 1 : + // SourceGenTriggers.g:105:25: ARG_ACTION + { + match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref784); + + } + break; + + } + + + match(input, Token.UP, null); + } + + match(input, Token.UP, null); + omo = new InvokeRule(gen, RULE_REF26, label); + + } + break; + case 3 : + // SourceGenTriggers.g:106:7: ^( RULE_REF ( ARG_ACTION )? ) + { + RULE_REF27=(GrammarAST)match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref798); + + if ( input.LA(1)==Token.DOWN ) { + match(input, Token.DOWN, null); + // SourceGenTriggers.g:106:18: ( ARG_ACTION )? + int alt14=2; + int LA14_0 = input.LA(1); + + if ( (LA14_0==ARG_ACTION) ) { + alt14=1; + } + switch (alt14) { + case 1 : + // SourceGenTriggers.g:106:18: ARG_ACTION + { + match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref800); + + } + break; + + } + + + match(input, Token.UP, null); + } + omo = new InvokeRule(gen, RULE_REF27, label); + + } + break; + + } + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + } + return omo; + } + // $ANTLR end "ruleref" + + + // $ANTLR start "range" + // SourceGenTriggers.g:109:1: range[GrammarAST label] returns [SrcOp omo] : ^( RANGE a= STRING_LITERAL b= STRING_LITERAL ) ; + public final SrcOp range(GrammarAST label) throws RecognitionException { + SrcOp omo = null; + + GrammarAST a=null; + GrammarAST b=null; + + try { + // SourceGenTriggers.g:110:5: ( ^( RANGE a= STRING_LITERAL b= STRING_LITERAL ) ) + // SourceGenTriggers.g:110:7: ^( RANGE a= STRING_LITERAL b= STRING_LITERAL ) + { + match(input,RANGE,FOLLOW_RANGE_in_range829); + + match(input, Token.DOWN, null); + a=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range833); + b=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range837); + + match(input, Token.UP, null); + + } + + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + } + return omo; + } + // $ANTLR end "range" + + + // $ANTLR start "terminal" + // SourceGenTriggers.g:113:1: terminal[GrammarAST label] returns [MatchToken omo] : ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal[label] ) | ^( BANG terminal[label] ) ); + public final MatchToken terminal(GrammarAST label) throws RecognitionException { + MatchToken omo = null; + + GrammarAST STRING_LITERAL28=null; + GrammarAST STRING_LITERAL29=null; + GrammarAST TOKEN_REF30=null; + GrammarAST TOKEN_REF31=null; + GrammarAST TOKEN_REF32=null; + + try { + // SourceGenTriggers.g:114:5: ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal[label] ) | ^( BANG terminal[label] ) ) + int alt16=7; + alt16 = dfa16.predict(input); + switch (alt16) { + case 1 : + // SourceGenTriggers.g:114:8: ^( STRING_LITERAL . ) + { + STRING_LITERAL28=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal867); + + match(input, Token.DOWN, null); + matchAny(input); + + match(input, Token.UP, null); + omo = new MatchToken(gen, (TerminalAST)STRING_LITERAL28, label); + + } + break; + case 2 : + // SourceGenTriggers.g:115:7: STRING_LITERAL + { + STRING_LITERAL29=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal882); + omo = new MatchToken(gen, (TerminalAST)STRING_LITERAL29, label); + + } + break; + case 3 : + // SourceGenTriggers.g:116:7: ^( TOKEN_REF ARG_ACTION . ) + { + TOKEN_REF30=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal896); + + match(input, Token.DOWN, null); + match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_terminal898); + matchAny(input); + + match(input, Token.UP, null); + omo = new MatchToken(gen, (TerminalAST)TOKEN_REF30, label); + + } + break; + case 4 : + // SourceGenTriggers.g:117:7: ^( TOKEN_REF . ) + { + TOKEN_REF31=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal912); + + match(input, Token.DOWN, null); + matchAny(input); + + match(input, Token.UP, null); + omo = new MatchToken(gen, (TerminalAST)TOKEN_REF31, label); + + } + break; + case 5 : + // SourceGenTriggers.g:118:7: TOKEN_REF + { + TOKEN_REF32=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal928); + omo = new MatchToken(gen, (TerminalAST)TOKEN_REF32, label); + + } + break; + case 6 : + // SourceGenTriggers.g:119:7: ^( ROOT terminal[label] ) + { + match(input,ROOT,FOLLOW_ROOT_in_terminal943); + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_terminal_in_terminal945); + terminal(label); + + state._fsp--; + + + match(input, Token.UP, null); + + } + break; + case 7 : + // SourceGenTriggers.g:120:7: ^( BANG terminal[label] ) + { + match(input,BANG,FOLLOW_BANG_in_terminal959); + + match(input, Token.DOWN, null); + pushFollow(FOLLOW_terminal_in_terminal961); + terminal(label); + + state._fsp--; + + + match(input, Token.UP, null); + + } + break; + + } + } + catch (RecognitionException re) { + reportError(re); + recover(input,re); + } + finally { + } + return omo; + } + // $ANTLR end "terminal" + + // Delegated rules + + + protected DFA6 dfa6 = new DFA6(this); + protected DFA7 dfa7 = new DFA7(this); + protected DFA10 dfa10 = new DFA10(this); + protected DFA16 dfa16 = new DFA16(this); + static final String DFA6_eotS = + "\14\uffff"; + static final String DFA6_eofS = + "\14\uffff"; + static final String DFA6_minS = + "\1\4\1\uffff\2\2\6\uffff\2\60"; + static final String DFA6_maxS = + "\1\141\1\uffff\2\2\6\uffff\2\115"; + static final String DFA6_acceptS = + "\1\uffff\1\1\2\uffff\1\2\1\3\1\4\1\5\1\6\1\7\2\uffff"; + static final String DFA6_specialS = + "\14\uffff}>"; + static final String[] DFA6_transitionS = { + "\1\7\13\uffff\1\6\32\uffff\1\5\2\uffff\1\1\1\uffff\1\3\2\uffff"+ + "\1\1\1\uffff\1\2\1\uffff\2\4\2\uffff\1\11\1\uffff\1\4\1\uffff"+ + "\2\4\3\uffff\1\4\10\uffff\1\5\1\uffff\3\5\14\uffff\1\10\2\uffff"+ + "\1\4", + "", + "\1\12", + "\1\13", + "", + "", + "", + "", + "", + "", + "\1\4\4\uffff\1\4\2\uffff\1\4\4\uffff\1\4\1\uffff\2\4\3\uffff"+ + "\1\4\10\uffff\1\5", + "\1\4\4\uffff\1\4\2\uffff\1\4\4\uffff\1\4\1\uffff\2\4\3\uffff"+ + "\1\4\10\uffff\1\5" + }; + + static final short[] DFA6_eot = DFA.unpackEncodedString(DFA6_eotS); + static final short[] DFA6_eof = DFA.unpackEncodedString(DFA6_eofS); + static final char[] DFA6_min = DFA.unpackEncodedStringToUnsignedChars(DFA6_minS); + static final char[] DFA6_max = DFA.unpackEncodedStringToUnsignedChars(DFA6_maxS); + static final short[] DFA6_accept = DFA.unpackEncodedString(DFA6_acceptS); + static final short[] DFA6_special = DFA.unpackEncodedString(DFA6_specialS); + static final short[][] DFA6_transition; + + static { + int numStates = DFA6_transitionS.length; + DFA6_transition = new short[numStates][]; + for (int i=0; i"; + static final String[] DFA7_transitionS = { + "\1\1\4\uffff\1\2", + "\1\3", + "\1\4", + "\1\5", + "\1\6", + "\1\10\4\uffff\1\10\1\uffff\2\10\4\uffff\1\10\1\uffff\2\10\3"+ + "\uffff\1\10\10\uffff\1\7\23\uffff\1\10", + "\1\12\4\uffff\1\12\1\uffff\2\12\4\uffff\1\12\1\uffff\2\12\3"+ + "\uffff\1\12\10\uffff\1\11\23\uffff\1\12", + "", + "", + "", + "" + }; + + static final short[] DFA7_eot = DFA.unpackEncodedString(DFA7_eotS); + static final short[] DFA7_eof = DFA.unpackEncodedString(DFA7_eofS); + static final char[] DFA7_min = DFA.unpackEncodedStringToUnsignedChars(DFA7_minS); + static final char[] DFA7_max = DFA.unpackEncodedStringToUnsignedChars(DFA7_maxS); + static final short[] DFA7_accept = DFA.unpackEncodedString(DFA7_acceptS); + static final short[] DFA7_special = DFA.unpackEncodedString(DFA7_specialS); + static final short[][] DFA7_transition; + + static { + int numStates = DFA7_transitionS.length; + DFA7_transition = new short[numStates][]; + for (int i=0; i"; + static final String[] DFA10_transitionS = { + "\1\2\4\uffff\1\1\1\uffff\1\5\1\4\4\uffff\1\3\1\uffff\1\7\1\10"+ + "\3\uffff\1\7\34\uffff\1\6", + "\1\11", + "\1\12", + "", + "", + "\1\13", + "\1\14\2\15\13\uffff\1\15\32\uffff\1\15\2\uffff\1\15\1\uffff"+ + "\1\15\2\uffff\1\15\1\uffff\1\15\1\uffff\2\15\2\uffff\1\15\1"+ + "\uffff\1\15\1\uffff\2\15\3\uffff\1\15\10\uffff\1\15\1\uffff"+ + "\3\15\14\uffff\1\15\2\uffff\1\15", + "", + "", + "\1\7\4\uffff\1\7\2\uffff\1\16\4\uffff\1\17\1\uffff\1\7\1\10"+ + "\3\uffff\1\7", + "\1\7\4\uffff\1\7\2\uffff\1\20\4\uffff\1\21\1\uffff\1\7\1\10"+ + "\3\uffff\1\7", + "\1\22", + "", + "", + "", + "", + "", + "", + "\1\25\4\uffff\1\24\11\uffff\1\23\1\26\3\uffff\1\23", + "", + "\1\27", + "\1\30", + "", + "\1\23\4\uffff\1\23\11\uffff\1\23\1\26\3\uffff\1\23", + "\1\23\4\uffff\1\23\11\uffff\1\23\1\26\3\uffff\1\23" + }; + + static final short[] DFA10_eot = DFA.unpackEncodedString(DFA10_eotS); + static final short[] DFA10_eof = DFA.unpackEncodedString(DFA10_eofS); + static final char[] DFA10_min = DFA.unpackEncodedStringToUnsignedChars(DFA10_minS); + static final char[] DFA10_max = DFA.unpackEncodedStringToUnsignedChars(DFA10_maxS); + static final short[] DFA10_accept = DFA.unpackEncodedString(DFA10_acceptS); + static final short[] DFA10_special = DFA.unpackEncodedString(DFA10_specialS); + static final short[][] DFA10_transition; + + static { + int numStates = DFA10_transitionS.length; + DFA10_transition = new short[numStates][]; + for (int i=0; i"; + static final String[] DFA16_transitionS = { + "\1\4\4\uffff\1\3\11\uffff\1\2\4\uffff\1\1", + "\1\5\2\6\13\uffff\1\6\32\uffff\1\6\2\uffff\1\6\1\uffff\1\6"+ + "\2\uffff\1\6\1\uffff\1\6\1\uffff\2\6\2\uffff\1\6\1\uffff\1\6"+ + "\1\uffff\2\6\3\uffff\1\6\10\uffff\1\6\1\uffff\3\6\14\uffff\1"+ + "\6\2\uffff\1\6", + "\1\7\2\10\13\uffff\1\10\32\uffff\1\10\2\uffff\1\10\1\uffff"+ + "\1\10\2\uffff\1\10\1\uffff\1\10\1\uffff\2\10\2\uffff\1\10\1"+ + "\uffff\1\10\1\uffff\2\10\3\uffff\1\10\10\uffff\1\10\1\uffff"+ + "\3\10\14\uffff\1\10\2\uffff\1\10", + "", + "", + "", + "", + "\12\12\1\11\130\12", + "", + "\2\12\143\13", + "", + "" + }; + + static final short[] DFA16_eot = DFA.unpackEncodedString(DFA16_eotS); + static final short[] DFA16_eof = DFA.unpackEncodedString(DFA16_eofS); + static final char[] DFA16_min = DFA.unpackEncodedStringToUnsignedChars(DFA16_minS); + static final char[] DFA16_max = DFA.unpackEncodedStringToUnsignedChars(DFA16_maxS); + static final short[] DFA16_accept = DFA.unpackEncodedString(DFA16_acceptS); + static final short[] DFA16_special = DFA.unpackEncodedString(DFA16_specialS); + static final short[][] DFA16_transition; + + static { + int numStates = DFA16_transitionS.length; + DFA16_transition = new short[numStates][]; + for (int i=0; i alts; + public List decls; - public Choice(CodeGenerator gen, List alts) { + public Choice(CodeGenerator gen, GrammarAST blkOrEbnfRootAST, List alts) { this.gen = gen; + this.ast = blkOrEbnfRootAST; this.alts = alts; + this.decision = ((BlockStartState)blkOrEbnfRootAST.nfaState).decision; } @Override public List getChildren() { - return new ArrayList() {{ add("alts"); }}; + final List sup = super.getChildren(); + return new ArrayList() {{ if ( sup!=null ) addAll(sup); add("alts"); add("decls"); }}; } } diff --git a/tool/src/org/antlr/v4/codegen/src/CodeBlock.java b/tool/src/org/antlr/v4/codegen/src/CodeBlock.java index f3a67977a..e813aeb83 100644 --- a/tool/src/org/antlr/v4/codegen/src/CodeBlock.java +++ b/tool/src/org/antlr/v4/codegen/src/CodeBlock.java @@ -22,6 +22,7 @@ public class CodeBlock extends SrcOp { @Override public List getChildren() { - return new ArrayList() {{ add("ops"); }}; + final List sup = super.getChildren(); + return new ArrayList() {{ if ( sup!=null ) addAll(sup); add("ops"); }}; } } diff --git a/tool/src/org/antlr/v4/codegen/src/Decl.java b/tool/src/org/antlr/v4/codegen/src/Decl.java new file mode 100644 index 000000000..db4a9f22d --- /dev/null +++ b/tool/src/org/antlr/v4/codegen/src/Decl.java @@ -0,0 +1,7 @@ +package org.antlr.v4.codegen.src; + +/** */ +public class Decl extends SrcOp { + public String varName; + public Decl(String varName) { this.varName = varName; } +} diff --git a/tool/src/org/antlr/v4/codegen/src/InvokeRule.java b/tool/src/org/antlr/v4/codegen/src/InvokeRule.java index c09886ed4..572e6b2ae 100644 --- a/tool/src/org/antlr/v4/codegen/src/InvokeRule.java +++ b/tool/src/org/antlr/v4/codegen/src/InvokeRule.java @@ -1,7 +1,9 @@ package org.antlr.v4.codegen.src; +import org.antlr.v4.analysis.LinearApproximator; import org.antlr.v4.codegen.CodeGenerator; import org.antlr.v4.misc.IntervalSet; +import org.antlr.v4.tool.GrammarAST; import java.util.List; @@ -10,17 +12,21 @@ public class InvokeRule extends SrcOp { public String name; public String label; public List args; - public IntervalSet[] follow; + public BitSetDef follow; - public InvokeRule(CodeGenerator gen, String name, String argAction, IntervalSet[] follow) { + public InvokeRule(CodeGenerator gen, GrammarAST ast, GrammarAST labelAST) { this.gen = gen; - // split and translate argAction - // compute follow - } - - public InvokeRule(CodeGenerator gen, String name, IntervalSet[] follow) { - this.gen = gen; - // split and translate argAction + this.ast = ast; + this.name = ast.getText(); + if ( labelAST!=null ) this.label = labelAST.getText(); + if ( ast.getChildCount()>0 ) { + String argAction = ast.getChild(0).getText(); + // split and translate argAction + } // compute follow + LinearApproximator approx = new LinearApproximator(gen.g, -1); + IntervalSet fset = approx.LOOK(ast.nfaState.transition(0).target); + System.out.println("follow="+follow); + follow = gen.defineFollowBitSet(ast, fset); } } diff --git a/tool/src/org/antlr/v4/codegen/src/LL1Choice.java b/tool/src/org/antlr/v4/codegen/src/LL1Choice.java index 5015da5b0..537fad416 100644 --- a/tool/src/org/antlr/v4/codegen/src/LL1Choice.java +++ b/tool/src/org/antlr/v4/codegen/src/LL1Choice.java @@ -1,12 +1,28 @@ package org.antlr.v4.codegen.src; +import org.antlr.v4.analysis.LinearApproximator; +import org.antlr.v4.automata.DFA; import org.antlr.v4.codegen.CodeGenerator; +import org.antlr.v4.misc.IntervalSet; +import org.antlr.v4.tool.GrammarAST; +import java.util.ArrayList; import java.util.List; -/** */ +/** (A | B | C) */ public class LL1Choice extends Choice { - public LL1Choice(CodeGenerator gen, List alts) { - super(gen, alts); + /** Token names for each alt 0..n-1 */ + public List altLook; + /** Lookahead for each alt 1..n */ + public IntervalSet[] altLookSets; + public LL1Choice(CodeGenerator gen, GrammarAST blkAST, List alts) { + super(gen, blkAST, alts); + DFA dfa = gen.g.decisionDFAs.get(decision); + altLookSets = LinearApproximator.getLL1LookaheadSets(dfa); + altLook = new ArrayList(); + for (int a=1; a alts) { - super(gen, alts); +public class LL1OptionalBlock extends LL1Choice { + public LL1OptionalBlock(CodeGenerator gen, GrammarAST blkAST, List alts) { + super(gen, blkAST, alts); } } diff --git a/tool/src/org/antlr/v4/codegen/src/LL1OptionalBlockSingleAlt.java b/tool/src/org/antlr/v4/codegen/src/LL1OptionalBlockSingleAlt.java index 2ae83d963..d1eb57df5 100644 --- a/tool/src/org/antlr/v4/codegen/src/LL1OptionalBlockSingleAlt.java +++ b/tool/src/org/antlr/v4/codegen/src/LL1OptionalBlockSingleAlt.java @@ -1,12 +1,31 @@ package org.antlr.v4.codegen.src; import org.antlr.v4.codegen.CodeGenerator; +import org.antlr.v4.misc.IntervalSet; +import org.antlr.v4.tool.GrammarAST; +import java.util.ArrayList; import java.util.List; /** */ -public class LL1OptionalBlockSingleAlt extends OptionalBlock { - public LL1OptionalBlockSingleAlt(CodeGenerator gen, List alts) { - super(gen, alts); +public class LL1OptionalBlockSingleAlt extends LL1OptionalBlock { + public Object expr; + public LL1OptionalBlockSingleAlt(CodeGenerator gen, GrammarAST blkAST, List alts) { + super(gen, blkAST, alts); + IntervalSet look = altLookSets[1]; + if ( look.size() < gen.target.getInlineTestsVsBitsetThreshold() ) { + expr = new TestSetInline(gen, blkAST, look); + decls = new ArrayList(); + decls.add(new NextTokenDecl("la34")); + } + else { + expr = new TestSet(gen, blkAST, look); + } + } + + @Override + public List getChildren() { + final List sup = super.getChildren(); + return new ArrayList() {{ if ( sup!=null ) addAll(sup); add("expr"); }}; } } diff --git a/tool/src/org/antlr/v4/codegen/src/LLStarOptionalBlock.java b/tool/src/org/antlr/v4/codegen/src/LLStarOptionalBlock.java index 1c991c4bc..3135e9181 100644 --- a/tool/src/org/antlr/v4/codegen/src/LLStarOptionalBlock.java +++ b/tool/src/org/antlr/v4/codegen/src/LLStarOptionalBlock.java @@ -1,12 +1,15 @@ package org.antlr.v4.codegen.src; import org.antlr.v4.codegen.CodeGenerator; +import org.antlr.v4.tool.BlockAST; import java.util.List; /** */ public class LLStarOptionalBlock extends OptionalBlock { - public LLStarOptionalBlock(CodeGenerator gen, List alts) { - super(gen, alts); + public DFADef dfaDef; + public LLStarOptionalBlock(CodeGenerator gen, BlockAST blkAST, List alts) { + super(gen, blkAST, alts); + dfaDef = gen.defineDFA(ast, gen.g.decisionDFAs.get(decision)); } } diff --git a/tool/src/org/antlr/v4/codegen/src/LLkOptionalBlock.java b/tool/src/org/antlr/v4/codegen/src/LLkOptionalBlock.java index 603c8821d..e199bb801 100644 --- a/tool/src/org/antlr/v4/codegen/src/LLkOptionalBlock.java +++ b/tool/src/org/antlr/v4/codegen/src/LLkOptionalBlock.java @@ -1,12 +1,13 @@ package org.antlr.v4.codegen.src; import org.antlr.v4.codegen.CodeGenerator; +import org.antlr.v4.tool.BlockAST; import java.util.List; /** */ public class LLkOptionalBlock extends OptionalBlock { - public LLkOptionalBlock(CodeGenerator gen, List alts) { - super(gen, alts); + public LLkOptionalBlock(CodeGenerator gen, BlockAST blkAST, List alts) { + super(gen, blkAST, alts); } } diff --git a/tool/src/org/antlr/v4/codegen/src/MatchToken.java b/tool/src/org/antlr/v4/codegen/src/MatchToken.java index 6988708fe..99ae821b8 100644 --- a/tool/src/org/antlr/v4/codegen/src/MatchToken.java +++ b/tool/src/org/antlr/v4/codegen/src/MatchToken.java @@ -3,20 +3,23 @@ package org.antlr.v4.codegen.src; import org.antlr.v4.analysis.LinearApproximator; import org.antlr.v4.codegen.CodeGenerator; import org.antlr.v4.misc.IntervalSet; +import org.antlr.v4.tool.GrammarAST; import org.antlr.v4.tool.TerminalAST; /** */ public class MatchToken extends SrcOp { public String name; public BitSetDef follow; + public String label; - public MatchToken(CodeGenerator gen, TerminalAST ast) { + public MatchToken(CodeGenerator gen, TerminalAST ast, GrammarAST labelAST) { this.gen = gen; name = ast.getText(); + if ( labelAST!=null ) this.label = labelAST.getText(); LinearApproximator approx = new LinearApproximator(gen.g, -1); IntervalSet fset = approx.LOOK(ast.nfaState.transition(0).target); System.out.println("follow="+follow); - follow = gen.defineBitSet(ast, fset); + follow = gen.defineFollowBitSet(ast, fset); } } diff --git a/tool/src/org/antlr/v4/codegen/src/NextTokenDecl.java b/tool/src/org/antlr/v4/codegen/src/NextTokenDecl.java new file mode 100644 index 000000000..0058bc6fe --- /dev/null +++ b/tool/src/org/antlr/v4/codegen/src/NextTokenDecl.java @@ -0,0 +1,6 @@ +package org.antlr.v4.codegen.src; + +/** */ +public class NextTokenDecl extends Decl { + public NextTokenDecl(String varName) { super(varName); } +} diff --git a/tool/src/org/antlr/v4/codegen/src/OptionalBlock.java b/tool/src/org/antlr/v4/codegen/src/OptionalBlock.java index b478e3044..7047d4a20 100644 --- a/tool/src/org/antlr/v4/codegen/src/OptionalBlock.java +++ b/tool/src/org/antlr/v4/codegen/src/OptionalBlock.java @@ -1,17 +1,13 @@ package org.antlr.v4.codegen.src; import org.antlr.v4.codegen.CodeGenerator; +import org.antlr.v4.tool.GrammarAST; import java.util.List; /** */ -public class OptionalBlock extends Choice { - public OptionalBlock(CodeGenerator gen, List alts) { - super(gen, alts); - } - - @Override - public List getChildren() { - return super.getChildren(); +public abstract class OptionalBlock extends Choice { + public OptionalBlock(CodeGenerator gen, GrammarAST blkAST, List alts) { + super(gen, blkAST, alts); } } diff --git a/tool/src/org/antlr/v4/codegen/src/Parser.java b/tool/src/org/antlr/v4/codegen/src/Parser.java index 92bf936b8..3765a5fa5 100644 --- a/tool/src/org/antlr/v4/codegen/src/Parser.java +++ b/tool/src/org/antlr/v4/codegen/src/Parser.java @@ -27,6 +27,7 @@ public class Parser extends OutputModelObject { @Override public List getChildren() { - return new ArrayList() {{ add("funcs"); }}; + final List sup = super.getChildren(); + return new ArrayList() {{ if ( sup!=null ) addAll(sup); add("funcs"); }}; } } diff --git a/tool/src/org/antlr/v4/codegen/src/ParserFile.java b/tool/src/org/antlr/v4/codegen/src/ParserFile.java index 5499f0e70..1ea32d705 100644 --- a/tool/src/org/antlr/v4/codegen/src/ParserFile.java +++ b/tool/src/org/antlr/v4/codegen/src/ParserFile.java @@ -19,7 +19,9 @@ public class ParserFile extends OutputModelObject { @Override public List getChildren() { + final List sup = super.getChildren(); return new ArrayList() {{ + if ( sup!=null ) addAll(sup); add("parser"); add("dfaDefs"); add("bitSetDefs"); diff --git a/tool/src/org/antlr/v4/codegen/src/RuleFunction.java b/tool/src/org/antlr/v4/codegen/src/RuleFunction.java index 378b1939e..f971179a4 100644 --- a/tool/src/org/antlr/v4/codegen/src/RuleFunction.java +++ b/tool/src/org/antlr/v4/codegen/src/RuleFunction.java @@ -28,7 +28,7 @@ public class RuleFunction extends OutputModelObject { public List exceptions; public String finallyAction; - public CodeBlock code; + public SrcOp code; public RuleFunction(CodeGenerator gen, Rule r) { this.gen = gen; @@ -52,7 +52,7 @@ public class RuleFunction extends OutputModelObject { CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor,blk); SourceGenTriggers genTriggers = new SourceGenTriggers(nodes, gen); try { - code = genTriggers.block(); // GEN Instr OBJECTS + code = genTriggers.block(null,null); // GEN Instr OBJECTS } catch (Exception e){ e.printStackTrace(System.err); @@ -61,6 +61,7 @@ public class RuleFunction extends OutputModelObject { @Override public List getChildren() { - return new ArrayList() {{ add("code"); }}; + final List sup = super.getChildren(); + return new ArrayList() {{ if ( sup!=null ) addAll(sup); add("code"); }}; } } diff --git a/tool/src/org/antlr/v4/codegen/src/TestSet.java b/tool/src/org/antlr/v4/codegen/src/TestSet.java new file mode 100644 index 000000000..869e44b6b --- /dev/null +++ b/tool/src/org/antlr/v4/codegen/src/TestSet.java @@ -0,0 +1,13 @@ +package org.antlr.v4.codegen.src; + +import org.antlr.v4.codegen.CodeGenerator; +import org.antlr.v4.misc.IntervalSet; +import org.antlr.v4.tool.GrammarAST; + +/** */ +public class TestSet extends OutputModelObject { + public BitSetDef set; + public TestSet(CodeGenerator gen, GrammarAST blkAST, IntervalSet set) { + this.set = gen.defineTestBitSet(blkAST, set); + } +} diff --git a/tool/src/org/antlr/v4/codegen/src/TestSetInline.java b/tool/src/org/antlr/v4/codegen/src/TestSetInline.java new file mode 100644 index 000000000..335824ce9 --- /dev/null +++ b/tool/src/org/antlr/v4/codegen/src/TestSetInline.java @@ -0,0 +1,13 @@ +package org.antlr.v4.codegen.src; + +import org.antlr.v4.codegen.CodeGenerator; +import org.antlr.v4.misc.IntervalSet; +import org.antlr.v4.tool.GrammarAST; + +/** */ +public class TestSetInline extends OutputModelObject { + public String[] ttypes; + public TestSetInline(CodeGenerator gen, GrammarAST blkAST, IntervalSet set) { + this.ttypes = gen.target.getTokenTypeAsTargetLabel(gen.g, set.toArray()); + } +}