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

📄 c.stg

📁 antlr最新版本V3源代码
💻 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 and the assocated C runtime was produced by: * Jim Idle jimi|hereisanat|idle|dotgoeshere|ws.  * 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 Idle, jimi|hereisanat|idle|dotgoeshere|ws. * * 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,            buildAST,            rewrite,            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>/* Aids in accessing scopes for grammar programmers */#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#define	SCOPE_SIZE(scope)			(ctx->SCOPE_STACK(scope)->size(ctx->SCOPE_STACK(scope)))#define SCOPE_INSTANCE(scope, i)	(ctx->SCOPE_STACK(scope)->get(ctx->SCOPE_STACK(scope),i))/* 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. */<if(LEXER)> /* Macros for accessing things in a lexer */#undef	    LEXER#undef	    RECOGNIZER		    #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	    INPUT#undef	    STRSTREAM#undef	    LA#undef	    HASEXCEPTION#undef	    EXCEPTION#undef	    CONSTRUCTEX#undef	    CONSUME#undef	    LRECOVER#undef	    MARK#undef	    REWIND#undef	    REWINDLAST#undef	    BACKTRACKING#undef		MATCHANY#undef		MEMOIZE#undef		HAVEPARSEDRULE#undef		GETTEXT#undef		INDEX#undef		SEEK#define	    LEXER					ctx->pLexer#define	    RECOGNIZER			    LEXER->rec#define	    RULEMEMO				RECOGNIZER->ruleMemo#define	    GETCHARINDEX()			LEXER->getCharIndex(LEXER)#define	    GETLINE()				LEXER->getLine(LEXER)#define	    GETTEXT()				LEXER->getText(LEXER)#define	    GETCHARPOSITIONINLINE() LEXER->getCharPositionInLine(LEXER)#define	    EMIT()					LEXER->type = _type; LEXER->emit(LEXER)#define	    EMITNEW(t)				LEXER->emitNew(LEXER, t)#define	    MATCHC(c)				LEXER->matchc(LEXER, c)#define	    MATCHS(s)				LEXER->matchs(LEXER, s)#define	    MATCHRANGE(c1,c2)	    LEXER->matchRange(LEXER, c1, c2)#define	    MATCHANY()				LEXER->matchAny(LEXER)#define	    LTOKEN  				LEXER->token#define	    HASFAILED()				(RECOGNIZER->failed == ANTLR3_TRUE)#define	    BACKTRACKING			RECOGNIZER->backtracking#define	    FAILEDFLAG				RECOGNIZER->failed#define	    INPUT					LEXER->input#define	    STRSTREAM				INPUT#define		INDEX()					INPUT->istream->index(INPUT->istream)#define		SEEK(n)					INPUT->istream->seek(INPUT->istream, n)#define	    EOF_TOKEN				&(LEXER->tokSource->eofToken)#define	    HASEXCEPTION()			(RECOGNIZER->error == ANTLR3_TRUE)#define	    EXCEPTION				RECOGNIZER->exception#define	    CONSTRUCTEX()			RECOGNIZER->exConstruct(RECOGNIZER)#define	    LRECOVER()				LEXER->recover(LEXER)#define	    MARK()					INPUT->istream->mark(INPUT->istream)#define	    REWIND(m)				INPUT->istream->rewind(INPUT->istream, m)#define	    REWINDLAST()			INPUT->istream->REWINDLAST(INPUT->istream)#define		MEMOIZE(ri,si)			RECOGNIZER->memoize(RECOGNIZER, ri, si)#define		HAVEPARSEDRULE(r)		RECOGNIZER->alreadyParsedRule(RECOGNIZER, r)/* If we have been told we can rely on the standard 8 bit or 16 bit input * stream, then we can define our macros to use the direct pointers * in the input object, which is much faster than indirect calls. This * is really only significant to lexers wiht a lot of fragment rules (which * do not place LA(1) in a temporary at the moment) and even then * only if there is a lot of input (order of say 1M or so). */#if	defined(ANTLR3_INLINE_INPUT_ASCII) || defined(ANTLR3_INLINE_INPUT_UTF16)# ifdef	ANTLR3_INLINE_INPUT_ASCII/* 8 bit "ASCII" (actually any 8 bit character set) */#  define	    NEXTCHAR			((pANTLR3_UINT8)(INPUT->nextChar))#  define	    DATAP				((pANTLR3_UINT8)(INPUT->data))# else#  define	    NEXTCHAR			((pANTLR3_UINT16)(INPUT->nextChar)) #  define	    DATAP				((pANTLR3_UINT16)(INPUT->data))# endif# define	    LA(n) ((NEXTCHAR + n) > (DATAP + INPUT->sizeBuf) ? ANTLR3_CHARSTREAM_EOF : (ANTLR3_UCHAR)(*(NEXTCHAR + n - 1)))# define	    CONSUME()											\{																	\    if	(NEXTCHAR \< (DATAP + INPUT->sizeBuf))					\    {																\		INPUT->charPositionInLine++;								\		if  ((ANTLR3_UCHAR)(*NEXTCHAR) == INPUT->newlineChar)		\		{															\			INPUT->line++;										\			INPUT->charPositionInLine	= 0;						\			INPUT->currentLine		= (void *)(NEXTCHAR + 1);	\		}															\		INPUT->nextChar = (void *)(NEXTCHAR + 1);					\    }																\}#else// Pick up the input character by calling the input stream implementation.//#define	    CONSUME()				INPUT->istream->consume(INPUT->istream)#define	    LA(n)					INPUT->istream->_LA(INPUT->istream, n)#endif<endif><if(PARSER)>/* Macros for accessing things in the parser */ #undef	    PARSER		    #undef	    RECOGNIZER		    #undef	    HAVEPARSEDRULE#undef		MEMOIZE#undef	    INPUT#undef	    STRSTREAM#undef	    HASEXCEPTION#undef	    EXCEPTION#undef	    MATCHT#undef	    MATCHANYT#undef	    FOLLOWSTACK#undef	    FOLLOWPUSH#undef	    FOLLOWPOP#undef	    PRECOVER#undef	    PREPORTERROR#undef	    LA#undef	    LT#undef	    CONSTRUCTEX#undef	    CONSUME#undef	    MARK#undef	    REWIND#undef	    REWINDLAST#undef	    PERRORRECOVERY#undef	    HASFAILED#undef	    FAILEDFLAG#undef	    RECOVERFROMMISMATCHEDSET#undef	    RECOVERFROMMISMATCHEDELEMENT#undef		INDEX#undef      ADAPTOR#define	    PARSER							ctx->pParser  #define	    RECOGNIZER						PARSER->rec#define	    HAVEPARSEDRULE(r)				RECOGNIZER->alreadyParsedRule(RECOGNIZER, r)#define		MEMOIZE(ri,si)					RECOGNIZER->memoize(RECOGNIZER, ri, si)#define	    INPUT							PARSER->tstream#define	    STRSTREAM						INPUT#define		INDEX()							INPUT->istream->index(INPUT->istream)#define	    HASEXCEPTION()					(RECOGNIZER->error == ANTLR3_TRUE)#define	    EXCEPTION						RECOGNIZER->exception#define	    MATCHT(t, fs)					RECOGNIZER->match(RECOGNIZER, t, fs)#define	    MATCHANYT()						RECOGNIZER->matchAny(RECOGNIZER)#define	    FOLLOWSTACK					    RECOGNIZER->following#define	    FOLLOWPUSH(x)					FOLLOWSTACK->push(FOLLOWSTACK, ((void *)(&(x))), NULL)#define	    FOLLOWPOP()						FOLLOWSTACK->pop(FOLLOWSTACK)#define	    PRECOVER()						RECOGNIZER->recover(RECOGNIZER)#define	    PREPORTERROR()					RECOGNIZER->reportError(RECOGNIZER)#define	    LA(n)							INPUT->istream->_LA(INPUT->istream, n)#define	    LT(n)							INPUT->_LT(INPUT, n)#define	    CONSTRUCTEX()					RECOGNIZER->exConstruct(RECOGNIZER)#define	    CONSUME()						INPUT->istream->consume(INPUT->istream)#define	    MARK()							INPUT->istream->mark(INPUT->istream)#define	    REWIND(m)						INPUT->istream->rewind(INPUT->istream, m)#define	    REWINDLAST()					INPUT->istream->REWINDLAST(INPUT->istream)#define	    PERRORRECOVERY					RECOGNIZER->errorRecovery#define	    _fsp							RECOGNIZER->_fsp#define	    FAILEDFLAG						RECOGNIZER->failed#define	    HASFAILED()						(FAILEDFLAG == ANTLR3_TRUE)#define	    BACKTRACKING					RECOGNIZER->backtracking#define	    RECOVERFROMMISMATCHEDSET(s)		RECOGNIZER->recoverFromMismatchedSet(RECOGNIZER, s)#define	    RECOVERFROMMISMATCHEDELEMENT(e)	RECOGNIZER->recoverFromMismatchedElement(RECOGNIZER, s)#define     ADAPTOR                         ctx->adaptor<endif><if(TREE_PARSER)>/* Macros for accessing things in the parser */ #undef	    PARSER#undef	    RECOGNIZER		    #undef	    HAVEPARSEDRULE#undef	    INPUT#undef	    STRSTREAM#undef	    HASEXCEPTION#undef	    EXCEPTION#undef	    MATCHT#undef	    MATCHANYT#undef	    FOLLOWSTACK#undef	    FOLLOWPUSH#undef	    FOLLOWPOP#undef	    PRECOVER#undef	    PREPORTERROR#undef	    LA#undef	    LT#undef	    CONSTRUCTEX#undef	    CONSUME#undef	    MARK#undef	    REWIND#undef	    REWINDLAST#undef	    PERRORRECOVERY#undef	    HASFAILED#undef	    FAILEDFLAG#undef	    RECOVERFROMMISMATCHEDSET#undef	    RECOVERFROMMISMATCHEDELEMENT#undef	    BACKTRACKING#undef      ADAPTOR#define	    PARSER							ctx->pTreeParser  #define	    RECOGNIZER						PARSER->rec#define	    HAVEPARSEDRULE(r)				RECOGNIZER->alreadyParsedRule(RECOGNIZER, r)#define	    INPUT							PARSER->ctnstream#define	    STRSTREAM						INPUT->tnstream#define	    HASEXCEPTION()					(RECOGNIZER->error == ANTLR3_TRUE)#define	    EXCEPTION						RECOGNIZER->exception#define	    MATCHT(t, fs)					RECOGNIZER->match(RECOGNIZER, t, fs)#define	    MATCHANYT()						RECOGNIZER->matchAny(RECOGNIZER)#define	    FOLLOWSTACK					    RECOGNIZER->following#define	    FOLLOWPUSH(x)					FOLLOWSTACK->push(FOLLOWSTACK, ((void *)(&(x))), NULL)#define	    FOLLOWPOP()						FOLLOWSTACK->pop(FOLLOWSTACK)#define	    PRECOVER()						RECOGNIZER->recover(RECOGNIZER)#define	    PREPORTERROR()					RECOGNIZER->reportError(RECOGNIZER)#define	    LA(n)							INPUT->tnstream->istream->_LA(INPUT->tnstream->istream, n)#define	    LT(n)							INPUT->tnstream->_LT(INPUT->tnstream, n)#define	    CONSTRUCTEX()					RECOGNIZER->exConstruct(RECOGNIZER)#define	    CONSUME()						INPUT->tnstream->istream->consume(INPUT->tnstream->istream)#define	    MARK()							INPUT->tnstream->istream->mark(INPUT->tnstream->istream)#define	    REWIND(m)						INPUT->tnstream->istream->rewind(INPUT->tnstream->istream, m)#define	    REWINDLAST(m)					INPUT->tnstream->istream->REWINDLAST(INPUT->tnstream->istream)#define	    PERRORRECOVERY					RECOGNIZER->errorRecovery#define	    _fsp							RECOGNIZER->_fsp#define	    FAILEDFLAG						RECOGNIZER->failed#define	    HASFAILED()						(FAILEDFLAG == ANTLR3_TRUE)#define	    BACKTRACKING					RECOGNIZER->backtracking#define	    RECOVERFROMMISMATCHEDSET(s)		RECOGNIZER->recoverFromMismatchedSet(RECOGNIZER, s)#define	    RECOVERFROMMISMATCHEDELEMENT(e)	RECOGNIZER->recoverFromMismatchedElement(RECOGNIZER, s)#define     ADAPTOR                         INPUT->adaptor<endif>/* The 4 tokens defined below may well clash with your own #defines or token types. If so * then for the present you must use different names for your defines as these are hard coded * in the code generator. It would be better not to use such names internally, and maybe * we can change this in a forthcoming release. I deliberately do not #undef these * here as this will at least give you a redefined error somewhere if they clash. */#define	    UP	    ANTLR3_TOKEN_UP#define	    DOWN    ANTLR3_TOKEN_DOWN#define	    EOR	    ANTLR3_TOKEN_EOR#define	    INVALID ANTLR3_TOKEN_INVALID/* ============================================================================= * 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)><globalAttributeScopeFuncDecl(scope=it)><globalAttributeScopeFuncs(scope=it)><endif>}>/* ============================================================================= */

⌨️ 快捷键说明

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