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

📄 c.stg

📁 antlr最新版本V3源代码
💻 STG
📖 第 1 页 / 共 5 页
字号:
    else    {	<(ruleDescriptor.actions.after):execAction()>    }<else><if(!emptyRule)><if(actions.(actionScope).rulecatch)>    <actions.(actionScope).rulecatch><else>    if (HASEXCEPTION())    {        PREPORTERROR();        PRECOVER();    }    else    {	<(ruleDescriptor.actions.after):execAction()>    }<\n><endif><endif><endif>    <if(trace)>System.out.println("exit <ruleName> "+LT(1)+" failed="+failed+" backtracking="+BACKTRACKING);<endif>    <memoize()>    <finally>    <@postamble()>    return <ruleReturnValue()>;}/* $ANTLR end <ruleName> */>>catch(decl,action) ::= <</* catch(decl,action) */if  (HASEXCEPTION() && EXCEPTION->type == <e.decl> ){    <e.action>}>>ruleDeclarations() ::= <<<if(ruleDescriptor.hasMultipleReturnValues)><returnType()> retval;<else><ruleDescriptor.returnScope.attributes:{ a |<a.type> <a.name> = <if(a.initValue)><a.initValue><else><initValue(a.type)><endif>;}><endif><if(memoize)>ANTLR3_UINT64 <ruleDescriptor.name>_StartIndex;<endif>>>ruleInitializations() ::= <</* Initialize rule variables */<if(memoize)><ruleDescriptor.name>_StartIndex = INDEX();<\n><endif><ruleDescriptor.useScopes:{<scopeTop(sname=it)> = <scopePush(sname=it)>;}; separator="\n"><ruleDescriptor.ruleScope:{<scopeTop(sname=it.name)> = <scopePush(sname=it.name)>;}; separator="\n">>>ruleLabelDefs() ::= <<<[ruleDescriptor.tokenLabels,ruleDescriptor.tokenListLabels]    :{<labelType>    <it.label.text>;}; separator="\n"><[ruleDescriptor.tokenListLabels,ruleDescriptor.ruleListLabels]    :{pANTLR3_VECTOR    list_<it.label.text>;}; separator="\n"><[ruleDescriptor.ruleLabels,ruleDescriptor.ruleListLabels]    :ruleLabelDef(label=it); separator="\n">>>ruleLabelInitializations() ::= <<<[ruleDescriptor.tokenLabels,ruleDescriptor.tokenListLabels]    :{<it.label.text>       = NULL;}; separator="\n"><[ruleDescriptor.tokenListLabels,ruleDescriptor.ruleListLabels]    :{list_<it.label.text>     = NULL;}; separator="\n"><[ruleDescriptor.ruleLabels,ruleDescriptor.ruleListLabels]    :ruleLabelInitVal(label=it); separator="\n"><if(ruleDescriptor.hasMultipleReturnValues)><if(!ruleDescriptor.isSynPred)>retval.start = LT(1);<\n><endif><endif>>>lexerRuleLabelDefs() ::= <<<[ruleDescriptor.tokenLabels,  ruleDescriptor.tokenListLabels,  ruleDescriptor.ruleLabels]    :{<labelType> <it.label.text>;}; separator="\n"><ruleDescriptor.charLabels:{ANTLR3_UINT32 <it.label.text>;}; separator="\n"><[ruleDescriptor.tokenListLabels,  ruleDescriptor.ruleListLabels,  ruleDescriptor.ruleListLabels]    :{pANTLR3_INT_TRIE list_<it.label.text>;}; separator="\n">>>lexerRuleLabelInit() ::= <<<[ruleDescriptor.tokenLabels,  ruleDescriptor.tokenListLabels,  ruleDescriptor.ruleLabels]    :{<it.label.text> = NULL;}; separator="\n"><[ruleDescriptor.tokenListLabels,  ruleDescriptor.ruleListLabels,  ruleDescriptor.ruleListLabels]    :{list_<it.label.text> = antlr3IntTrieNew(31);}; separator="\n">>>lexerRuleLabelFree() ::= <<<[ruleDescriptor.tokenLabels,  ruleDescriptor.tokenListLabels,  ruleDescriptor.ruleLabels]    :{<it.label.text> = NULL;}; separator="\n"><[ruleDescriptor.tokenListLabels,  ruleDescriptor.ruleListLabels,  ruleDescriptor.ruleListLabels]    :{list_<it.label.text>->free(list_<it.label.text>);}; separator="\n">>>ruleReturnValue() ::= <<<if(!ruleDescriptor.isSynPred)><if(ruleDescriptor.hasReturnValue)><if(ruleDescriptor.hasSingleReturnValue)><ruleDescriptor.singleValueReturnName><else>retval<endif><endif><endif>>>memoize() ::= <<<if(memoize)><if(backtracking)>if ( BACKTRACKING>0 ) { MEMOIZE(<ruleDescriptor.index>, <ruleDescriptor.name>_StartIndex); }<endif><endif>>>ruleCleanUp() ::= <<goto rule<ruleDescriptor.name>Ex; /* Prevent compiler warnings */rule<ruleDescriptor.name>Ex: ;<ruleDescriptor.useScopes:{<scopePop(sname=it)>;}; separator="\n"><ruleDescriptor.ruleScope:{<scopePop(sname=it.name)>;}; separator="\n"><if(ruleDescriptor.hasMultipleReturnValues)><if(!TREE_PARSER)><if(!ruleDescriptor.isSynPred)>retval.stop = LT(-1);<\n><endif><endif><endif>>>/** How to generate a rule in the lexer; naked blocks are used for *  fragment rules, which do not produce tokens. */lexerRule(ruleName,nakedBlock,ruleDescriptor,block,memoize) ::= <<//   Comes from: <block.description>/** \brief Lexer rule generated by ANTLR3 * * $ANTLR start <ruleName> * * Looks to match the chracters the constitute the token <ruleName> * from the attached input stream. * * * \remark *  - lexer->error == ANTLR3_TRUE if an exception was thrown. */static ANTLR3_INLINEvoid m<ruleName>(p<name> ctx<if(ruleDescriptor.parameterScope)>, <endif><ruleDescriptor.parameterScope:parameterScope(scope=it)>){	ANTLR3_UINT32	_type;    <ruleDeclarations()>    <ruleDescriptor.actions.declarations>    <lexerRuleLabelDefs()>    <if(trace)>System.out.println("enter <ruleName> '"+(char)LA(1)+"' line="+GETLINE()+":"+GETCHARPOSITIONINLINE()+" failed="+failed+" backtracking="+BACKTRACKING);<endif><if(nakedBlock)>    <ruleMemoization(name=ruleName)>    <lexerRuleLabelInit()>    <ruleDescriptor.actions.init>            <block><\n><else>    <ruleMemoization(name=ruleName)>       <lexerRuleLabelInit()>    _type	    = <ruleName>;           <ruleDescriptor.actions.init>        <block>	LEXER->type = _type;<endif>    <if(trace)> fprintf(stderr, "exit <ruleName> '%c' line=%d:%d failed = %d, backtracking =%d\n",LA(1),GETLINE(),GETCHARPOSITIONINLINE(),failed,BACKTRACKING);<endif>    <ruleCleanUp()>    <lexerRuleLabelFree()>    <(ruleDescriptor.actions.after):execAction()>    <memoize>}// $ANTLR end <ruleName>>>/** How to generate code for the implicitly-defined lexer grammar rule *  that chooses between lexer rules. */tokensRule(ruleName,nakedBlock,args,block,ruleDescriptor) ::= <</** This is the entry point in to the lexer from an object that *  wants to generate the next token, such as a pCOMMON_TOKEN_STREAM */static void mTokens(p<name> ctx){    <block><\n>        goto ruleTokensEx; /* Prevent compiler warnings */ruleTokensEx: ;}>>// S U B R U L E S/** A (...) subrule with multiple alternatives */block(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<// <fileName>:<description>{    int alt<decisionNumber>=<maxAlt>;    <decls>    <@predecision()>    <decision>    <@postdecision()>    <@prebranch()>    switch (alt<decisionNumber>)     {	<alts:altSwitchCase()>    }    <@postbranch()>}>>/** A rule block with multiple alternatives */ruleBlock(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<{    //  <fileName>:<description>        ANTLR3_UINT32 alt<decisionNumber>;    alt<decisionNumber>=<maxAlt>;    <decls>    <@predecision()>    <decision>    <@postdecision()>    switch (alt<decisionNumber>)     {	<alts:altSwitchCase()>    }}>>ruleBlockSingleAlt(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,description) ::= <<// <fileName>:<description><decls><@prealt()><alts><@postalt()>>>/** A special case of a (...) subrule with a single alternative */blockSingleAlt(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,description) ::= <<// <fileName>:<description><decls><@prealt()><alts><@postalt()>>>/** A (..)+ block with 1 or more alternatives */positiveClosureBlock(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<// <fileName>:<description>{    int cnt<decisionNumber>=0;    <decls>    <@preloop()>    for (;;)    {        int alt<decisionNumber>=<maxAlt>;	<@predecision()>	<decision>	<@postdecision()>	switch (alt<decisionNumber>) 	{	    <alts:altSwitchCase()>	    default:	    		if ( cnt<decisionNumber> >= 1 )		{		    goto loop<decisionNumber>; /* Ah well, generated code or I'd shoot myself */		}		<ruleBacktrackFailure()>		<earlyExitEx()>		<@earlyExitException()>		goto rule<ruleDescriptor.name>Ex;	}	cnt<decisionNumber>++;    }    loop<decisionNumber>: ;	/* Jump to here if this rule does not match */    <@postloop()>}>>earlyExitEx() ::= <</* mismatchedSetEx() */CONSTRUCTEX();EXCEPTION->type = ANTLR3_EARLY_EXIT_EXCEPTION;EXCEPTION->name = ANTLR3_EARLY_EXIT_NAME;<\n>>>positiveClosureBlockSingleAlt ::= positiveClosureBlock/** A (..)* block with 1 or more alternatives */closureBlock(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<// <fileName>:<description><decls><@preloop()>for (;;){    int alt<decisionNumber>=<maxAlt>;    <@predecision()>    <decision>    <@postdecision()>    switch (alt<decisionNumber>)     {	<alts:altSwitchCase()>	default:	    goto loop<decisionNumber>;	/* break out of the loop */	    break;    }}loop<decisionNumber>: ; /* Jump out to here if this rule does not match */<@postloop()>>>closureBlockSingleAlt ::= closureBlock/** Optional blocks (x)? are translated to (x|) by antlr before code generation *  so we can just use the normal block template */optionalBlock ::= blockoptionalBlockSingleAlt ::= block/** A case in a switch that jumps to an alternative given the alternative *  number.  A DFA predicts the alternative and then a simple switch *  does the jump to the code that actually matches that alternative. */altSwitchCase() ::= <<case <i>:    <@prealt()>    <it>    break;<\n>>>/** An alternative is just a list of elements; at outermost level */alt(elements,altNum,description,autoAST,outerAlt) ::= <<// <fileName>:<description>{    <@declarations()>    <@initializations()>    <elements:element()>    <@cleanup()>}>>// E L E M E N T S/** Dump the elements one per line */element() ::= <<<@prematch()><it.el><\n>>>/** match a token optionally with a label in front */tokenRef(token,label,elementIndex) ::= <<<if(label)><label> = (<labelType>)LT(1);<\n><endif>MATCHT(<token>, &FOLLOW_<token>_in_<ruleName><elementIndex>); <checkRuleBacktrackFailure()>>>/** ids+=ID */tokenRefAndListLabel(token,label,elementIndex) ::= <<<tokenRef(...)><listLabel(elem=label,...)>>>listLabel(label,elem) ::= <<if (list_<label> == NULL){    list_<label>=ctx->vectors->newVector(ctx->vectors);}list_<label>->add(list_<label>, <elem>, NULL);>>/** match a character */charRef(char,label) ::= <<<if(label)><label> = LA(1);<\n><endif>MATCHC(<char>); <checkRuleBacktrackFailure()>>>/** match a character range */charRangeRef(a,b,label) ::= <<<if(label)><label> = LA(1);<\n><endif>MATCHRANGE(<a>, <b>); 

⌨️ 快捷键说明

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