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

📄 c.stg

📁 ANTLR(ANother Tool for Language Recognition)它是这样的一种工具
💻 STG
📖 第 1 页 / 共 5 页
字号:
<ruleRef(...)><listLabel(...)>>>/** A lexer rule reference */lexerRuleRef(rule,label,args) ::= <</* lexerRuleRef(rule,label,args) * From: <description> */<if(label)>{    ANTLR3_UINT64 <label>Start = getCharIndex();    m<rule>(ctx <if(args)>, <endif><args; separator=", ">);     <checkRuleBacktrackFailure()>    <label> = lexr->tokFactory->newToken(lexr->tokFactory);    <label>->setType(<label>, ANTLR3_TOKEN_INVALID);    <label>->setStartIndex(<label>, <label>Start);    <label>->setStopIndex(<label>, getCharIndex()-1);    <label>->input = theInput();}<else>m<rule>(ctx <if(args)>, <endif><args; separator=", ">); <checkRuleBacktrackFailure()><endif>>>/** EOF in the lexer */lexerMatchEOF(label) ::= <</* lexerMatchEOF(label) */<if(label)>{    int <label>Start = getCharIndex();    <labelType> <label>;    matchc(ANTLR3_CHARSTREAM_EOF);     <checkRuleBacktrackFailure()>    <label> = lexr->tokFactory->newToken(lexr->tokFactory);    <label>->setType(<label>, ANTLR3_TOKEN_EOF);    <label>->setStartIndex(<label>, <label>Start);    <label>->setStopIndex(<label>, getCharIndex()-1);    <label>->input = theInput()->tnstream->istream;}<else>    matchc(ANTLR3_CHARSTREAM_EOF);     <checkRuleBacktrackFailure()>    <endif>>>/** match ^(root children) in tree parser */tree(root, children, nullableChildList) ::= <</* tree(root, children) */<root:element()><if(nullableChildList)>if ( LA(1)==ANTLR3_TOKEN_DOWN ) {    tmatch(ANTLR3_TOKEN_DOWN, NULL);     <checkRuleBacktrackFailure()>    <children:element()>    tmatch(ANTLR3_TOKEN_UP, NULL);     <checkRuleBacktrackFailure()>}<else>tmatch(ANTLR3_TOKEN_DOWN, NULL); <checkRuleBacktrackFailure()><children:element()>tmatch(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) ::= <</* validateSemanticPredicate(pred,description)  */if ( !(<evalPredicate(...)>) ) {    <ruleBacktrackFailure()>    <newFPE(...)>}>>newFPE() ::= <<    /* newFPE()     */    exConstruct();    theException()->type         = ANTLR3_FAILED_PREDICATE_EXCEPTION;    theException()->message      = "<description>";    theException()->ruleName	 = "<ruleName>";    <\n>>>// F i x e d  D F A  (if-then-else)dfaState(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <</* dfaState(k,edges,eotPredictsAlt,description,stateNumber) */{<if(!semPredState)>    int LA<decisionNumber>_<stateNumber> = LA(<k>);<endif>    <edges; separator="\nelse ">    else     {<if(eotPredictsAlt)>        alt<decisionNumber>=<eotPredictsAlt>;<else>        <ruleBacktrackFailure()>            <newNVException()>            goto rule<ruleDescriptor.name>Ex;<endif>    }}>>newNVException() ::= <</* newNVException() */exConstruct();theException()->type         = ANTLR3_NO_VIABLE_ALT_EXCEPTION;theException()->message      = "<description>";theException()->decisionNum  = <decisionNumber>;theException()->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) ::= <</* dfaOptionalBlockState(k,edges,eotPredictsAlt,description,stateNumber,sempredState) */{    <if(!semPredState)>    int LA<decisionNumber>_<stateNumber> = LA(<k>);    <endif>    <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()::= <</* dfaLoopbackStateDecls(decisionNumber) */ANTLR3_UINT32   LA<decisionNumber>_<stateNumber>;>>dfaLoopbackState(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<{   /* dfaLoopbackState(k,edges,eotPredictsAlt,description,stateNumber,semPredState)    */    <if(!semPredState)>    int LA<decisionNumber>_<stateNumber> = LA(<k>);    <endif>    <edges; separator="\nelse "><\n>    <if(eotPredictsAlt)>    else     {	alt<decisionNumber>=<eotPredictsAlt>;    }<\n>    <endif>}>>/** An accept state indicates a unique alternative has been predicted */dfaAcceptState(alt) ::= "alt<decisionNumber>=<alt>; /* dfaAcceptState(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) ::= <</* dfaEdge(labelExpr, targetState, predicates) */if ( (<labelExpr>) <if(predicates)>&& (<predicates>)<endif>) {    <targetState>}>>// 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) ::= <</* 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) ::= <</* dfaOptionalBlockStateSwitch(k,edges,eotPredictsAlt,description,stateNumber) */switch ( LA(<k>) ) {    <edges; separator="\n">}<\n>>>dfaLoopbackStateSwitch(k, edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <</* 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) ::= <</* 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) ::= <</* dfaDecision(decisionNumber,description) */alt<decisionNumber> = cdfa<decisionNumber>.predict(ctx, rec, theInput()->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_INT16 dfa<dfa.decisionNumber>_eot[<dfa.numberOfStates>] =    {	<dfa.eot; wrap="\n", separator=", ", null="-1">    };static const ANTLR3_INT16 dfa<dfa.decisionNumber>_eof[<dfa.numberOfStates>] =    {	<dfa.eof; wrap="\n", separator=", ", null="-1">    };static const ANTLR3_INT16 dfa<dfa.decisionNumber>_min[<dfa.numberOfStates>] =    {	<dfa.min; wrap="\n", separator=", ", null="-1">    };static const ANTLR3_INT16 dfa<dfa.decisionNumber>_max[<dfa.numberOfStates>] =    {	<dfa.max; wrap="\n", separator=", ", null="-1">    };static const ANTLR3_INT16 dfa<dfa.decisionNumber>_accept[<dfa.numberOfStates>] =    {	<dfa.accept; wrap="\n", separator=", ", null="-1">    };static const ANTLR3_INT16 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_INT16 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_INT16 * const dfa<dfa.decisionNumber>_transitions[] ={    <dfa.transitionEdgeTables:{xref|dfa<dfa.decisionNumber>_T<xref>}; separator=", ", wrap="\n", null="_empty">	};<if(dfa.specialStateSTs)>static ANTLR3_INT16 dfa<dfa.decisionNumber>_sst(p<name> ctx, pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_INT_STREAM is, pANTLR3_CYCLIC_DFA dfa, ANTLR3_UINT32 s){    ANTLR3_INT16    _s;        _s	    = s;    switch  (s)    {    <dfa.specialStateSTs:{state |    case <i0>:    	<state>}; separator="\n">    }<if(backtracking)>    if (backtracking > 0)    {	failedFlag = ANTLR3_TRUE;	return	-1;    }<endif>        exConstruct();    theException()->type         = ANTLR3_NO_VIABLE_ALT_EXCEPTION;    theException()->message      = "<dfa.description>";    theException()->decisionNum  = <dfa.decisionNumber>;    theException()->state        = _s;    <@noViableAltException()>    return -1;}<endif><@errorMethod()>/* Declare tracking structure for Cyclic DFA <dfa.decisionNumber> */ANTLR3_CYCLIC_DFA cdfa<dfa.decisionNumber>    =	{	    <dfa.decisionNumber>,		    /* Decision number of this dfa	    */	    /* Which decision this represents:   */	    (const pANTLR3_UCHAR)"<dfa.description>",	<if(dfa.specialStateSTs)>	    (CDFA_SPECIAL_FUNC) dfa<dfa.decisionNumber>_sst,<else>	    (CDFA_SPECIAL_FUNC) antlr3dfaspecialStateTransition,	/* Default special state transition function	*/<endif>	    antlr3dfaspecialTransition,		/* DFA specialTransition is currently just a default function in the runtime */	    antlr3dfapredict,			/* DFA simulator function is in the runtime */	    dfa<dfa.decisionNumber>_eot,	    /* EOT table			    */	    dfa<dfa.decisionNumber>_eof,	    /* EOF table			    */	    dfa<dfa.decisionNumber>_min,	    /* Minimum tokens for each state    */	    dfa<dfa.decisionNumber>_max,	    /* Maximum tokens for each state    */	    dfa<dfa.decisionNumber>_accept,	/* Accept table			    */	    dfa<dfa.decisionNumber>_special,	/* Special transition states	    */	    dfa<dfa.decisionNumber>_transitions	/* Table of transition tables	    */	};	    /* End of Cyclic DFA <dfa.decisionNumber> * --------------------- */>>/** 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) ::= <<{    <if(semPredState)>    rewindLast();<\n>    <else>    int LA<decisionNumber>_<stateNumber> = LA(1);<\n>    <endif>    s = -1;    <edges; separator="\nelse ">    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) ::= <</* 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>(ctx)"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) ::= "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) ::= "(LA(<k>) \>= <lower> && LA(<k>) \<= <upper>)"setTest(ranges) ::= "<ranges; separator=\" || \">"// A T T R I B U T E SmakeScopeSet() ::= <</* makeScopeSet()  */ /** Definition of the <scope.name> scope variable tracking *  structure. A

⌨️ 快捷键说明

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