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

📄 c.stg

📁 antlr最新版本V3源代码
💻 STG
📖 第 1 页 / 共 5 页
字号:
<checkRuleBacktrackFailure()>>>/** For now, sets are interval tests and must be tested inline */matchSet(s,label,elementIndex,postmatchCode="") ::= <<<if(label)><if(LEXER)><label>= LA(1);<\n><else><label>=(<labelType>)LT(1);<\n><endif><endif>if ( <s> ){    CONSUME();    <postmatchCode><if(!LEXER)>    PERRORRECOVERY=ANTLR3_FALSE;<endif>    <if(backtracking)>FAILEDFLAG=ANTLR3_FALSE;<\n><endif>}else {    <ruleBacktrackFailure()>    <mismatchedSetEx()>    <@mismatchedSetException()><if(LEXER)>    LRECOVER();<else>    RECOVERFROMMISMATCHEDSET(&FOLLOW_set_in_<ruleName><elementIndex>);<endif>    goto rule<ruleDescriptor.name>Ex;}<\n>>>mismatchedSetEx() ::= <<CONSTRUCTEX();EXCEPTION->type         = ANTLR3_MISMATCHED_SET_EXCEPTION;EXCEPTION->name         = ANTLR3_MISMATCHED_SET_NAME;<if(PARSER)>EXCEPTION->expectingSet = &FOLLOW_set_in_<ruleName><elementIndex>;<endif>>>matchSetAndListLabel(s,label,elementIndex,postmatchCode) ::= <<<matchSet(...)><listLabel(elem=label,...)>>>/** Match a string literal */lexerStringRef(string,label) ::= <<<if(label)>int <label>Start = GETCHARINDEX();MATCHS(<string>); <checkRuleBacktrackFailure()><labelType> <label> = LEXER->tokFactory->newToken(LEXER->tokFactory);<label>->setType(<label>, ANTLR3_TOKEN_INVALID);<label>->setStartIndex(<label>, <label>Start);<label>->setStopIndex(<label>, GETCHARINDEX()-1);<label>->input = INPUT->tnstream->istream;<else>MATCHS(<string>); <checkRuleBacktrackFailure()><\n><endif>>>wildcard(label,elementIndex) ::= <<<if(label)><label>=(<labelType>)LT(1);<\n><endif>MATCHANYT(); <checkRuleBacktrackFailure()>>>wildcardAndListLabel(label,elementIndex) ::= <<<wildcard(...)><listLabel(elem=label,...)>>>/** Match . wildcard in lexer */wildcardChar(label, elementIndex) ::= <<<if(label)><label> = LA(1);<\n><endif>MATCHANY(); <checkRuleBacktrackFailure()>>>wildcardCharListLabel(label, elementIndex) ::= <<<wildcardChar(...)><listLabel(elem=label,...)>>>/** Match a rule reference by invoking it possibly with arguments *  and a return value or values. */ruleRef(rule,label,elementIndex,args) ::= <<FOLLOWPUSH(FOLLOW_<rule>_in_<ruleName><elementIndex>);<if(label)><label>=<rule>(ctx<if(args)>, <args; separator=", "><endif>);<\n><else><rule>(ctx<if(args)>, <args; separator=", "><endif>);<\n><endif>FOLLOWPOP();if  (HASEXCEPTION()){    goto rule<ruleDescriptor.name>Ex;}<checkRuleBacktrackFailure()>>>/** ids+=r */ruleRefAndListLabel(rule,label,elementIndex,args) ::= <<<ruleRef(...)><listLabel(elem=label,...)>>>/** A lexer rule reference */lexerRuleRef(rule,label,args,elementIndex) ::= <</* <description> */<if(label)>{    ANTLR3_UINT64 <label>Start<elementIndex> = GETCHARINDEX();    m<rule>(ctx <if(args)>, <endif><args; separator=", ">);     <checkRuleBacktrackFailure()>    <label> = LEXER->tokFactory->newToken(LEXER->tokFactory);    <label>->setType(<label>, ANTLR3_TOKEN_INVALID);    <label>->setStartIndex(<label>, <label>Start<elementIndex>);    <label>->setStopIndex(<label>, GETCHARINDEX()-1);    <label>->input = INPUT;}<else>m<rule>(ctx <if(args)>, <endif><args; separator=", ">); <checkRuleBacktrackFailure()><endif>>>/** i+=INT in lexer */lexerRuleRefAndListLabel(rule,label,args,elementIndex) ::= <<<lexerRuleRef(...)><listLabel(elem=label,...)>>>/** EOF in the lexer */lexerMatchEOF(label,elementIndex) ::= <<<if(label)>{    ANTLR3_UINT64 <label>Start<elementIndex>;    <labelType> <label>;    <label>Start<elementIndex> = GETCHARINDEX();    MATCHC(ANTLR3_CHARSTREAM_EOF);     <checkRuleBacktrackFailure()>    <label> = LEXER->tokFactory->newToken(LEXER->tokFactory);    <label>->setType(<label>, ANTLR3_TOKEN_EOF);    <label>->setStartIndex(<label>, <label>Start<elementIndex>);    <label>->setStopIndex(<label>, GETCHARINDEX()-1);    <label>->input = INPUT->tnstream->istream;}<else>    MATCHC(ANTLR3_CHARSTREAM_EOF);     <checkRuleBacktrackFailure()>    <endif>>>/** match ^(root children) in tree parser */tree(root, actionsAfterRoot, children, nullableChildList) ::= <<<root:element()><actionsAfterRoot:element()><if(nullableChildList)>if ( LA(1)==ANTLR3_TOKEN_DOWN ) {    MATCHT(ANTLR3_TOKEN_DOWN, NULL);     <checkRuleBacktrackFailure()>    <children:element()>    MATCHT(ANTLR3_TOKEN_UP, NULL);     <checkRuleBacktrackFailure()>}<else>MATCHT(ANTLR3_TOKEN_DOWN, NULL); <checkRuleBacktrackFailure()><children:element()>MATCHT(ANTLR3_TOKEN_UP, NULL); <checkRuleBacktrackFailure()><endif>>>/** Every predicate is used as a validating predicate (even when it is *  also hoisted into a prediction expression). */validateSemanticPredicate(pred,description) ::= <<if ( !(<evalPredicate(...)>) ) {    <ruleBacktrackFailure()>    <newFPE(...)>}>>newFPE() ::= <<    CONSTRUCTEX();    EXCEPTION->type         = ANTLR3_FAILED_PREDICATE_EXCEPTION;    EXCEPTION->message      = "<description>";    EXCEPTION->ruleName	 = "<ruleName>";    <\n>>>// F i x e d  D F A  (if-then-else)dfaState(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<{    int LA<decisionNumber>_<stateNumber> = LA(<k>);    <edges; separator="\nelse ">    else     {<if(eotPredictsAlt)>        alt<decisionNumber>=<eotPredictsAlt>;<else>        <ruleBacktrackFailure()>            <newNVException()>            goto rule<ruleDescriptor.name>Ex;<endif>    }}>>newNVException() ::= <<CONSTRUCTEX();EXCEPTION->type         = ANTLR3_NO_VIABLE_ALT_EXCEPTION;EXCEPTION->message      = "<description>";EXCEPTION->decisionNum  = <decisionNumber>;EXCEPTION->state        = <stateNumber>;<@noViableAltException()><\n>>>/** Same as a normal DFA state except that we don't examine lookahead *  for the bypass alternative.  It delays error detection but this *  is faster, smaller, and more what people expect.  For (X)? people *  expect "if ( LA(1)==X ) match(X);" and that's it. */dfaOptionalBlockState(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<{    int LA<decisionNumber>_<stateNumber> = LA(<k>);    <edges; separator="\nelse ">}>>/** A DFA state that is actually the loopback decision of a closure *  loop.  If end-of-token (EOT) predicts any of the targets then it *  should act like a default clause (i.e., no error can be generated). *  This is used only in the lexer so that for ('a')* on the end of a rule *  anything other than 'a' predicts exiting. */dfaLoopbackStateDecls()::= <<ANTLR3_UINT32   LA<decisionNumber>_<stateNumber>;>>dfaLoopbackState(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<{   /* dfaLoopbackState(k,edges,eotPredictsAlt,description,stateNumber,semPredState)    */    int LA<decisionNumber>_<stateNumber> = LA(<k>);    <edges; separator="\nelse "><\n>    <if(eotPredictsAlt)>    <if(!edges)>	alt<decisionNumber>=<eotPredictsAlt>; <! if no edges, don't gen ELSE !>	<else>        else     {	alt<decisionNumber>=<eotPredictsAlt>;    }<\n>    <endif>    <endif>}>>/** An accept state indicates a unique alternative has been predicted */dfaAcceptState(alt) ::= "alt<decisionNumber>=<alt>;"/** A simple edge with an expression.  If the expression is satisfied, *  enter to the target state.  To handle gated productions, we may *  have to evaluate some predicates for this edge. */dfaEdge(labelExpr, targetState, predicates) ::= <<if ( (<labelExpr>) <if(predicates)>&& (<predicates>)<endif>) {    <targetState> // It is I}>>// F i x e d  D F A  (switch case)/** A DFA state where a SWITCH may be generated.  The code generator *  decides if this is possible: CodeGenerator.canGenerateSwitch(). */dfaStateSwitch(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<switch ( LA(<k>) ) {<edges; separator="\n">default:<if(eotPredictsAlt)>    alt<decisionNumber>=<eotPredictsAlt>;<else>    <ruleBacktrackFailure()>    <newNVException()>    goto rule<ruleDescriptor.name>Ex;<\n><endif>}<\n>>>dfaOptionalBlockStateSwitch(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<switch ( LA(<k>) ) {    <edges; separator="\n">}<\n>>>dfaLoopbackStateSwitch(k, edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<switch ( 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> = cdfa<decisionNumber>.predict(ctx, RECOGNIZER, INPUT->istream, &cdfa<decisionNumber>);>>/* Dump DFA tables as static initialized arrays of shorts(16 bits)/characters(8 bits) * which are then used to statically initialize the dfa structure, which means that there * is no runtime initialization whatsoever, other than anything the C compiler might * need to generate. In general the C compiler will lay out memory such that there is no  * runtime code required. */cyclicDFA(dfa) ::= <</** Static dfa state tables for Cyclic dfa: *    <dfa.description> */static const ANTLR3_INT32 dfa<dfa.decisionNumber>_eot[<dfa.numberOfStates>] =    {	<dfa.eot; wrap="\n", separator=", ", null="-1">    };static const ANTLR3_INT32 dfa<dfa.decisionNumber>_eof[<dfa.numberOfStates>] =    {	<dfa.eof; wrap="\n", separator=", ", null="-1">    };static const ANTLR3_INT32 dfa<dfa.decisionNumber>_min[<dfa.numberOfStates>] =    {	<dfa.min; wrap="\n", separator=", ", null="-1">    };static const ANTLR3_INT32 dfa<dfa.decisionNumber>_max[<dfa.numberOfStates>] =    {	<dfa.max; wrap="\n", separator=", ", null="-1">    };static const ANTLR3_INT32 dfa<dfa.decisionNumber>_accept[<dfa.numberOfStates>] =    {	<dfa.accept; wrap="\n", separator=", ", null="-1">    };static const ANTLR3_INT32 dfa<dfa.decisionNumber>_special[<dfa.numberOfStates>] =    {		<dfa.special; wrap="\n", separator=", ", null="-1">    };/** Used when there is no transition table entry for a particular state */#define dfa<dfa.decisionNumber>_T_empty	    NULL<dfa.edgeTransitionClassMap.keys:{ table |static const ANTLR3_INT32 dfa<dfa.decisionNumber>_T<i0>[] =    {	<table; separator=", ", wrap="\n", null="-1">    };}; null = "">/* Transition tables are a table of sub tables, with some tables * reused for efficiency. */static const ANTLR3_INT32 * const dfa<dfa.decisionNumber>_transitions[] ={    <dfa.transitionEdgeTables:{xref|dfa<dfa.decisionNumber>_T<xref>}; separator=", ", wrap="\n", null="_empty">	};<if(dfa.specialStateSTs)>static ANTLR3_INT32 dfa<dfa.decisionNumber>_sst(p<name> ctx, pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_INT_STREAM is, pANTLR3_CYCLIC_DFA dfa, ANTLR3_UINT32 s){    ANTLR3_INT32    _s;        _s	    = s;    switch  (s)    {    <dfa.specialStateSTs:{state |    case <i0>:    	<state>}; separator="\n">    }<if(backtracking)>    if (BACKTRACKING > 0)    {	FAILEDFLAG = ANTLR3_TRUE;	return	-1;    }<endif>        CONSTRUCTEX();    EXCEPTION->type         = ANTLR3_NO_VIABLE_ALT_EXCEPTION;    EXCEPTION->message      = "<dfa.description>";    EXCEPTION->decisionNum  = <dfa.decisionNumber>;    EXCEPTION->state        = _s;    <@noViableAltException()>    return -1;}<endif><@errorMethod()>/* Declare tracking structure for Cyclic DFA <dfa.decisionNumber> */ANTLR3_CYCLIC_DFA cd

⌨️ 快捷键说明

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