📄 c.stg
字号:
/** 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) ::= <</* lexerRule(ruleName,nakedBlock,ruleDescriptor,block,memoize) *//** \brief Lexer rule generated by ANTLR3 * * $ANTLR start <ruleName> * * Looks to match the chracters the constitute the token <ruleName> * from the attached input stream. * * Comes from: <block.description> * * \remark * - lexer->error == ANTLR3_TRUE if an exception was thrown. */staticvoid m<ruleName>(p<name> ctx<if(ruleDescriptor.parameterScope)>, <endif><ruleDescriptor.parameterScope:parameterScope(scope=it)>){ <if(trace)>System.out.println("enter <ruleName> '"+(char)LA(1)+"' line="+getLine()+":"+getCharPositionInLine()+" failed="+failed+" backtracking="+backtracking);<endif> <ruleDeclarations()> <ruleLabelDefs()> <ruleInitializations()> <ruleLabelInitializations()><if(nakedBlock)> ctx->pLexer->ruleNestingLevel++; <ruleDescriptor.actions.init> <ruleMemoization(name=ruleName)> <block><\n><else> ANTLR3_UINT32 type; ANTLR3_UINT64 start; ANTLR3_UINT64 line; ANTLR3_UINT32 charPosition; ANTLR3_UINT32 channel; ctx->pLexer->ruleNestingLevel++; type = <ruleName>; start = getCharIndex(); line = getLine(); charPosition = getCharPositionInLine(); channel = ANTLR3_TOKEN_DEFAULT_CHANNEL; <ruleDescriptor.actions.init> <ruleMemoization(name=ruleName)> <block> <! create token if none exists *and* we are an outermost token rule !> <execAction({ if ( ltoken() == NULL && !hasException()) { emitNew(type,line,charPosition,channel,start,getCharIndex()-1); }<\n> } )><endif> ctx->pLexer->ruleNestingLevel--; <if(trace)> -- Convert to C Jim!!! System.out.println("exit <ruleName> '"+(char)LA(1)+"' line="+getLine()+":"+getCharPositionInLine()+" failed="+failed+" backtracking="+backtracking);<endif> <ruleCleanUp()> <(ruleDescriptor.actions.finally):execAction()>}// $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) ::= <</* 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) ::= <</* 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) ::= <<{ /* 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) ::= <</* 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) ::= <</* 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) ::= <</* 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() */exConstruct();theException()->type = ANTLR3_EARLY_EXIT_EXCEPTION;theException()->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) ::= <</* 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() ::= <</* altSwitchCase() */case <i>: <@prealt()> <it> break;<\n>>>/** An alternative is just a list of elements; at outermost level */alt(elements,altNum,description,autoAST,outerAlt) ::= <</* 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() ::= <</* element() */<@prematch()><it.el><\n>>>/** match a token optionally with a label in front */tokenRef(token,label,elementIndex) ::= <</* tokenRef(token,label,elementIndex) */<if(label)><label> = (<labelType>)LT(1);<\n><endif>tmatch(<token>, FOLLOW_<token>_in_<ruleName><elementIndex>); <checkRuleBacktrackFailure()>>>/** ids+=ID */tokenRefAndListLabel(token,label,elementIndex) ::= <</* tokenRefAndListLabel(token,label,elementIndex) */<tokenRef(...)><listLabel(...)>>>listLabel(label) ::= <</* listLabel(label) */if (list_<label> == NULL){ list_<label>=ctx->vectors->newVector(ctx->vectors);}list_<label>->add(list_<label>, <label>, NULL);>>/** match a character */charRef(char,label) ::= <</* charRef(char,label) */<if(label)><label> = LA(1);<\n><endif>matchc(<char>); <checkRuleBacktrackFailure()>>>/** match a character range */charRangeRef(a,b) ::= <</* charRangeRef(a,b) */matchRange(<a>, <b>); <checkRuleBacktrackFailure()>>>/** For now, sets are interval tests and must be tested inline */matchSet(s,label,elementIndex,postmatchCode="") ::= <</* matchSet(s,label,elementIndex,postmatchCode="") */<if(label)><label>=(<labelType>)LT(1);<\n><endif>if ( <s> ) { <postmatchCode> inputConsume();<if(!LEXER)> perrorRecovery()=ANTLR3_FALSE;<endif> <if(backtracking)>failedFlag=ANTLR3_FALSE;<\n><endif>}else { <ruleBacktrackFailure()> <mismatchedSetEx()> <@mismatchedSetException()><if(LEXER)> lrecover();<else> precoverFromMismatchedSet(FOLLOW_set_in_<ruleName><elementIndex>);<endif> goto rule<ruleDescriptor.name>Ex;}<\n>>>mismatchedSetEx() ::= <</* mismatchedSetEx() */exConstruct();theException()->type = ANTLR3_MISMATCHED_SET_EXCEPTION;theException()->name = ANTLR3_MISMATCHED_SET_NAME;<if(PARSER)>theException()->expectingSet = FOLLOW_set_in_<ruleName><elementIndex>;<endif>>>matchSetAndListLabel(s,label,elementIndex,postmatchCode) ::= <</* matchSetAndListLabel(s,label,elementIndex,postmatchCode) */<matchSet(...)><listLabel(...)>>>/** Match a string literal */lexerStringRef(string,label) ::= <</* lexerStringRef(string,label) */<if(label)>int <label>Start = getCharIndex();matchs(<string>); <checkRuleBacktrackFailure()><labelType> <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()->tnstream->istream;<else>matchs(<string>); <checkRuleBacktrackFailure()><\n><endif>>>wildcard(label,elementIndex) ::= <</* wildcard(label,elementIndex) */<if(label)><label>=(<labelType>)LT(1);<\n><endif>tmatchAny(); <checkRuleBacktrackFailure()>>>wildcardAndListLabel(label,elementIndex) ::= <</* wildcardAndListLabel(label,elementIndex) */<wildcard(...)><listLabel(...)>>>/** Match . wildcard in lexer */wildcardChar(label, elementIndex) ::= <</* wildcardChar(label, elementIndex) */<if(label)>int <label> = LA(1);<\n><endif>matchAny(); <checkRuleBacktrackFailure()>>>wildcardCharListLabel(label, elementIndex) ::= <</* wildcardCharListLabel(label, elementIndex) */<wildcardChar(...)><listLabel(...)>>>/** Match a rule reference by invoking it possibly with arguments * and a return value or values. */ruleRef(rule,label,elementIndex,args) ::= <</* 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>if (hasException()){ goto rule<ruleDescriptor.name>Ex;}_fsp--;<checkRuleBacktrackFailure()>>>/** ids+=ID */ruleRefAndListLabel(rule,label,elementIndex,args) ::= <</* ruleRefAndListLabel(rule,label,elementIndex,args) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -