⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 java.stg

📁 antlr最新版本V3源代码
💻 STG
📖 第 1 页 / 共 3 页
字号:
    <ruleBacktrackFailure()>    NoViableAltException nvae =        new NoViableAltException("<description>", <decisionNumber>, <stateNumber>, input);<\n>    <@noViableAltException()>    throw nvae;<\n><endif>}<\n>>>dfaOptionalBlockStateSwitch(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<switch ( input.LA(<k>) ) {    <edges; separator="\n">}<\n>>>dfaLoopbackStateSwitch(k, edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<switch ( input.LA(<k>) ) {<edges; separator="\n"><\n><if(eotPredictsAlt)>default:    alt<decisionNumber>=<eotPredictsAlt>;    break;<\n><endif>}<\n>>>dfaEdgeSwitch(labels, targetState) ::= <<<labels:{case <it>:}; separator="\n">    {    <targetState>    }    break;>>// C y c l i c  D F A/** The code to initiate execution of a cyclic DFA; this is used *  in the rule to predict an alt just like the fixed DFA case. *  The <name> attribute is inherited via the parser, lexer, ... */dfaDecision(decisionNumber,description) ::= <<alt<decisionNumber> = dfa<decisionNumber>.predict(input);>>/* Dump DFA tables as run-length-encoded Strings of octal values. * Can't use hex as compiler translates them before compilation. * These strings are split into multiple, concatenated strings. * Java puts them back together at compile time thankfully. * Java cannot handle large static arrays, so we're stuck with this * encode/decode approach.  See analysis and runtime DFA for * the encoding methods. */cyclicDFA(dfa) ::= <<static final String DFA<dfa.decisionNumber>_eotS =    "<dfa.javaCompressedEOT; wrap="\"+\n    \"">";static final String DFA<dfa.decisionNumber>_eofS =    "<dfa.javaCompressedEOF; wrap="\"+\n    \"">";static final String DFA<dfa.decisionNumber>_minS =    "<dfa.javaCompressedMin; wrap="\"+\n    \"">";static final String DFA<dfa.decisionNumber>_maxS =    "<dfa.javaCompressedMax; wrap="\"+\n    \"">";static final String DFA<dfa.decisionNumber>_acceptS =    "<dfa.javaCompressedAccept; wrap="\"+\n    \"">";static final String DFA<dfa.decisionNumber>_specialS =    "<dfa.javaCompressedSpecial; wrap="\"+\n    \"">}>";static final String[] DFA<dfa.decisionNumber>_transitionS = {        <dfa.javaCompressedTransition:{s|"<s; wrap="\"+\n\"">"}; separator=",\n">};static final short[] DFA<dfa.decisionNumber>_eot = DFA.unpackEncodedString(DFA<dfa.decisionNumber>_eotS);static final short[] DFA<dfa.decisionNumber>_eof = DFA.unpackEncodedString(DFA<dfa.decisionNumber>_eofS);static final char[] DFA<dfa.decisionNumber>_min = DFA.unpackEncodedStringToUnsignedChars(DFA<dfa.decisionNumber>_minS);static final char[] DFA<dfa.decisionNumber>_max = DFA.unpackEncodedStringToUnsignedChars(DFA<dfa.decisionNumber>_maxS);static final short[] DFA<dfa.decisionNumber>_accept = DFA.unpackEncodedString(DFA<dfa.decisionNumber>_acceptS);static final short[] DFA<dfa.decisionNumber>_special = DFA.unpackEncodedString(DFA<dfa.decisionNumber>_specialS);static final short[][] DFA<dfa.decisionNumber>_transition;static {    int numStates = DFA<dfa.decisionNumber>_transitionS.length;    DFA<dfa.decisionNumber>_transition = new short[numStates][];    for (int i=0; i\<numStates; i++) {        DFA<dfa.decisionNumber>_transition[i] = DFA.unpackEncodedString(DFA<dfa.decisionNumber>_transitionS[i]);    }}class DFA<dfa.decisionNumber> extends DFA {    public DFA<dfa.decisionNumber>(BaseRecognizer recognizer) {        this.recognizer = recognizer;        this.decisionNumber = <dfa.decisionNumber>;        this.eot = DFA<dfa.decisionNumber>_eot;        this.eof = DFA<dfa.decisionNumber>_eof;        this.min = DFA<dfa.decisionNumber>_min;        this.max = DFA<dfa.decisionNumber>_max;        this.accept = DFA<dfa.decisionNumber>_accept;        this.special = DFA<dfa.decisionNumber>_special;        this.transition = DFA<dfa.decisionNumber>_transition;    }    public String getDescription() {        return "<dfa.description>";    }    <@errorMethod()><if(dfa.specialStateSTs)>    public int specialStateTransition(int s, IntStream input) throws NoViableAltException {    	int _s = s;        switch ( s ) {        <dfa.specialStateSTs:{state |        case <i0> : <! compressed special state numbers 0..n-1 !>            <state>}; separator="\n">        }<if(backtracking)>        if (backtracking>0) {failed=true; return -1;}<\n><endif>        NoViableAltException nvae =            new NoViableAltException(getDescription(), <dfa.decisionNumber>, _s, input);        error(nvae);        throw nvae;    }<\n><endif>}<\n>>>/** A state in a cyclic DFA; it's a special state and part of a big switch on *  state. */cyclicDFAState(decisionNumber,stateNumber,edges,needErrorClause,semPredState) ::= <<int LA<decisionNumber>_<stateNumber> = input.LA(1);<\n><if(semPredState)> <! get next lookahead symbol to test edges, then rewind !>int index<decisionNumber>_<stateNumber> = input.index();input.rewind();<\n><endif>s = -1;<edges; separator="\nelse "><if(semPredState)> <! return input cursor to state before we rewound !>input.seek(index<decisionNumber>_<stateNumber>);<\n><endif>if ( s>=0 ) return s;break;>>/** Just like a fixed DFA edge, test the lookahead and indicate what *  state to jump to next if successful. */cyclicDFAEdge(labelExpr, targetStateNumber, edgeNumber, predicates) ::= <<if ( (<labelExpr>) <if(predicates)>&& (<predicates>)<endif>) {s = <targetStateNumber>;}<\n>>>/** An edge pointing at end-of-token; essentially matches any char; *  always jump to the target. */eotDFAEdge(targetStateNumber,edgeNumber, predicates) ::= <<s = <targetStateNumber>;<\n>>>// D F A  E X P R E S S I O N SandPredicates(left,right) ::= "(<left>&&<right>)"orPredicates(operands) ::= "(<first(operands)><rest(operands):{o | ||<o>}>)"notPredicate(pred) ::= "!(<evalPredicate(...)>)"evalPredicate(pred,description) ::= "<pred>"evalSynPredicate(pred,description) ::= "<pred>()"lookaheadTest(atom,k,atomAsInt) ::= "LA<decisionNumber>_<stateNumber>==<atom>"/** Sometimes a lookahead test cannot assume that LA(k) is in a temp variable *  somewhere.  Must ask for the lookahead directly. */isolatedLookaheadTest(atom,k,atomAsInt) ::= "input.LA(<k>)==<atom>"lookaheadRangeTest(lower,upper,k,rangeNumber,lowerAsInt,upperAsInt) ::= <<(LA<decisionNumber>_<stateNumber>\>=<lower> && LA<decisionNumber>_<stateNumber>\<=<upper>)>>isolatedLookaheadRangeTest(lower,upper,k,rangeNumber,lowerAsInt,upperAsInt) ::= "(input.LA(<k>)\>=<lower> && input.LA(<k>)\<=<upper>)"setTest(ranges) ::= "<ranges; separator=\"||\">"// A T T R I B U T E SglobalAttributeScope(scope) ::= <<<if(scope.attributes)>protected static class <scope.name>_scope {    <scope.attributes:{<it.decl>;}; separator="\n">}protected Stack <scope.name>_stack = new Stack();<\n><endif>>>ruleAttributeScope(scope) ::= <<<if(scope.attributes)>protected static class <scope.name>_scope {    <scope.attributes:{<it.decl>;}; separator="\n">}protected Stack <scope.name>_stack = new Stack();<\n><endif>>>returnType() ::= <<<if(ruleDescriptor.hasMultipleReturnValues)><ruleDescriptor.name>_return<else><if(ruleDescriptor.hasSingleReturnValue)><ruleDescriptor.singleValueReturnType><else>void<endif><endif>>>/** Generate the Java type associated with a single or multiple return *  values. */ruleLabelType(referencedRule) ::= <<<if(referencedRule.hasMultipleReturnValues)><referencedRule.name>_return<else><if(referencedRule.hasSingleReturnValue)><referencedRule.singleValueReturnType><else>void<endif><endif>>>/** Using a type to init value map, try to init a type; if not in table *  must be an object, default value is "null". */initValue(typeName) ::= <<<javaTypeInitMap.(typeName)>>>/** Define a rule label including default value */ruleLabelDef(label) ::= <<<ruleLabelType(referencedRule=label.referencedRule)> <label.label.text> = <initValue(typeName=ruleLabelType(referencedRule=label.referencedRule))>;<\n>>>/** Define a return struct for a rule if the code needs to access its *  start/stop tokens, tree stuff, attributes, ...  Leave a hole for *  subgroups to stick in members. */returnScope(scope) ::= <<<if(ruleDescriptor.hasMultipleReturnValues)>public static class <returnType()> extends <if(TREE_PARSER)>Tree<else>Parser<endif>RuleReturnScope {    <scope.attributes:{public <it.decl>;}; separator="\n">    <@ruleReturnMembers()>};<endif>>>parameterScope(scope) ::= <<<scope.attributes:{<it.decl>}; separator=", ">>>parameterAttributeRef(attr) ::= "<attr.name>"parameterSetAttributeRef(attr,expr) ::= "<attr.name> =<expr>;"scopeAttributeRef(scope,attr,index,negIndex) ::= <<<if(negIndex)>((<scope>_scope)<scope>_stack.elementAt(<scope>_stack.size()-<negIndex>-1)).<attr.name><else><if(index)>((<scope>_scope)<scope>_stack.elementAt(<index>)).<attr.name><else>((<scope>_scope)<scope>_stack.peek()).<attr.name><endif><endif>>>scopeSetAttributeRef(scope,attr,expr,index,negIndex) ::= <<<if(negIndex)>((<scope>_scope)<scope>_stack.elementAt(<scope>_stack.size()-<negIndex>-1)).<attr.name> =<expr>;<else><if(index)>((<scope>_scope)<scope>_stack.elementAt(<index>)).<attr.name> =<expr>;<else>((<scope>_scope)<scope>_stack.peek()).<attr.name> =<expr>;<endif><endif>>>/** $x is either global scope or x is rule with dynamic scope; refers *  to stack itself not top of stack.  This is useful for predicates *  like {$function.size()>0 && $function::name.equals("foo")}? */isolatedDynamicScopeRef(scope) ::= "<scope>_stack"/** reference an attribute of rule; might only have single return value */ruleLabelRef(referencedRule,scope,attr) ::= <<<if(referencedRule.hasMultipleReturnValues)><scope>.<attr.name><else><scope><endif>>>returnAttributeRef(ruleDescriptor,attr) ::= <<<if(ruleDescriptor.hasMultipleReturnValues)>retval.<attr.name><else><attr.name><endif>>>returnSetAttributeRef(ruleDescriptor,attr,expr) ::= <<<if(ruleDescriptor.hasMultipleReturnValues)>retval.<attr.name> =<expr>;<else><attr.name> =<expr>;<endif>>>/** How to translate $tokenLabel */tokenLabelRef(label) ::= "<label>"/** ids+=ID {$ids} or e+=expr {$e} */listLabelRef(label) ::= "list_<label>"// not sure the next are the right approachtokenLabelPropertyRef_text(scope,attr) ::= "<scope>.getText()"tokenLabelPropertyRef_type(scope,attr) ::= "<scope>.getType()"tokenLabelPropertyRef_line(scope,attr) ::= "<scope>.getLine()"tokenLabelPropertyRef_pos(scope,attr) ::= "<scope>.getCharPositionInLine()"tokenLabelPropertyRef_channel(scope,attr) ::= "<scope>.getChannel()"tokenLabelPropertyRef_index(scope,attr) ::= "<scope>.getTokenIndex()"tokenLabelPropertyRef_tree(scope,attr) ::= "<scope>_tree"ruleLabelPropertyRef_start(scope,attr) ::= "((<labelType>)<scope>.start)"ruleLabelPropertyRef_stop(scope,attr) ::= "((<labelType>)<scope>.stop)"ruleLabelPropertyRef_tree(scope,attr) ::= "((<ASTLabelType>)<scope>.tree)"ruleLabelPropertyRef_text(scope,attr) ::= <<<if(TREE_PARSER)>input.getTokenStream().toString(  input.getTreeAdaptor().getTokenStartIndex(<scope>.start),  input.getTreeAdaptor().getTokenStopIndex(<scope>.start))<else>input.toString(<scope>.start,<scope>.stop)<endif>>>ruleLabelPropertyRef_st(scope,attr) ::= "<scope>.st"/** Isolated $RULE ref ok in lexer as it's a Token */lexerRuleLabel(label) ::= "<label>"lexerRuleLabelPropertyRef_type(scope,attr) ::= "<scope>.getType()"lexerRuleLabelPropertyRef_line(scope,attr) ::= "<scope>.getLine()"lexerRuleLabelPropertyRef_pos(scope,attr) ::= "<scope>.getCharPositionInLine()"lexerRuleLabelPropertyRef_channel(scope,attr) ::= "<scope>.getChannel()"lexerRuleLabelPropertyRef_index(scope,attr) ::= "<scope>.getTokenIndex()"lexerRuleLabelPropertyRef_text(scope,attr) ::= "<scope>.getText()"// Somebody may ref $template or $tree or $stop within a rule:rulePropertyRef_start(scope,attr) ::= "((<labelType>)retval.start)"rulePropertyRef_stop(scope,attr) ::= "((<labelType>)retval.stop)"rulePropertyRef_tree(scope,attr) ::= "((<ASTLabelType>)retval.tree)"rulePropertyRef_text(scope,attr) ::= <<<if(TREE_PARSER)>input.getTokenStream().toString(  input.getTreeAdaptor().getTokenStartIndex(retval.start),  input.getTreeAdaptor().getTokenStopIndex(retval.start))<else>input.toString(retval.start,input.LT(-1))<endif>>>rulePropertyRef_st(scope,attr) ::= "retval.st"lexerRulePropertyRef_text(scope,attr) ::= "getText()"lexerRulePropertyRef_type(scope,attr) ::= "_type"lexerRulePropertyRef_line(scope,attr) ::= "tokenStartLine"lexerRulePropertyRef_pos(scope,attr) ::= "tokenStartCharPositionInLine"lexerRulePropertyRef_index(scope,attr) ::= "-1" // undefined token index in lexerlexerRulePropertyRef_channel(scope,attr) ::= "channel"lexerRulePropertyRef_start(scope,attr) ::= "tokenStartCharIndex"lexerRulePropertyRef_stop(scope,attr) ::= "(getCharIndex()-1)"// setting $st and $tree is allowed in local rule. everything else// is flagged as errorruleSetPropertyRef_tree(scope,attr,expr) ::= "retval.tree =<expr>;"ruleSetPropertyRef_st(scope,attr,expr) ::= "retval.st =<expr>;"/** How to execute an action */execAction(action) ::= <<<if(backtracking)><if(actions.(actionScope).synpredgate)>if ( <actions.(actionScope).synpredgate> ) {  <action>}<else>if ( backtracking==0 ) {  <action>}<endif><else><action><endif>>>// M I S C (properties, etc...)bitset(name, words64) ::= <<public static final BitSet <name> = new BitSet(new long[]{<words64:{<it>L};separator=",">});<\n>>>codeFileExtension() ::= ".java"true() ::= "true"false() ::= "false"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -