a bit of clean up
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 8906]
This commit is contained in:
parent
613c802c8c
commit
a29feac1bf
|
@ -226,7 +226,7 @@ public class Recognizer<ATNInterpreter> {
|
||||||
public void action(RuleContext _localctx, int ruleIndex, int actionIndex) {
|
public void action(RuleContext _localctx, int ruleIndex, int actionIndex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParserRuleContext args(RuleContext _localctx, int s, int ruleIndex, int actionIndex) {
|
public ParserRuleContext newContext(RuleContext _localctx, int s, int ruleIndex, int actionIndex) {
|
||||||
return new ParserRuleContext(_localctx, s);
|
return new ParserRuleContext(_localctx, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,8 +94,9 @@ public class ParserATNSimulator extends ATNSimulator {
|
||||||
{
|
{
|
||||||
if ( originalContext==null ) originalContext = RuleContext.EMPTY;
|
if ( originalContext==null ) originalContext = RuleContext.EMPTY;
|
||||||
RuleContext ctx = RuleContext.EMPTY;
|
RuleContext ctx = RuleContext.EMPTY;
|
||||||
if ( useContext ) ctx = originalContext;
|
if ( useContext ) ctx = originalContext;
|
||||||
OrderedHashSet<ATNConfig> s0_closure = computeStartState(dfa.atnStartState, ctx, originalContext);
|
OrderedHashSet<ATNConfig> s0_closure =
|
||||||
|
computeStartState(dfa.atnStartState, ctx, originalContext);
|
||||||
dfa.s0 = addDFAState(dfa, s0_closure);
|
dfa.s0 = addDFAState(dfa, s0_closure);
|
||||||
if ( prevAccept!=null ) {
|
if ( prevAccept!=null ) {
|
||||||
dfa.s0.isAcceptState = true;
|
dfa.s0.isAcceptState = true;
|
||||||
|
@ -300,7 +301,7 @@ public class ParserATNSimulator extends ATNSimulator {
|
||||||
OrderedHashSet<ATNConfig> tmp = reach;
|
OrderedHashSet<ATNConfig> tmp = reach;
|
||||||
reach = closure;
|
reach = closure;
|
||||||
closure = tmp;
|
closure = tmp;
|
||||||
reach.clear();
|
reach.clear(); // THIS MIGHT BE SLOW! kills each element; realloc might be faster
|
||||||
} while ( true );
|
} while ( true );
|
||||||
|
|
||||||
if ( prevAccept==null ) {
|
if ( prevAccept==null ) {
|
||||||
|
@ -457,7 +458,7 @@ public class ParserATNSimulator extends ATNSimulator {
|
||||||
RuleContext newContext;
|
RuleContext newContext;
|
||||||
if ( parser != null ) {
|
if ( parser != null ) {
|
||||||
System.out.println("rule trans to rule "+parser.getRuleNames()[t.target.ruleIndex]);
|
System.out.println("rule trans to rule "+parser.getRuleNames()[t.target.ruleIndex]);
|
||||||
newContext = parser.args(config.context, t.target.stateNumber, t.target.ruleIndex, -999);
|
newContext = parser.newContext(config.context, t.target.stateNumber, t.target.ruleIndex, -999);
|
||||||
newContext.invokingState = p.stateNumber;
|
newContext.invokingState = p.stateNumber;
|
||||||
System.out.println("new ctx type is "+newContext.getClass().getSimpleName());
|
System.out.println("new ctx type is "+newContext.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,56 +1,14 @@
|
||||||
grammar T;
|
grammar T;
|
||||||
options {output=AST;}
|
|
||||||
s : e EOF ;
|
s : e[9] {true}? ';' ;
|
||||||
expressionList
|
|
||||||
: e (','! e)*
|
e[int i]
|
||||||
;
|
: {$i>=0}? ID
|
||||||
e : '('! e ')'!
|
| ID '!'
|
||||||
| 'this'
|
;
|
||||||
| 'super'
|
|
||||||
| INT
|
foo[int j] : e[8] {$j==2}? '$' ; // not called but in FOLLOW(e)
|
||||||
| ID
|
|
||||||
| type '.'^ 'class'
|
ID : 'a'..'z'+;
|
||||||
| e '.'^ ID
|
|
||||||
| e '.'^ 'this'
|
WS : ' '+ {skip();} ;
|
||||||
| e '.'^ 'super' '('^ expressionList? ')'!
|
|
||||||
| e '.'^ 'new'^ ID '('! expressionList? ')'!
|
|
||||||
| 'new'^ type ( '(' expressionList? ')'! | ('[' e ']'!)+)
|
|
||||||
| e '['^ e ']'!
|
|
||||||
| '('^ type ')'! e
|
|
||||||
| e ('++'^ | '--'^)
|
|
||||||
| e '('^ expressionList? ')'!
|
|
||||||
| ('+'^|'-'^|'++'^|'--'^) e
|
|
||||||
| ('~'^|'!'^) e
|
|
||||||
| e ('*'^|'/'^|'%'^) e
|
|
||||||
| e ('+'^|'-'^) e
|
|
||||||
| e ('<'^ '<' | '>'^ '>' '>' | '>'^ '>') e
|
|
||||||
| e ('<='^ | '>='^ | '>'^ | '<'^) e
|
|
||||||
| e 'instanceof'^ e
|
|
||||||
| e ('=='^ | '!='^) e
|
|
||||||
| e '&'^ e
|
|
||||||
| e '^'<assoc=right>^ e
|
|
||||||
| e '|'^ e
|
|
||||||
| e '&&'^ e
|
|
||||||
| e '||'^ e
|
|
||||||
| e '?' e ':' e
|
|
||||||
| e ('='<assoc=right>^
|
|
||||||
|'+='<assoc=right>^
|
|
||||||
|'-='<assoc=right>^
|
|
||||||
|'*='<assoc=right>^
|
|
||||||
|'/='<assoc=right>^
|
|
||||||
|'&='<assoc=right>^
|
|
||||||
|'|='<assoc=right>^
|
|
||||||
|'^='<assoc=right>^
|
|
||||||
|'>>='<assoc=right>^
|
|
||||||
|'>>>='<assoc=right>^
|
|
||||||
|'<<='<assoc=right>^
|
|
||||||
|'%='<assoc=right>^) e
|
|
||||||
;
|
|
||||||
type: ID
|
|
||||||
| ID '['^ ']'!
|
|
||||||
| 'int'
|
|
||||||
| 'int' '['^ ']'!
|
|
||||||
;
|
|
||||||
ID : ('a'..'z'|'A'..'Z'|'_'|'$')+;
|
|
||||||
INT : '0'..'9'+ ;
|
|
||||||
WS : (' '|'\n') {skip();} ;
|
|
||||||
|
|
|
@ -65,10 +65,10 @@ public class <parser.name> extends Parser {
|
||||||
|
|
||||||
dumpActions(recog, argFuncs, actionFuncs, sempredFuncs) ::= <<
|
dumpActions(recog, argFuncs, actionFuncs, sempredFuncs) ::= <<
|
||||||
<if(argFuncs)>
|
<if(argFuncs)>
|
||||||
public ParserRuleContext args(RuleContext _localctx, int s, int ruleIndex, int actionIndex) {
|
public ParserRuleContext newContext(RuleContext _localctx, int s, int ruleIndex, int actionIndex) {
|
||||||
switch ( ruleIndex ) {
|
switch ( ruleIndex ) {
|
||||||
<recog.argFuncs.values:{f|
|
<recog.argFuncs.values:{f|
|
||||||
case <f.ruleIndex> : return <f.name>_arg((<f.ctxType>)_localctx, s, actionIndex);}; separator="\n">
|
case <f.ruleIndex> : return <f.name>_argEval((<f.ctxType>)_localctx, s, actionIndex);}; separator="\n">
|
||||||
}
|
}
|
||||||
return new ParserRuleContext(_localctx, s);
|
return new ParserRuleContext(_localctx, s);
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ public <p.name>(TokenStream input) {
|
||||||
|
|
||||||
RuleArgFunction(r, actions) ::= <<
|
RuleArgFunction(r, actions) ::= <<
|
||||||
/** arg computations for rules called FROM and evaluated in context of <r.name> */
|
/** arg computations for rules called FROM and evaluated in context of <r.name> */
|
||||||
public ParserRuleContext <r.name>_arg(ParserRuleContext _localctx, int s, int actionIndex) {
|
public ParserRuleContext <r.name>_argEval(ParserRuleContext _localctx, int s, int actionIndex) {
|
||||||
switch ( actionIndex ) {
|
switch ( actionIndex ) {
|
||||||
<actions:{index|
|
<actions:{index|
|
||||||
case <index> : return new <r.actions.(index).ctxType>(_localctx, s, <actions.(index)>);}; separator="\n">
|
case <index> : return new <r.actions.(index).ctxType>(_localctx, s, <actions.(index)>);}; separator="\n">
|
||||||
|
|
|
@ -253,6 +253,7 @@ rule
|
||||||
@init {
|
@init {
|
||||||
List<GrammarAST> mods = new ArrayList<GrammarAST>();
|
List<GrammarAST> mods = new ArrayList<GrammarAST>();
|
||||||
List<GrammarAST> actions = new ArrayList<GrammarAST>(); // track roots
|
List<GrammarAST> actions = new ArrayList<GrammarAST>(); // track roots
|
||||||
|
currentOuterAltNumber=0;
|
||||||
}
|
}
|
||||||
: ^( RULE ID {currentRuleName=$ID.text; currentRuleAST=$RULE;}
|
: ^( RULE ID {currentRuleName=$ID.text; currentRuleAST=$RULE;}
|
||||||
DOC_COMMENT? (^(RULEMODIFIERS (m=ruleModifier{mods.add($m.start);})+))?
|
DOC_COMMENT? (^(RULEMODIFIERS (m=ruleModifier{mods.add($m.start);})+))?
|
||||||
|
@ -308,8 +309,7 @@ ruleModifier
|
||||||
;
|
;
|
||||||
|
|
||||||
ruleBlock
|
ruleBlock
|
||||||
: {currentOuterAltNumber=0;}
|
: ^( BLOCK
|
||||||
^( BLOCK
|
|
||||||
( {
|
( {
|
||||||
currentOuterAltRoot = (GrammarAST)input.LT(1);
|
currentOuterAltRoot = (GrammarAST)input.LT(1);
|
||||||
currentOuterAltNumber++;
|
currentOuterAltNumber++;
|
||||||
|
|
Loading…
Reference in New Issue