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

📄 ast.stg

📁 antlr最新版本V3源代码
💻 STG
📖 第 1 页 / 共 2 页
字号:
/* [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.*/group AST;@outputFile.imports() ::= <<<@super.imports()><if(!TREE_PARSER)><! tree parser would already have imported !>#import \<ANTLR/ANTLR.h><\n><endif>>>@parserHeaderFile.ivars() ::= <<<@super.ivars()><parserIVars()>>>@parserHeaderFile.methodsdecl() ::= <<<@super.methodsdecl()><parserMethodsDecl()>>>@genericParser.methods() ::= <<<@super.methods()><parserMethods()>>>/** additional init code for tree support */@genericParser.init() ::= <<<@super.init()>[self setTreeAdaptor:[[[ANTLRCommonTreeAdaptor alloc] init] autorelease]];>>@genericParser.dealloc() ::= <<[self setTreeAdaptor:nil];<@super.dealloc()>>>/** Add an adaptor property that knows how to build trees */parserIVars() ::= <<id\<ANTLRTreeAdaptor> treeAdaptor;>>/** Declaration of additional tree support methods - go in interface of parserHeaderFile() */parserMethodsDecl() ::= <<- (id\<ANTLRTreeAdaptor>) treeAdaptor;- (void) setTreeAdaptor:(id\<ANTLRTreeAdaptor>)theTreeAdaptor;>>/** Definition of addition tree support methods - go in implementation of genericParser() */parserMethods() ::= <<- (id\<ANTLRTreeAdaptor>) treeAdaptor{	return treeAdaptor;}- (void) setTreeAdaptor:(id\<ANTLRTreeAdaptor>)aTreeAdaptor{	if (aTreeAdaptor != treeAdaptor) {		[aTreeAdaptor retain];		[treeAdaptor release];		treeAdaptor = aTreeAdaptor;	}}>>/** addition ivars for returnscopes */@returnScopeInterface.ivars() ::= <<<recognizer.ASTLabelType; null="id"> tree;>>/** the interface of returnScope methods */@returnScopeInterface.methods() ::= <<- (<recognizer.ASTLabelType; null="id">) tree;- (void) setTree:(<recognizer.ASTLabelType; null="id">)aTree;>>/** the implementation of returnScope methods */@returnScope.methods() ::= <<- (<ASTLabelType>) tree{	return tree;}- (void) setTree:(<ASTLabelType>)aTree{	if (tree != aTree) {		[aTree retain];		[tree release];		tree = aTree;	}}>>/** Add a variable to track rule's return AST */ruleDeclarations() ::= <<<super.ruleDeclarations()><ASTLabelType> root_0 = nil;<\n>>>ruleLabelDefs() ::= <<<super.ruleLabelDefs()><ruleDescriptor.tokenLabels:{<ASTLabelType> _<it.label.text>_tree = nil;}; separator="\n"><ruleDescriptor.tokenListLabels:{<ASTLabelType> _<it.label.text>_tree = nil;}; separator="\n">>>ruleCleanUp() ::= <<<super.ruleCleanUp()><if(ruleDescriptor.hasMultipleReturnValues)><if(backtracking)>if ( backtracking == 0 ) {<\n><endif>    [_<prevRuleRootRef()> setTree:(<ASTLabelType>)[treeAdaptor postProcessTree:root_0]];    [treeAdaptor setBoundariesForTree:[_<prevRuleRootRef()> tree] fromToken:[_<prevRuleRootRef()> start] toToken:[_<prevRuleRootRef()> stop]];<if(backtracking)>}<endif><endif>>>/** When doing auto AST construction, we must define some variables; *  These should be turned off if doing rewrites.  This must be a "mode" *  as a rule could have both rewrite and AST within the same alternative *  block. */@alt.declarations() ::= <<<if(autoAST)><if(outerAlt)>root_0 = (<ASTLabelType>)[treeAdaptor emptyTree];<\n><endif><endif>>>// TOKEN AST STUFF/** ID and output=AST */tokenRef(token,label,elementIndex) ::= <<<super.tokenRef(...)><if(backtracking)>if ( backtracking == 0 ) {<endif>_<label>_tree = (<ASTLabelType>)[treeAdaptor newTreeWithToken:_<label>];[treeAdaptor addChild:_<label>_tree toTree:root0];<if(backtracking)>}<endif>>>/** ID! and output=AST (same as plain tokenRef) */tokenRefBang(token,label,elementIndex) ::= "<super.tokenRef(...)>"/** ID^ and output=AST */tokenRefRuleRoot(token,label,elementIndex) ::= <<<super.tokenRef(...)><if(backtracking)>if ( backtracking == 0 ) {<endif>_<label>_tree = (<ASTLabelType>)[treeAdaptor newTreeWithToken:_<label>];root_0 = (<ASTLabelType>)[treeAdaptor makeNode:_<label>_tree parentOf:root_0];<if(backtracking)>}<endif>>>/** ids+=ID! and output=AST */tokenRefBangAndListLabel(token,label,elementIndex) ::= <<<tokenRefBang(...)><listLabel(...)>>>/** label+=TOKEN when output=AST but not rewrite alt */tokenRefAndListLabel(token,label,elementIndex) ::= <<<tokenRef(...)><listLabel(...)>>>/** Match label+=TOKEN^ when output=AST but not rewrite alt */tokenRefRuleRootAndListLabel(token,label,elementIndex) ::= <<<tokenRefRuleRoot(...)><listLabel(...)>>>/** ID but track it for use in a rewrite rule */tokenRefTrack(token,label,elementIndex) ::= <<<super.tokenRef(...)><if(backtracking)>if ( backtracking == 0 ) <endif>[_list_<token> addObject:_<label>];<\n>>>/** ids+=ID and track it for use in a rewrite rule; adds to ids *and* *  to the tracking list list_ID for use in the rewrite. */tokenRefTrackAndListLabel(token,label,elementIndex) ::= <<<tokenRefTrack(...)><listLabel(...)>>>// SET AST// the match set stuff is interesting in that it uses an argument list// to pass code to the default matchSet; another possible way to alter// inherited code.  I don't use the region stuff because I need to pass// different chunks depending on the operator.  I don't like making// the template name have the operator as the number of templates gets// large but this is the most flexible--this is as opposed to having// the code generator call matchSet then add root code or ruleroot code// plus list label plus ...  The combinations might require complicated// rather than just added on code.  Investigate that refactoring when// I have more time.matchSet(s,label,elementIndex,postmatchCode) ::= <<<super.matchSet(..., postmatchCode={<if(backtracking)>if (backtracking == 0) <endif>[treeAdaptor addChild:[treeAdaptor newTreeWithToken:_<label>] toTree:root_0];})>>>matchSetRoot(s,label,elementIndex,debug) ::= <<<super.matchSet(..., postmatchCode={<if(backtracking)>if (backtracking == 0) <endif>root_0 = (<ASTLabelType>)[treeAdaptor makeNode:[treeAdaptor newTreeWithToken:_<label> parentOf:root_0];})>>>matchSetRuleRoot(s,label,elementIndex,debug) ::= <<<super.matchSet(..., postmatchCode={<if(backtracking)>if (backtracking == 0) <endif>root_0 = (<ASTLabelType>)[treeAdaptor makeNode:[treeAdaptor newTreeWithToken:_<label>] parentOf:root_0];})>>>// RULE REF AST/** rule when output=AST */ruleRef(rule,label,elementIndex,args) ::= <<<super.ruleRef(...)><if(backtracking)>if (backtracking == 0) <endif>[treeAdaptor addChild:[_<label> tree] toTree:root_0];>>/** rule! is same as normal rule ref */ruleRefBang(rule,label,elementIndex,args) ::= "<super.ruleRef(...)>"/** rule^ */ruleRefRuleRoot(rule,label,elementIndex,args) ::= <<<super.ruleRef(...)><if(backtracking)>if (backtracking == 0) <endif>root_0 = (<ASTLabelType>)[treeAdaptor makeNode:[_<label> tree] parentOf:root_0];>>/** rule when output=AST and tracking for rewrite */ruleRefTrack(rule,label,elementIndex,args) ::= <<<super.ruleRef(...)><if(backtracking)>if (backtracking == 0) <endif>[_list_<rule> addObject:[_<label> tree]];>>/** x+=rule when output=AST and tracking for rewrite */ruleRefTrackAndListLabel(rule,label,elementIndex,args) ::= <<<ruleRefTrack(...)><listLabel(...)>>>/** x+=rule when output=AST */ruleRefAndListLabel(rule,label,elementIndex,args) ::= <<<ruleRef(...)><listLabel(...)>>>/** x+=rule! when output=AST is a rule ref with list addition */ruleRefBangAndListLabel(rule,label,elementIndex,args) ::= <<<ruleRefBang(...)><listLabel(...)>>>

⌨️ 快捷键说明

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