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

📄 c.stg

📁 ANTLR(ANother Tool for Language Recognition)它是这样的一种工具
💻 STG
📖 第 1 页 / 共 5 页
字号:
/* [The "BSD licence"] Copyright (c) 2005-2006 Terence Parr 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.*//* * This code generating template was produced by Jim "Any relation to Eric?" Idle.  * If it does cause the destruction of the UniVerse, it will be pretty cool so long as  * I am in a different one at the time.  */group C implements ANTLRCore ;cTypeInitMap ::= [	"int"		    : "0",              // Integers     start out being 0	"long"		    : "0",              // Longs        start out being 0	"float"		    : "0.0",            // Floats       start out being 0	"double"	    : "0.0",            // Doubles      start out being 0	"ANTLR3_BOOLEAN"    : "ANTLR3_FALSE",   // Booleans     start out being Antlr C for false	"byte"		    : "0",              // Bytes        start out being 0	"short"		    : "0",              // Shorts       start out being 0	"char"		    : "0",              // Chars        start out being 0	default		    : "NULL"            // Anything other than an atomic type (above) is a NULL (probably NULL pointer).]leadIn(type) ::=<</** \file *  This <type> file was generated by $ANTLR version <ANTLRVersion> * *     -  From the grammar source file : <fileName> *     -                            On : <generatedTimestamp><if(LEXER)> *     -                 for the lexer : <name>Lexer<endif><if(PARSER)> *     -                for the parser : <name>Parser<endif><if(TREE_PARSER)> *     -           for the tree parser : <name>TreeParser<endif> * * Editing it, at least manually, is not wise.  * * C language generator and runtime by Jim "Any relation to Eric?" Idle - "jimi" at idledotws * * View this file with tabs set to 8 (:set ts=8 in gvim) and indent at 4 (:set sw=4 in gvim) *>>/** 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            ) ::=<<<leadIn("C source")>*/<if(actions.(actionScope).header)>/* ============================================================================= * This is what the grammar programmer asked us to put at the top of every file. */<actions.(actionScope).header>/* End of Header action. * ============================================================================= */<endif>/* ----------------------------------------- * Include the ANTLR3 generated header file. */#include    "<name>.h"/* ----------------------------------------- */<docComment><if(literals)>/** String literals used by <name> that we must do things like matchs() with. *  C will normally just lay down 8 bit characters, and you can use L"xxx" to *  get wchar_t, but wchar_t is 16 bits on Windows, which is not UTF32 and so *  we perform this little trick of defining the literals as arrays of UINT32 *  and passing in the address of these. */<literals:{static ANTLR3_UCHAR	lit_<i>[]  = <it>;}; separator="\n"><endif>/* ============================================================================= * Functions to create and destroy scopes. First come the rule scopes, followed * by the global declared scopes. */<rules: {r |<if(r.ruleDescriptor.ruleScope)><ruleAttributeScopeFuncDecl(scope=r.ruleDescriptor.ruleScope)><ruleAttributeScopeFuncs(scope=r.ruleDescriptor.ruleScope)><endif>}><recognizer.scopes:{<if(it.isDynamicGlobalScope)><ruleAttributeScopeDef(scope=it)><globalAttributeScopeFuncDecl(scope=it)><globalAttributeScopeFuncs(scope=it)><endif>}>/* ============================================================================= *//* ============================================================================= * Start of recognizer */<recognizer>/* End of code * ============================================================================= */>>headerFile( LEXER,            PARSER,            TREE_PARSER,            actionScope,             actions,            docComment,             recognizer,            name,             tokens,             tokenNames,             rules,            cyclicDFAs,            bitsets,            buildTemplate,            profile,            backtracking,             synpreds,             memoize,             numRules,            fileName,            ANTLRVersion,            generatedTimestamp,            scopes,	    superClass,            trace,            literals        ) ::=<<<leadIn("C header")><if(PARSER)> * The parser <mainName()><endif><if(LEXER)> * The lexer <mainName()><endif><if(TREE_PARSER)> * The tree parser <mainName()><endif>has the callable functions (rules) shown below, * which will invoke the code for the associated rule in the source grammar * assuming that the input stream is pointing to a token/text stream that could begin * this rule. *  * For instance if you call the first (topmost) rule in a parser grammar, you will * get the results of a full parse, but calling a rule half way through the grammar will * allow you to pass part of a full token stream to the parser, such as for syntax checking * in editors and so on. * * The parser entry points are called indirectly (by function pointer to function) via * a parser context typedef p<name>, which is returned from a call to <name>New(). *<if(LEXER)> * As this is a generated lexer, it is unlikely you will call it 'manually'. However * the entry points are provided anyway. *<endif> * The entry points for <name> are  as follows: * * <rules: {r |  - <headerReturnType(ruleDescriptor=r.ruleDescriptor,...)>      p<name>-><r.ruleDescriptor.name>(p<name>)}; separator="\n * "> * * The return type for any particular rule is of course determined by the source * grammar file. */#ifndef	_<name>_H#define _<name>_H<actions.(actionScope).preincludes>/* ============================================================================= * Standard antlr3 C runtime definitions */#include    \<antlr3.h>/* End of standard antlr 3 runtime definitions * ============================================================================= */<actions.(actionScope).includes><actions.(actionScope).header>#ifdef	WIN32// Disable: Unreferenced parameter,                - Rules with parameters that are not used//          constant conditional,                  - ANTLR realizes that a prediction is always true (synpred usually)//          initialized but unused variable        - tree rewrite vairables declared but not needed//          potentially unitialized variable used  - retval always returned from a rule //// These are only really displayed at waring level /W4 but that is the code ideal I am aiming at// and the codegen must generate some of these warnings by necessity, apart from 4100, which is// usually generated when a parser rule is given a parameter that it does not use. Mostly though// this is a matter of orthogonality hence I disable that one.//#pragma warning( disable : 4100 )#pragma warning( disable : 4127 )#pragma warning( disable : 4189 )#pragma warning( disable : 4701 )#endif<if(backtracking)>/* ======================== * BACKTRACKING IS ENABLED * ======================== */<endif><rules:{r |<headerReturnScope(ruleDescriptor=r.ruleDescriptor,...)>}><scopes:{<if(it.isDynamicGlobalScope)><globalAttributeScopeDecl(scope=it)><endif>}><rules:{r |<ruleAttributeScopeDecl(scope=r.ruleDescriptor.ruleScope)>}><rules:{r |<ruleAttributeScopeFuncMacro(scope=r.ruleDescriptor.ruleScope)>}>/** Context tracking structure for <mainName()> */typedef struct <name>_Ctx_struct{    /** Built in ANTLR3 context tracker contains all the generic elements     *  required for context tracking.     */<if(PARSER)>    pANTLR3_PARSER   pParser;<endif><if(LEXER)>    pANTLR3_LEXER    pLexer;<endif><if(TREE_PARSER)>    pANTLR3_TREE_PARSER	    pTreeParser;<endif><scopes:{<if(it.isDynamicGlobalScope)>    <globalAttributeScopeDef(scope=it)><endif>}; separator="\n\n"><rules: {r |<if(r.ruleDescriptor.ruleScope)>    <ruleAttributeScopeDef(scope=r.ruleDescriptor.ruleScope)><endif>}><if(LEXER)>    <rules:{r | <headerReturnType(ruleDescriptor=r.ruleDescriptor)> (*m<r.ruleDescriptor.name>)	(struct <name>_Ctx_struct * ctx<if(r.ruleDescriptor.parameterScope)>, <endif><r.ruleDescriptor.parameterScope:parameterScope(scope=it)>);}; separator="\n";><endif><if(PARSER)>    <rules:{r | <headerReturnType(ruleDescriptor=r.ruleDescriptor)> (*<r.ruleDescriptor.name>)	(struct <name>_Ctx_struct * ctx<if(r.ruleDescriptor.parameterScope)>, <endif><r.ruleDescriptor.parameterScope:parameterScope(scope=it)>);}; separator="\n";><endif><if(TREE_PARSER)>    <rules:{r | <headerReturnType(ruleDescriptor=r.ruleDescriptor)> (*<r.ruleDescriptor.name>)	(struct <name>_Ctx_struct * ctx<if(r.ruleDescriptor.parameterScope)>, <endif><r.ruleDescriptor.parameterScope:parameterScope(scope=it)>);}; separator="\n";><endif>    unsigned char * (*getGrammarFileName)();    void	    (*free)   (struct <name>_Ctx_struct * ctx);    <@members>    <@end>}    <name>, * p<name>;<if(LEXER)>/* Function protoypes for the lexer functions that external translation units * may wish to call. */ANTLR3_API p<name> <name>New         (pANTLR3_INPUT_STREAM     instream);<endif><if(PARSER)>/* Function protoypes for the parser functions that external translation units * may wish to call. */ANTLR3_API p<name> <name>New         (pANTLR3_COMMON_TOKEN_STREAM     instream);<endif><if(TREE_PARSER)>/* Function protoypes for the treeparser functions that external translation units * may wish to call. */ANTLR3_API p<name> <name>New         (pANTLR3_COMMON_TREE_NODE_STREAM     instream);<endif>/** Symbolic definitions of all the tokens that the <grammarType()> will work with. * \{ * * Antlr will define EOF, but we can't use that as it it is too common in * in C header files and that would be confusing. There is no way to filter this out at the moment * so we just undef it here for now. That isn't the value we get back from C recognizers * anyway. We are looking for ANTLR3_TOKEN_EOF. */#ifdef	EOF#undef	EOF#endif#ifdef	Tokens#undef	Tokens#endif <tokens:{#define <it.name>      <it.type>}; separator="\n">/* End of token definitions for <name> * ============================================================================= *//** \} *//* Work arounds because ruleScopeRef() does not have access to <name> */#undef	SCOPE_TYPE#undef	SCOPE_STACK#undef	SCOPE_TOP#define	SCOPE_TYPE(scope)   p<name>_##scope##_SCOPE#define SCOPE_STACK(scope)  p<name>_##scope##Stack#define	SCOPE_TOP(scope)    ctx->p<name>_##scope##Top/* MACROS that hide the C interface implementations from the * generated code, which makes it a little more understandable to the human eye. * I am very much against using C pre-processor macros for function calls and bits * of code as you cannot see what is happening when single stepping in debuggers * and so on. The exception (in my book at least) is for generated code, where you are * not maintaining it, but may wish to read and understand it. If you single step it, you know that input() * hides some indirect calls, but is always refering to the input stream. This is * probably more readable than ctx->input->istream->input(snarfle0->blarg) and allows me to rejig * the runtime interfaces without changing the generated code too often, without * confusing the reader of the generated output, who may not wish to know the gory * details of the interface inheritence and without nailing anybody to a cross for  * suggesting we just be nice to each other. */<if(LEXER)> /* Macros for access things in a lexer */#undef	    lexr#undef	    rec		    #undef	    ruleMemo		    #undef	    getCharIndex#undef	    getLine#undef	    getCharPositionInLine#undef	    emit#undef	    emitNew#undef	    matchc#undef	    matchs#undef	    matchRange#undef	    ltoken#undef	    hasFailed#undef	    failedFlag#undef	    theInput#undef	    strStream#undef	    LA#undef	    hasException#undef	    theException#undef	    exConstruct#undef	    inputConsume#undef	    lrecover#undef	    markMyWords#undef	    rewindInput#undef	    rewindLast#undef	    backtracking#define	    lexr		    ctx->pLexer#define	    rec			    lexr->rec#define	    ruleMemo		    rec->ruleMemo#define	    getCharIndex()	    lexr->getCharIndex(lexr)#define	    getLine()		    lexr->getLine(lexr)#define	    getCharPositionInLine() lexr->getCharPositionInLine(lexr)#define	    emit(t)		    lexr->emit(lexr, t)#define	    emitNew(t,l,cp,ch,s,i)  lexr->emitNew(lexr, t, l, cp, ch, s, i)#define	    matchc(c)		    lexr->matchc(lexr, c)#define	    matchs(s)		    lexr->matchs(lexr, s)#define	    matchRange(c1,c2)	    lexr->matchRange(lexr, c1, c2)#define	    matchAny()		    rec->matchAny(rec)#define	    ltoken()		    lexr->token#define	    hasFailed()		    (rec->failed == ANTLR3_TRUE)#define	    backtracking	    rec->backtracking#define	    failedFlag		    rec->failed#define	    theInput()		    lexr->input#define	    strStream		    theInput()#define	    LA(n)		    theInput()->istream->LA(lexr->input->istream, n)#define	    EOF_TOKEN		    theInput()->istream->eofToken#define	    hasException()	    (rec->error == ANTLR3_TRUE)#define	    theException()	    rec->exception#define	    exConstruct()	    rec->exConstruct(rec)#define	    inputConsume()	    theInput()->istream->consume(theInput()->istream)#define	    lrecover()		    lexr->recover(lexr)#define	    markMyWords()	    theInput()->istream->mark(theInput()->istream)#define	    rewindInput(m)	    theInput()->istream->rewind(theInput()->istream, m)#define	    rewindLast()	    theInput()->istream->rewindLast(theInput()->istream)<endif><if(PARSER)>/* Macros for accessing things in the parser */ #undef	    prsr		    #undef	    rec		    #undef	    haveAlreadyParsedRule#undef	    theInput#undef	    strStream#undef	    hasException#undef	    theException#undef	    tmatch#undef	    tmatchAny#undef	    followStk

⌨️ 快捷键说明

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