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

📄 objc.stg

📁 antlr最新版本V3源代码
💻 STG
📖 第 1 页 / 共 3 页
字号:
<endif><if(memoize)>int <ruleDescriptor.name>_StartIndex = [input index];<endif>>>ruleScopeSetUp() ::= <<<ruleDescriptor.useScopes:{[<name>_<it>_stack addObject:[[[<name><it>Scope alloc] init] autorelease]];}; separator="\n"><ruleDescriptor.ruleScope:{[<name>_<it.name>_stack addObject:[[[<name><it.name>Scope alloc] init] autorelease]];}; separator="\n">>>ruleScopeCleanUp() ::= <<<ruleDescriptor.useScopes:{[<name>_<it>_stack removeLastObject];}; separator="\n"><ruleDescriptor.ruleScope:{[<name>_<it.name>_stack removeLastObject];}; separator="\n">>>ruleLabelDefs() ::= <<<[ruleDescriptor.tokenLabels,ruleDescriptor.tokenListLabels]    :{<labelType> _<it.label.text> = nil;}; separator="\n"><[ruleDescriptor.tokenListLabels,ruleDescriptor.ruleListLabels]    :{NSMutableArray *_list_<it.label.text> = nil;}; separator="\n"><[ruleDescriptor.ruleLabels,ruleDescriptor.ruleListLabels]    :ruleLabelDef(label=it); separator="\n"><[ruleDescriptor.allRuleRefsInAltsWithRewrites,ruleDescriptor.allTokenRefsInAltsWithRewrites]    :{NSMutableArray *_list_<it> = [[NSMutableArray alloc] init];}; separator="\n">>>ruleReturnValue() ::= <<<if(!ruleDescriptor.isSynPred)><if(ruleDescriptor.hasReturnValue)><if(ruleDescriptor.hasSingleReturnValue)>_<ruleDescriptor.singleValueReturnName><else>_retval<endif><endif><endif>>>ruleCleanUp() ::= <<// token labels<[ruleDescriptor.tokenLabels]:{[_<it.label.text> release];}; separator="\n">// token+rule list labels<[ruleDescriptor.tokenListLabels,ruleDescriptor.ruleListLabels]:{[_list_<it.label.text> release];}; separator="\n">// rule labels<[ruleDescriptor.ruleLabels]:{[_<it.label.text> release];}; separator="\n">// rule refs in alts with rewrites<[ruleDescriptor.allRuleRefsInAltsWithRewrites,ruleDescriptor.allTokenRefsInAltsWithRewrites]	:{[_list_<it> release];}; separator="\n"><if(ruleDescriptor.hasMultipleReturnValues)>[_retval setStop:[input LT:-1]];<\n><endif><if(memoize)><if(backtracking)>if ( backtracking>0 ) { [self memoize:input ruleIndex:<ruleDescriptor.index> startIndex:<ruleDescriptor.name>_StartIndex]; }<endif><endif>>>/** How to generate a rule in the lexer; naked blocks are used for *  fragment rules. */lexerRule(ruleName,nakedBlock,ruleDescriptor,block, memoize) ::= <<- (void) m<ruleName><if(ruleDescriptor.parameterScope)><ruleDescriptor.parameterScope:parameterScope(scope=it)><endif>{    <if(trace)>NSLog(@"enter <ruleName> %C line=%d:%d failed=%@ backtracking=%d", [input LA:1], [self line], [self charPositionInLine], failed ? @"YES" : @"NO", backtracking);<endif>	<ruleDeclarations()>	<ruleLabelDefs()>	@try {		ruleNestingLevel++;<ruleDescriptor.actions.init><if(nakedBlock)>        <ruleMemoization(name=ruleName)>		<block><\n><else>		int _type = <name>_<ruleName>;		int _start = [self charIndex];		int _line = [self line];		int _charPosition = [self charPositionInLine];		int _channel = [ANTLRToken defaultChannel];		<block>		if ( token == nil && ruleNestingLevel == 1) { [self emitTokenWithType:_type line:_line charPosition:_charPosition channel:_channel start:_start stop:[self charIndex]];}<\n><endif>	}	@finally {		ruleNestingLevel--;        <if(trace)>NSLog(@"exit <ruleName> %C line=%d:%d failed=%@ backtracking=%d", [input LA:1], [self line], [self charPositionInLine], failed ? @"YES" : @"NO", backtracking);<endif>        // rule cleanup		<ruleCleanUp()><if(backtracking)>		if ( backtracking == 0 ) {			<ruleDescriptor.actions.finally>		}<\n><else>		<ruleDescriptor.actions.finally><endif>	}	return;}// $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) ::= <<- (void) mTokens{    <block><\n>}>>// 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> // blockint 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> //ruleblockint alt<decisionNumber>=<maxAlt>;<decls><@predecision()><decision><@postdecision()>switch (alt<decisionNumber>) {	<alts:altSwitchCase()>}>>ruleBlockSingleAlt(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,description) ::= <<// <fileName>:<description> // ruleBlockSingleAlt<decls><@prealt()><alts><@postalt()>>>/** A special case of a (...) subrule with a single alternative */blockSingleAlt(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,description) ::= <<// <fileName>:<description> // blockSingleAlt<decls><@prealt()><alts><@postalt()>>>/** A (..)+ block with 0 or more alternatives */positiveClosureBlock(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<// <fileName>:<description>	// positiveClosureBlockint cnt<decisionNumber>=0;<decls><@preloop()>do {    int alt<decisionNumber>=<maxAlt>;    <@predecision()>    <decision>    <@postdecision()>    switch (alt<decisionNumber>) {	<alts:altSwitchCase()>	default :	    if ( cnt<decisionNumber> >= 1 )  goto loop<decisionNumber>;	    <if(backtracking)>            <ruleBacktrackFailure()>            <endif>			ANTLREarlyExitException *eee = [ANTLREarlyExitException exceptionWithStream:input decisionNumber:<decisionNumber>];			<@earlyExitException()>			@throw eee;    }    cnt<decisionNumber>++;} while (YES); loop<decisionNumber>: ;<@postloop()>>>positiveClosureBlockSingleAlt ::= positiveClosureBlock/** A (..)* block with 0 or more alternatives */closureBlock(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<<decls><@preloop()>do {    int alt<decisionNumber>=<maxAlt>;    <@predecision()>    <decision>    <@postdecision()>    switch (alt<decisionNumber>) {	<alts:altSwitchCase()>	default :	    goto loop<decisionNumber>;    }} while (YES); loop<decisionNumber>: ;<@postloop()>>>closureBlockSingleAlt ::= closureBlock/** Optional blocks (x)? are translated to (x|) by 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> // alt{<@declarations()><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>)[input LT:1];[_<label> retain];<\n><endif>[self match:input tokenType:<token> follow:FOLLOW_<token>_in_<ruleName><elementIndex>]; <checkRuleBacktrackFailure()>>>/** ids+=ID */tokenRefAndListLabel(token,label,elementIndex) ::= <<<tokenRef(...)><listLabel(...)>>>listLabel(label) ::= <<if (_list_<label> == nil)	_list_<label> = [[NSMutableArray alloc] initWithObjects:_<label>, nil];else	[_list_<label> addObject:_<label>];>>/** match a character */charRef(char,label) ::= <<<if(label)>int _<label> = [input LA:1];<\n><endif>[self matchChar:<char>];<checkRuleBacktrackFailure()><\n>>>/** match a character range */charRangeRef(a,b) ::= "[self matchRangeFromChar:<a> to:<b>];<checkRuleBacktrackFailure()>"/** For now, sets are interval tests and must be tested inline */matchSet(s,label,elementIndex,postmatchCode="") ::= <<<if(label)>_<label> = (<labelType>)[input LT:1];<\n><endif>if (<s>) {	<postmatchCode>	[input consume];<if(!LEXER)>	errorRecovery = NO;<endif>	<if(backtracking)>failed = NO;<endif>} else {	<ruleBacktrackFailure()>	ANTLRMismatchedSetException *mse = [ANTLRMismatchedSetException exceptionWithSet:nil stream:input];	<@mismatchedSetException()><if(LEXER)>	[self recover:mse];<else>	[self recoverFromMismatchedSet:input exception:mse follow:FOLLOW_set_in_<ruleName><elementIndex>];<endif>	@throw mse;}<\n>>>matchSetAndListLabel(s,label,elementIndex,postmatchCode) ::= <<<matchSet(...)><listLabel(...)>>>/** Match a string literal */lexerStringRef(string,label) ::= <<<if(label)>int _<label>Start = [self charIndex];[self matchString:<string>];<checkRuleBacktrackFailure()>_<label> = [[ANTLRCommonToken alloc] initWithInput:input tokenType:ANTLRTokenTypeInvalid channel:ANTLRTokenChannelDefault start:_<label>Start, stop:[self charIndex]];<else>[self matchString:<string>];<checkRuleBacktrackFailure()><\n><endif>>>wildcard(label,elementIndex) ::= <<<if(label)>_<label> = (<labelType>)[input LT:1];<\n><endif>[self matchAny:input];<checkRuleBacktrackFailure()>>>wildcardAndListLabel(label,elementIndex) ::= <<<wildcard(...)><listLabel(...)>>>/** Match . wildcard in lexer */wildcardChar(label, elementIndex) ::= <<<if(label)>int _<label> = [input LA:1];<\n><endif>[self matchAny];<checkRuleBacktrackFailure()><\n>>>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) ::= <<[following addObject:FOLLOW_<rule>_in_<ruleName><elementIndex>];<if(label)>_<label> = [self <rule><if(args)>:<args; separator=" :"><endif>];<\n><else>[self <rule><if(args)>:<args; separator=" :"><endif>];<\n><endif>[following removeLastObject];<checkRuleBacktrackFailure()><\n>>>/** ids+=ID */ruleRefAndListLabel(rule,label,elementIndex,args) ::= <<<ruleRef(...)><listLabel(...)>>>/** A lexer rule reference */lexerRuleRef(rule,label,args) ::= <<<if(label)>int _<label>Start = [self charIndex];[self m<rule><if(args)>:<args; separator=" :"><endif>];<checkRuleBacktrackFailure()><\n>_<label> = [[ANTLRCommonToken alloc] initWithInput:input tokenType:ANTLRTokenTypeInvalid channel:ANTLRTokenChannelDefault start:_<label>Start stop:[self charIndex]];[_<label> setLine:[self line]];<else>[self m<rule><if(args)>:<args; separator=" :"><endif>];<checkRuleBacktrackFailure()><\n><endif>>>/** EOF in the lexer */lexerMatchEOF(label) ::= <<<if(label)>int _<label>Start = [self charIndex];[self matchChar:ANTLRCharStreamEOF];<checkRuleBacktrackFailure()><\n><labelType> _<label> = [[ANTLRCommonToken alloc] initWithInput:input tokenType:ANTLRTokenTypeEOF channel:ANTLRTokenChannelDefault start:_<label>Start stop:[self charIndex]];[_<label> setLine:[self line]];<else>[self matchChar:ANTLRCharStreamEOF];<checkRuleBacktrackFailure()><\n><endif>>>/** match ^(root children) in tree parser */tree(root, children,nullableChildList) ::= <<<root:element()><if(nullableChildList)>if ( [input LA:1] == ANTLRTokenTypeDOWN ) {    [self match:input tokenType:ANTLRTokenTypeDOWN follow:nil]; <checkRuleBacktrackFailure()>    <children:element()>    [self match:input tokenType:ANTLRTokenTypeUP follow:nil]; <checkRuleBacktrackFailure()>}<else>[self match:input tokenType:ANTLRTokenTypeDOWN follow:nil]; <checkRuleBacktrackFailure()><children:element()>[self match:input tokenType:ANTLRTokenTypeUP follow:nil]; <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()>    @throw [ANTLRFailedPredicateException exceptionWithRuleName:@"<ruleName>" predicate:@"<description>" stream:input];}>>// F i x e d  D F A  (if-then-else)dfaState(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<{	int LA<decisionNumber>_<stateNumber> = [input LA:<k>];	<edges; separator="\nelse ">else {<if(eotPredictsAlt)>	alt<decisionNumber> = <eotPredictsAlt>;<else>	<ruleBacktrackFailure()>    ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException exceptionWithDecision:<decisionNumber> state:<stateNumber> stream:input];	<@noViableAltException()>	@throw nvae;<\n><endif>	}}>>/** 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> = [input 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. */dfaLoopbackState(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<{	int LA<decisionNumber>_<stateNumber> = [input LA:<k>];	<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>;"/** A simple edge with an expression.  If the expression is satisfied, *  enter to the target state.  To handle gated productions, we may

⌨️ 快捷键说明

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