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

📄 objc.stg

📁 antlr最新版本V3源代码
💻 STG
📖 第 1 页 / 共 3 页
字号:
/* [The "BSD licence"] Copyright (c) 2006 Kay Roepke All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright    notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright    notice, this list of conditions and the following disclaimer in the    documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products    derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*//*	Template group file for the Objective C code generator.	Heavily based on Java.stg	Written by Kay Roepke <kroepke(at)classdump.org>	This file is part of ANTLR and subject to the same license as ANTLR itself.*/group ObjC implements ANTLRCore;objcTypeInitMap ::= [	"int":"0",	"long":"0",	"float":"0.0",	"double":"0.0",	"boolean":"false",	"byte":"0",	"short":"0",	"char":"0",	"id":"nil",	default:"nil" // anything other than an atomic type]className() ::= "<name><! if(LEXER)>Lexer<else><if(TREE_PARSER)>Tree<endif>Parser<endif !>"/** The overall file structure of a recognizer; stores methods for rules *  and cyclic DFAs plus support code. */outputFile(LEXER,PARSER,TREE_PARSER, actionScope, actions,           docComment, recognizer,           name, tokens, tokenNames, rules, cyclicDFAs,	   bitsets, buildTemplate, profile,	   backtracking, synpreds, memoize, numRules,	   fileName, ANTLRVersion, generatedTimestamp, trace, scopes, superClass,literals) ::=<<// $ANTLR <ANTLRVersion> <fileName> <generatedTimestamp><@imports>#import "<name><!if(LEXER)>Lexer<else><if(TREE_PARSER)>Tree<endif>Parser<endif!>.h"<@end><docComment><recognizer>>>headerFile(LEXER,PARSER,TREE_PARSER, actionScope, actions,           docComment, recognizer,           name, tokens, tokenNames, rules, cyclicDFAs,	   bitsets, buildTemplate, profile,	   backtracking, synpreds, memoize, numRules,	   fileName, ANTLRVersion, generatedTimestamp, trace, scopes, superClass,literals) ::=<<// $ANTLR <ANTLRVersion> <fileName> <generatedTimestamp><@imports>#import \<Cocoa/Cocoa.h>#import \<ANTLR/ANTLR.h><@end><actions.(actionScope).header><if(LEXER)><lexerHeaderFile(...)><endif><if(PARSER)><parserHeaderFile(...)><endif><if(TREE_PARSER)><treeParserHeaderFile(...)><endif>>>lexerHeaderFile() ::=<<#pragma mark Cyclic DFA start<cyclicDFAs:cyclicDFAInterface()>#pragma mark Cyclic DFA end#pragma mark Rule return scopes start<rules:{rule |<rule.ruleDescriptor:returnScopeInterface(ruleDescriptor=rule.ruleDescriptor)>}>#pragma mark Rule return scopes end#pragma mark Tokens<tokens:{#define <name>_<it.name>	<it.type>}; separator="\n">@interface <className()> : ANTLRLexer {	<cyclicDFAs:{dfa | <name>DFA<dfa.decisionNumber> *dfa<dfa.decisionNumber>;}; separator="\n">	<synpreds:{p | SEL <p>SyntacticPredicate;}; separator="\n">	<actions.lexer.ivars>}<actions.lexer.methodsdecl><rules:{rule |- (<rule.ruleDescriptor:{ruleDescriptor|<returnType()>}>) <if(!rule.ruleDescriptor.isSynPred)>m<endif><rule.ruleName><if(rule.ruleDescriptor.parameterScope)><rule.ruleDescriptor.parameterScope:parameterScope(scope=it)><endif>;}>@end>>lexer(grammar, name, tokens, scopes, rules, numRules, labelType="ANTLRToken *",      filterMode) ::= <<#pragma mark Cyclic DFAs<cyclicDFAs:cyclicDFA()>/** As per Terence: No returns for lexer rules!#pragma mark Rule return scopes start<rules:{rule |<rule.ruleDescriptor:returnScope(ruleDescriptor=rule.ruleDescriptor)>}>#pragma mark Rule return scopes end*/@implementation <className()><actions.lexer.methods>- (id) initWithCharStream:(id\<ANTLRCharStream>)anInput{	if (nil!=(self = [super initWithCharStream:anInput])) {		<if(memoize)>		// init memoize facility		<endif>		<synpreds:{p | <lexerSynpred(name=p)>};separator="\n">		<cyclicDFAs:{dfa | dfa<dfa.decisionNumber> = [[<name>DFA<dfa.decisionNumber> alloc] initWithRecognizer:self];}; separator="\n">		<actions.lexer.init>	}	return self;}- (void) dealloc{	<cyclicDFAs:{dfa | [dfa<dfa.decisionNumber> release];}; separator="\n"><actions.lexer.dealloc>	[super dealloc];}- (NSString *) grammarFileName{	return @"<fileName>";}<if(actions.lexer.reset)>- (void) reset{<actions.lexer.reset>	[super reset];}<endif><if(filterMode)><filteringNextToken()><endif><rules; separator="\n\n">@end>>/** A override of Lexer.nextToken() that backtracks over mTokens() looking *  for matches.  No error can be generated upon error; just rewind, consume *  a token and then try again.  backtracking needs to be set as well. */filteringNextToken() ::= <<- (ANTLRToken *) nextToken{    while (YES) {        if ( [input LA:1] == ANTLRCharStreamEOF ) {            return nil; // should really be a +eofToken call here -> go figure        }        [self setToken:nil];        tokenStartCharIndex = [self charIndex];        @try {            int m = [input mark];            backtracking = 1;            failed = NO;            [self mTokens];            backtracking = 0;            if ( failed ) {                [input rewind:m];                [input consume]; <! // advance one char and try again !>            } else {                return token;            }        }        @catch (ANTLRRecognitionException *re) {            // shouldn't happen in backtracking mode, but...            [self reportError:re];            [self recover:re];        }    }}>>filteringActionGate() ::= "backtracking==1"treeParserHeaderFile(LEXER, PARSER, TREE_PARSER, actionScope, actions, docComment,           recognizer, name, tokens, tokenNames, rules, cyclicDFAs,           bitsets, buildTemplate, profile, backtracking, synpreds,           memoize, numRules, fileName, ANTLRVersion, generatedTimestamp, trace, scopes, superClass="ANTLRTreeParser") ::= <<<parserHeaderFile(...)>>>parserHeaderFile(LEXER, PARSER, TREE_PARSER, actionScope, actions, docComment,           recognizer, name, tokens, tokenNames, rules, cyclicDFAs,           bitsets, buildTemplate, profile, backtracking, synpreds,           memoize, numRules, fileName, ANTLRVersion, generatedTimestamp, trace, scopes, superClass="ANTLRParser") ::=<<#pragma mark Cyclic DFA<cyclicDFAs:cyclicDFAInterface()>#pragma mark Tokens<tokens:{#define <name>_<it.name>	<it.type>}; separator="\n">#pragma mark Dynamic Global Scopes<scopes:{<if(it.isDynamicGlobalScope)><globalAttributeScopeDecl(scope=it)><endif>}>#pragma mark Dynamic Rule Scopes<rules:{rule |<rule.ruleDescriptor.ruleScope:ruleAttributeScopeDecl(scope=it)>}>#pragma mark Rule Return Scopes<rules:{rule |<rule.ruleDescriptor:returnScopeInterface(ruleDescriptor=rule.ruleDescriptor)>}>@interface <className()> : <@superClassName><superClass><@end> {	<cyclicDFAs:{dfa | <name>DFA<dfa.decisionNumber> *dfa<dfa.decisionNumber>;}; separator="\n">	<synpreds:{p | SEL <p>SyntacticPredicate;}; separator="\n">	<scopes:{<if(it.isDynamicGlobalScope)><globalAttributeScopeIVar(scope=it)><endif>}>	<rules:{rule |	<rule.ruleDescriptor.ruleScope:ruleAttributeScopeIVar(scope=it)>	}>	<@ivars()>	<actions.parser.ivars> }<actions.parser.methodsdecl><rules:{rule |- (<rule.ruleDescriptor:{ruleDescriptor|<returnType()>}>) <rule.ruleName><if(rule.ruleDescriptor.parameterScope)><rule.ruleDescriptor.parameterScope:parameterScope(scope=it)><endif>;}><@methodsdecl()>@end>>/** How to generate a parser */genericParser(name, scopes, tokens, tokenNames, rules, numRules,              cyclicDFAs, bitsets, inputStreamType, superClass,              ASTLabelType="id", labelType, members) ::= <<#pragma mark Cyclic DFA<cyclicDFAs:cyclicDFA()>#pragma mark Bitsets<bitsets:bitset(name={FOLLOW_<it.name>_in_<it.inName><it.tokenIndex>}, words64=it.bits)>#pragma mark Dynamic Global Scopes<scopes:{<if(it.isDynamicGlobalScope)><globalAttributeScopeImpl(scope=it)><endif>}>#pragma mark Dynamic Rule Scopes<rules:{rule |<rule.ruleDescriptor.ruleScope:ruleAttributeScopeImpl(scope=it)>}>#pragma mark Rule return scopes start<rules:{rule |<rule.ruleDescriptor:returnScope(ruleDescriptor=rule.ruleDescriptor)>}>@implementation <className()>+ (void) initialize{	<bitsets:bitsetInit(name={FOLLOW_<it.name>_in_<it.inName><it.tokenIndex>}, words64=it.bits)>}<if(PARSER)>- (id) initWithTokenStream:(<inputStreamType>)aStream{	if ((self = [super initWithTokenStream:aStream])) {<else><!TREE_PARSER!>- (id) initWithTreeNodeStream:(<inputStreamType>)aStream{	if ((self = [super initWithTreeNodeStream:aStream])) {<endif><\n>		tokenNames = [[NSArray alloc] initWithObjects:@"\<invalid>", @"\<EOR>", @"\<DOWN>", @"\<UP>", <tokenNames:{@<it>}; separator=", ", wrap="\n	">, nil];<if(memoize)>		ruleMemo = [[NSMutableDictionary alloc] initWithCapacity:<numRules>+1];<endif>		<cyclicDFAs:{dfa | dfa<dfa.decisionNumber> = [[<name>DFA<dfa.decisionNumber> alloc] initWithRecognizer:self];}; separator="\n">		<scopes:{<if(it.isDynamicGlobalScope)><globalAttributeScopeInit(scope=it)><endif>}>		<rules:{rule |		<rule.ruleDescriptor.ruleScope:ruleAttributeScopeInit(scope=it)>		}>		<actions.parser.init>		<@init()>	}	return self;}- (void) dealloc{	[tokenNames release];<if(memoize)>	[ruleMemo release];<endif>	<cyclicDFAs:{dfa | [dfa<dfa.decisionNumber> release];}; separator="\n">	<scopes:{<if(it.isDynamicGlobalScope)><globalAttributeScopeDealloc(scope=it)><endif>}>	<actions.parser.dealloc>	<@dealloc()>	[super dealloc];}- (NSString *) grammarFileName{	return @"<fileName>";}<actions.parser.methods><rules; separator="\n\n"><synpreds:{p | <synpred(p)>}><@methods()>@end>>parser(grammar, name, scopes, tokens, tokenNames, rules, numRules, bitsets, ASTLabelType, superClass="ANTLRParser", labelType="ANTLRToken *", members={<actions.parser.members>}) ::= <<<genericParser(inputStreamType="id\<ANTLRTokenStream>", ...)>>>treeParser(grammar, name, scopes, tokens, tokenNames, globalAction, rules, numRules, bitsets, labelType={<ANTLRASTLabelType>}, ASTLabelType="id", superClass="ANTLRTreeParser", members={<actions.treeparser.members>}) ::= <<<genericParser(inputStreamType="id\<ANTLRTreeNodeStream>", ...)>>>/** A simpler version of a rule template that is specific to the imaginary *  rules created for syntactic predicates.  As they never have return values *  nor parameters etc..., just give simplest possible method.  Don't do *  any of the normal memoization stuff in here either; it's a waste. *  As predicates cannot be inlined into the invoking rule, they need to *  be in a rule by themselves. */synpredRule(ruleName, ruleDescriptor, block, description, nakedBlock) ::=<<- (void) <ruleName>{    <if(trace)>NSLog(@"enter <ruleName> %d failed=%@ backtracking=%d", [input LA:1], failed ? @"YES" : @"NO", backtracking);    @try {        <block>    }    @finally {        NSLog(@"exit <ruleName> %d failed=%@ backtracking=%d", [input LA:1], failed ? @"YES" : @"NO", backtracking);    }<else>    <block><endif>}>>/** How to test for failure and return from rule */checkRuleBacktrackFailure() ::= <<<if(backtracking)>if (failed) return <ruleReturnValue()>;<endif>>>/** This rule has failed, exit indicating failure during backtrack */ruleBacktrackFailure() ::= <<<if(backtracking)>if (backtracking > 0) {failed=YES; return <ruleReturnValue()>;}<endif>>>synpred(name) ::= <<<!name>SyntacticPredicate = @selector(<name>); !>>>lexerSynpred(name) ::= <<<synpred(name)>>>ruleMemoization(name) ::= <<<if(memoize)>if ( backtracking>0 && [self alreadyParsedRule:input ruleIndex:<ruleDescriptor.index>] ) { return <ruleReturnValue()>; }<endif>>>/** How to generate code for a rule. *  The return type aggregates are declared in the header file (headerFile template) */rule(ruleName,ruleDescriptor,block,emptyRule,description,exceptions, memoize) ::= <<// $ANTLR start <ruleName>// <fileName>:<description>- (<returnType()>) <ruleName><ruleDescriptor.parameterScope:parameterScope(scope=it)>{    <if(trace)>NSLog(@"enter <ruleName> %@ failed=%@ backtracking=%d", [input LT:1], failed ? @"YES" : @"NO", backtracking);<endif>    <ruleScopeSetUp()>    <ruleDeclarations()>    <ruleLabelDefs()>    <ruleDescriptor.actions.init>    <@preamble()>    <ruleMemoization(name=ruleName)>    @try {        <block>    }<if(exceptions)>    <exceptions:{e|<catch(decl=e.decl,action=e.action)><\n>}><else><if(!emptyRule)><if(actions.(actionScope).rulecatch)>	<actions.(actionScope).rulecatch><else>	@catch (ANTLRRecognitionException *re) {		[self reportError:re];		[self recover:input exception:re];	}<\n><endif><endif><endif>	@finally {		<if(trace)>NSLog(@"exit <ruleName> %@ failed=%@ backtracking=%d", [input LT:1], failed ? @"YES" : @"NO", backtracking);<endif>		<ruleCleanUp()>		<(ruleDescriptor.actions.finally):execAction()>		<ruleScopeCleanUp()>	}	<@postamble()>	return <ruleReturnValue()>;}// $ANTLR end <ruleName>>>catch(decl,action) ::= <<catch (<e.decl>) {    <e.action>}>>ruleDeclarations() ::= <<<if(ruleDescriptor.hasMultipleReturnValues)><returnType()> _retval = [[<returnTypeName()> alloc] init]; <! retvals are released in the calling rule! !>[_retval setStart:[input LT:1]];<\n><else><if(ruleDescriptor.hasSingleReturnValue)><returnType()> _<ruleDescriptor.singleValueReturnName>;<endif>

⌨️ 快捷键说明

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