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 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,8 +94,9 @@ public class ParserATNSimulator extends ATNSimulator {
|
|||
{
|
||||
if ( originalContext==null ) originalContext = RuleContext.EMPTY;
|
||||
RuleContext ctx = RuleContext.EMPTY;
|
||||
if ( useContext ) ctx = originalContext;
|
||||
OrderedHashSet<ATNConfig> s0_closure = computeStartState(dfa.atnStartState, ctx, originalContext);
|
||||
if ( useContext ) ctx = originalContext;
|
||||
OrderedHashSet<ATNConfig> s0_closure =
|
||||
computeStartState(dfa.atnStartState, ctx, originalContext);
|
||||
dfa.s0 = addDFAState(dfa, s0_closure);
|
||||
if ( prevAccept!=null ) {
|
||||
dfa.s0.isAcceptState = true;
|
||||
|
@ -300,7 +301,7 @@ public class ParserATNSimulator extends ATNSimulator {
|
|||
OrderedHashSet<ATNConfig> tmp = reach;
|
||||
reach = closure;
|
||||
closure = tmp;
|
||||
reach.clear();
|
||||
reach.clear(); // THIS MIGHT BE SLOW! kills each element; realloc might be faster
|
||||
} while ( true );
|
||||
|
||||
if ( prevAccept==null ) {
|
||||
|
@ -457,7 +458,7 @@ public class ParserATNSimulator extends ATNSimulator {
|
|||
RuleContext newContext;
|
||||
if ( parser != null ) {
|
||||
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;
|
||||
System.out.println("new ctx type is "+newContext.getClass().getSimpleName());
|
||||
}
|
||||
|
|
|
@ -1,56 +1,14 @@
|
|||
grammar T;
|
||||
options {output=AST;}
|
||||
s : e EOF ;
|
||||
expressionList
|
||||
: e (','! e)*
|
||||
;
|
||||
e : '('! e ')'!
|
||||
| 'this'
|
||||
| 'super'
|
||||
| INT
|
||||
| ID
|
||||
| type '.'^ 'class'
|
||||
| e '.'^ ID
|
||||
| e '.'^ 'this'
|
||||
| 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();} ;
|
||||
|
||||
s : e[9] {true}? ';' ;
|
||||
|
||||
e[int i]
|
||||
: {$i>=0}? ID
|
||||
| ID '!'
|
||||
;
|
||||
|
||||
foo[int j] : e[8] {$j==2}? '$' ; // not called but in FOLLOW(e)
|
||||
|
||||
ID : 'a'..'z'+;
|
||||
|
||||
WS : ' '+ {skip();} ;
|
||||
|
|
|
@ -65,10 +65,10 @@ public class <parser.name> extends Parser {
|
|||
|
||||
dumpActions(recog, argFuncs, actionFuncs, sempredFuncs) ::= <<
|
||||
<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 ) {
|
||||
<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);
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public <p.name>(TokenStream input) {
|
|||
|
||||
RuleArgFunction(r, actions) ::= <<
|
||||
/** 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 ) {
|
||||
<actions:{index|
|
||||
case <index> : return new <r.actions.(index).ctxType>(_localctx, s, <actions.(index)>);}; separator="\n">
|
||||
|
|
|
@ -253,6 +253,7 @@ rule
|
|||
@init {
|
||||
List<GrammarAST> mods = new ArrayList<GrammarAST>();
|
||||
List<GrammarAST> actions = new ArrayList<GrammarAST>(); // track roots
|
||||
currentOuterAltNumber=0;
|
||||
}
|
||||
: ^( RULE ID {currentRuleName=$ID.text; currentRuleAST=$RULE;}
|
||||
DOC_COMMENT? (^(RULEMODIFIERS (m=ruleModifier{mods.add($m.start);})+))?
|
||||
|
@ -308,8 +309,7 @@ ruleModifier
|
|||
;
|
||||
|
||||
ruleBlock
|
||||
: {currentOuterAltNumber=0;}
|
||||
^( BLOCK
|
||||
: ^( BLOCK
|
||||
( {
|
||||
currentOuterAltRoot = (GrammarAST)input.LT(1);
|
||||
currentOuterAltNumber++;
|
||||
|
|
Loading…
Reference in New Issue