-/** \file\r
- * This C source file was generated by $ANTLR version 3.2 Sep 23, 2009 12:02:23\r
- *\r
- * - From the grammar source file : LangDumpDecl.g\r
- * - On : 2010-02-24 13:30:09\r
- * - for the tree parser : LangDumpDeclTreeParser *\r
- * Editing it, at least manually, is not wise. \r
- *\r
- * C language generator and runtime by Jim Idle, jimi|hereisanat|idle|dotgoeshere|ws.\r
- *\r
- *\r
-*/\r
-// [The "BSD licence"]\r
-// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC\r
-// http://www.temporal-wave.com\r
-// http://www.linkedin.com/in/jimidle\r
-//\r
-// All rights reserved.\r
-//\r
-// Redistribution and use in source and binary forms, with or without\r
-// modification, are permitted provided that the following conditions\r
-// are met:\r
-// 1. Redistributions of source code must retain the above copyright\r
-// notice, this list of conditions and the following disclaimer.\r
-// 2. Redistributions in binary form must reproduce the above copyright\r
-// notice, this list of conditions and the following disclaimer in the\r
-// documentation and/or other materials provided with the distribution.\r
-// 3. The name of the author may not be used to endorse or promote products\r
-// derived from this software without specific prior written permission.\r
-//\r
-// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
-// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
-// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
-// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
-// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
-// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-\r
-/* -----------------------------------------\r
- * Include the ANTLR3 generated header file.\r
- */\r
-#include "LangDumpDecl.h"\r
-/* ----------------------------------------- */\r
-\r
-\r
-\r
-\r
-\r
-/* MACROS that hide the C interface implementations from the\r
- * generated code, which makes it a little more understandable to the human eye.\r
- * I am very much against using C pre-processor macros for function calls and bits\r
- * of code as you cannot see what is happening when single stepping in debuggers\r
- * and so on. The exception (in my book at least) is for generated code, where you are\r
- * not maintaining it, but may wish to read and understand it. If you single step it, you know that input()\r
- * hides some indirect calls, but is always referring to the input stream. This is\r
- * probably more readable than ctx->input->istream->input(snarfle0->blarg) and allows me to rejig\r
- * the runtime interfaces without changing the generated code too often, without\r
- * confusing the reader of the generated output, who may not wish to know the gory\r
- * details of the interface inheritance.\r
- */\r
- \r
-#define CTX ctx\r
-\r
-/* Aids in accessing scopes for grammar programmers\r
- */\r
-#undef SCOPE_TYPE\r
-#undef SCOPE_STACK\r
-#undef SCOPE_TOP\r
-#define SCOPE_TYPE(scope) pLangDumpDecl_##scope##_SCOPE\r
-#define SCOPE_STACK(scope) pLangDumpDecl_##scope##Stack\r
-#define SCOPE_TOP(scope) ctx->pLangDumpDecl_##scope##Top\r
-#define SCOPE_SIZE(scope) ctx->pLangDumpDecl_##scope##Stack_limit\r
-#define SCOPE_INSTANCE(scope, i) (ctx->SCOPE_STACK(scope)->get(ctx->SCOPE_STACK(scope),i))\r
-\r
-/* Macros for accessing things in the parser\r
- */\r
- \r
-#undef PARSER\r
-#undef RECOGNIZER \r
-#undef HAVEPARSEDRULE\r
-#undef INPUT\r
-#undef STRSTREAM\r
-#undef HASEXCEPTION\r
-#undef EXCEPTION\r
-#undef MATCHT\r
-#undef MATCHANYT\r
-#undef FOLLOWSTACK\r
-#undef FOLLOWPUSH\r
-#undef FOLLOWPOP\r
-#undef PRECOVER\r
-#undef PREPORTERROR\r
-#undef LA\r
-#undef LT\r
-#undef CONSTRUCTEX\r
-#undef CONSUME\r
-#undef MARK\r
-#undef REWIND\r
-#undef REWINDLAST\r
-#undef PERRORRECOVERY\r
-#undef HASFAILED\r
-#undef FAILEDFLAG\r
-#undef RECOVERFROMMISMATCHEDSET\r
-#undef RECOVERFROMMISMATCHEDELEMENT\r
-#undef BACKTRACKING\r
-#undef ADAPTOR\r
-#undef RULEMEMO \r
-#undef SEEK \r
-#undef INDEX\r
-#undef DBG\r
-\r
-#define PARSER ctx->pTreeParser \r
-#define RECOGNIZER PARSER->rec\r
-#define PSRSTATE RECOGNIZER->state\r
-#define HAVEPARSEDRULE(r) RECOGNIZER->alreadyParsedRule(RECOGNIZER, r)\r
-#define INPUT PARSER->ctnstream\r
-#define ISTREAM INPUT->tnstream->istream\r
-#define STRSTREAM INPUT->tnstream\r
-#define HASEXCEPTION() (PSRSTATE->error == ANTLR3_TRUE)\r
-#define EXCEPTION PSRSTATE->exception\r
-#define MATCHT(t, fs) RECOGNIZER->match(RECOGNIZER, t, fs)\r
-#define MATCHANYT() RECOGNIZER->matchAny(RECOGNIZER)\r
-#define FOLLOWSTACK PSRSTATE->following\r
-#define FOLLOWPUSH(x) FOLLOWSTACK->push(FOLLOWSTACK, ((void *)(&(x))), NULL)\r
-#define FOLLOWPOP() FOLLOWSTACK->pop(FOLLOWSTACK)\r
-#define PRECOVER() RECOGNIZER->recover(RECOGNIZER)\r
-#define PREPORTERROR() RECOGNIZER->reportError(RECOGNIZER)\r
-#define LA(n) ISTREAM->_LA(ISTREAM, n)\r
-#define LT(n) INPUT->tnstream->_LT(INPUT->tnstream, n)\r
-#define CONSTRUCTEX() RECOGNIZER->exConstruct(RECOGNIZER)\r
-#define CONSUME() ISTREAM->consume(ISTREAM)\r
-#define MARK() ISTREAM->mark(ISTREAM)\r
-#define REWIND(m) ISTREAM->rewind(ISTREAM, m)\r
-#define REWINDLAST() ISTREAM->rewindLast(ISTREAM)\r
-#define PERRORRECOVERY PSRSTATE->errorRecovery\r
-#define FAILEDFLAG PSRSTATE->failed\r
-#define HASFAILED() (FAILEDFLAG == ANTLR3_TRUE)\r
-#define BACKTRACKING PSRSTATE->backtracking\r
-#define RECOVERFROMMISMATCHEDSET(s) RECOGNIZER->recoverFromMismatchedSet(RECOGNIZER, s)\r
-#define RECOVERFROMMISMATCHEDELEMENT(e) RECOGNIZER->recoverFromMismatchedElement(RECOGNIZER, s)\r
-#define ADAPTOR INPUT->adaptor\r
-#define RULEMEMO PSRSTATE->ruleMemo\r
-#define SEEK(n) ISTREAM->seek(ISTREAM, n)\r
-#define INDEX() ISTREAM->index(ISTREAM)\r
-#define DBG RECOGNIZER->debugger\r
-\r
-\r
-#define TOKTEXT(tok, txt) tok, (pANTLR3_UINT8)txt\r
-\r
-/* The 4 tokens defined below may well clash with your own #defines or token types. If so\r
- * then for the present you must use different names for your defines as these are hard coded\r
- * in the code generator. It would be better not to use such names internally, and maybe\r
- * we can change this in a forthcoming release. I deliberately do not #undef these\r
- * here as this will at least give you a redefined error somewhere if they clash.\r
- */\r
-#define UP ANTLR3_TOKEN_UP\r
-#define DOWN ANTLR3_TOKEN_DOWN\r
-#define EOR ANTLR3_TOKEN_EOR\r
-#define INVALID ANTLR3_TOKEN_INVALID\r
-\r
-\r
-/* =============================================================================\r
- * Functions to create and destroy scopes. First come the rule scopes, followed\r
- * by the global declared scopes.\r
- */\r
-\r
-\r
-\r
-/* ============================================================================= */\r
-\r
-/* =============================================================================\r
- * Start of recognizer\r
- */\r
-\r
-\r
-\r
-/** \brief Table of all token names in symbolic order, mainly used for\r
- * error reporting.\r
- */\r
-pANTLR3_UINT8 LangDumpDeclTokenNames[7+4]\r
- = {\r
- (pANTLR3_UINT8) "<invalid>", /* String to print to indicate an invalid token */\r
- (pANTLR3_UINT8) "<EOR>",\r
- (pANTLR3_UINT8) "<DOWN>", \r
- (pANTLR3_UINT8) "<UP>", \r
- (pANTLR3_UINT8) "DECL",\r
- (pANTLR3_UINT8) "ID",\r
- (pANTLR3_UINT8) "INTTYPE",\r
- (pANTLR3_UINT8) "FLOATTYPE",\r
- (pANTLR3_UINT8) "INT",\r
- (pANTLR3_UINT8) "WS",\r
- (pANTLR3_UINT8) "';'"\r
- };\r
-\r
- \r
-\r
-// Forward declare the locally static matching functions we have generated.\r
-//\r
-static void decl (pLangDumpDecl ctx);\r
-static void decls (pLangDumpDecl ctx);\r
-static void type (pLangDumpDecl ctx);\r
-static LangDumpDecl_declarator_return declarator (pLangDumpDecl ctx);\r
-static void LangDumpDeclFree(pLangDumpDecl ctx);\r
-/* For use in tree output where we are accumulating rule labels via label += ruleRef\r
- * we need a function that knows how to free a return scope when the list is destroyed. \r
- * We cannot just use ANTLR3_FREE because in debug tracking mode, this is a macro.\r
- */\r
-static void ANTLR3_CDECL freeScope(void * scope)\r
-{\r
- ANTLR3_FREE(scope);\r
-}\r
-\r
-/** \brief Name of the grammar file that generated this code\r
- */\r
-static const char fileName[] = "LangDumpDecl.g";\r
-\r
-/** \brief Return the name of the grammar file that generated this code.\r
- */\r
-static const char * getGrammarFileName()\r
-{\r
- return fileName;\r
-}\r
-/** \brief Create a new LangDumpDecl parser and return a context for it.\r
- *\r
- * \param[in] instream Pointer to an input stream interface.\r
- *\r
- * \return Pointer to new parser context upon success.\r
- */\r
-ANTLR3_API pLangDumpDecl\r
-LangDumpDeclNew (pANTLR3_COMMON_TREE_NODE_STREAM instream)\r
-{\r
- // See if we can create a new parser with the standard constructor\r
- //\r
- return LangDumpDeclNewSSD(instream, NULL);\r
-}\r
-\r
-/** \brief Create a new LangDumpDecl parser and return a context for it.\r
- *\r
- * \param[in] instream Pointer to an input stream interface.\r
- *\r
- * \return Pointer to new parser context upon success.\r
- */\r
-ANTLR3_API pLangDumpDecl\r
-LangDumpDeclNewSSD (pANTLR3_COMMON_TREE_NODE_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state)\r
-{\r
- pLangDumpDecl ctx; /* Context structure we will build and return */\r
- \r
- ctx = (pLangDumpDecl) ANTLR3_CALLOC(1, sizeof(LangDumpDecl));\r
- \r
- if (ctx == NULL)\r
- {\r
- // Failed to allocate memory for parser context\r
- //\r
- return NULL;\r
- }\r
- \r
- /* -------------------------------------------------------------------\r
- * Memory for basic structure is allocated, now to fill in\r
- * the base ANTLR3 structures. We initialize the function pointers\r
- * for the standard ANTLR3 parser function set, but upon return\r
- * from here, the programmer may set the pointers to provide custom\r
- * implementations of each function. \r
- *\r
- * We don't use the macros defined in LangDumpDecl.h here, in order that you can get a sense\r
- * of what goes where.\r
- */\r
-\r
- /* Create a base Tree parser/recognizer, using the supplied tree node stream\r
- */\r
- ctx->pTreeParser = antlr3TreeParserNewStream(ANTLR3_SIZE_HINT, instream, state);\r
- /* Install the implementation of our LangDumpDecl interface\r
- */\r
- ctx->decl = decl;\r
- ctx->decls = decls;\r
- ctx->type = type;\r
- ctx->declarator = declarator;\r
- ctx->free = LangDumpDeclFree;\r
- ctx->getGrammarFileName = getGrammarFileName;\r
- \r
- /* Install the scope pushing methods.\r
- */\r
-\r
- \r
- \r
-\r
- \r
- /* Install the token table\r
- */\r
- PSRSTATE->tokenNames = LangDumpDeclTokenNames;\r
- \r
- \r
- /* Return the newly built parser to the caller\r
- */\r
- return ctx;\r
-}\r
-\r
-/** Free the parser resources\r
- */\r
- static void\r
- LangDumpDeclFree(pLangDumpDecl ctx)\r
- {\r
- /* Free any scope memory\r
- */\r
- \r
- \r
- // Free this parser\r
- //\r
- ctx->pTreeParser->free(ctx->pTreeParser);\r
- ANTLR3_FREE(ctx);\r
-\r
- /* Everything is released, so we can return\r
- */\r
- return;\r
- }\r
- \r
-/** Return token names used by this tree parser\r
- *\r
- * The returned pointer is used as an index into the token names table (using the token \r
- * number as the index).\r
- * \r
- * \return Pointer to first char * in the table.\r
- */\r
-static pANTLR3_UINT8 *getTokenNames() \r
-{\r
- return LangDumpDeclTokenNames; \r
-}\r
-\r
- \r
-/* Declare the bitsets\r
- */\r
-\r
-/** Bitset defining follow set for error recovery in rule state: FOLLOW_decls_in_decl58 */\r
-static ANTLR3_BITWORD FOLLOW_decls_in_decl58_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000012) };\r
-static ANTLR3_BITSET_LIST FOLLOW_decls_in_decl58 = { FOLLOW_decls_in_decl58_bits, 1 };\r
-/** Bitset defining follow set for error recovery in rule state: FOLLOW_DECL_in_decls71 */\r
-static ANTLR3_BITWORD FOLLOW_DECL_in_decls71_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000004) };\r
-static ANTLR3_BITSET_LIST FOLLOW_DECL_in_decls71 = { FOLLOW_DECL_in_decls71_bits, 1 };\r
-/** Bitset defining follow set for error recovery in rule state: FOLLOW_type_in_decls73 */\r
-static ANTLR3_BITWORD FOLLOW_type_in_decls73_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000020) };\r
-static ANTLR3_BITSET_LIST FOLLOW_type_in_decls73 = { FOLLOW_type_in_decls73_bits, 1 };\r
-/** Bitset defining follow set for error recovery in rule state: FOLLOW_declarator_in_decls77 */\r
-static ANTLR3_BITWORD FOLLOW_declarator_in_decls77_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000008) };\r
-static ANTLR3_BITSET_LIST FOLLOW_declarator_in_decls77 = { FOLLOW_declarator_in_decls77_bits, 1 };\r
-/** Bitset defining follow set for error recovery in rule state: FOLLOW_INTTYPE_in_type110 */\r
-static ANTLR3_BITWORD FOLLOW_INTTYPE_in_type110_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };\r
-static ANTLR3_BITSET_LIST FOLLOW_INTTYPE_in_type110 = { FOLLOW_INTTYPE_in_type110_bits, 1 };\r
-/** Bitset defining follow set for error recovery in rule state: FOLLOW_ID_in_declarator126 */\r
-static ANTLR3_BITWORD FOLLOW_ID_in_declarator126_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };\r
-static ANTLR3_BITSET_LIST FOLLOW_ID_in_declarator126 = { FOLLOW_ID_in_declarator126_bits, 1 };\r
- \r
-\r
- \r
- \r
-/* ==============================================\r
- * Parsing rules\r
- */\r
-/** \r
- * $ANTLR start decl\r
- * LangDumpDecl.g:10:1: decl : ( decls )+ ;\r
- */\r
-static void\r
-decl(pLangDumpDecl ctx)\r
-{ \r
- /* Initialize rule variables\r
- */\r
-\r
-\r
- {\r
- // LangDumpDecl.g:10:6: ( ( decls )+ )\r
- // LangDumpDecl.g:10:8: ( decls )+\r
- {\r
- // LangDumpDecl.g:10:8: ( decls )+\r
- {\r
- int cnt1=0;\r
-\r
- for (;;)\r
- {\r
- int alt1=2;\r
- switch ( LA(1) ) \r
- {\r
- case DECL:\r
- {\r
- alt1=1;\r
- }\r
- break;\r
-\r
- }\r
-\r
- switch (alt1) \r
- {\r
- case 1:\r
- // LangDumpDecl.g:10:8: decls\r
- {\r
- FOLLOWPUSH(FOLLOW_decls_in_decl58);\r
- decls(ctx);\r
-\r
- FOLLOWPOP();\r
- if (HASEXCEPTION())\r
- {\r
- goto ruledeclEx;\r
- }\r
-\r
-\r
- }\r
- break;\r
-\r
- default:\r
- \r
- if ( cnt1 >= 1 )\r
- {\r
- goto loop1;\r
- }\r
- /* mismatchedSetEx()\r
- */\r
- CONSTRUCTEX();\r
- EXCEPTION->type = ANTLR3_EARLY_EXIT_EXCEPTION;\r
- EXCEPTION->name = (void *)ANTLR3_EARLY_EXIT_NAME;\r
-\r
-\r
- goto ruledeclEx;\r
- }\r
- cnt1++;\r
- }\r
- loop1: ; /* Jump to here if this rule does not match */\r
- }\r
-\r
- }\r
-\r
- }\r
- \r
-\r
- // This is where rules clean up and exit\r
- //\r
- goto ruledeclEx; /* Prevent compiler warnings */\r
- ruledeclEx: ;\r
-\r
- if (HASEXCEPTION())\r
- {\r
- PREPORTERROR();\r
- PRECOVER();\r
- }\r
-\r
-\r
- return ;\r
-}\r
-/* $ANTLR end decl */\r
-\r
-/** \r
- * $ANTLR start decls\r
- * LangDumpDecl.g:13:1: decls : ^( DECL type d= declarator ) ;\r
- */\r
-static void\r
-decls(pLangDumpDecl ctx)\r
-{ \r
- LangDumpDecl_declarator_return d;\r
- #undef RETURN_TYPE_d\r
- #define RETURN_TYPE_d LangDumpDecl_declarator_return\r
-\r
- /* Initialize rule variables\r
- */\r
-\r
-\r
- {\r
- // LangDumpDecl.g:13:7: ( ^( DECL type d= declarator ) )\r
- // LangDumpDecl.g:13:9: ^( DECL type d= declarator )\r
- {\r
- MATCHT(DECL, &FOLLOW_DECL_in_decls71); \r
- if (HASEXCEPTION())\r
- {\r
- goto ruledeclsEx;\r
- }\r
-\r
-\r
- MATCHT(ANTLR3_TOKEN_DOWN, NULL); \r
- if (HASEXCEPTION())\r
- {\r
- goto ruledeclsEx;\r
- }\r
-\r
- FOLLOWPUSH(FOLLOW_type_in_decls73);\r
- type(ctx);\r
-\r
- FOLLOWPOP();\r
- if (HASEXCEPTION())\r
- {\r
- goto ruledeclsEx;\r
- }\r
-\r
- FOLLOWPUSH(FOLLOW_declarator_in_decls77);\r
- d=declarator(ctx);\r
-\r
- FOLLOWPOP();\r
- if (HASEXCEPTION())\r
- {\r
- goto ruledeclsEx;\r
- }\r
-\r
-\r
- MATCHT(ANTLR3_TOKEN_UP, NULL); \r
- if (HASEXCEPTION())\r
- {\r
- goto ruledeclsEx;\r
- }\r
-\r
- {\r
-\r
- printf("int %s\n", (STRSTREAM->toStringSS(STRSTREAM, d.start, d.start))->chars);\r
- \r
- }\r
-\r
- }\r
-\r
- }\r
- \r
-\r
- // This is where rules clean up and exit\r
- //\r
- goto ruledeclsEx; /* Prevent compiler warnings */\r
- ruledeclsEx: ;\r
-\r
- if (HASEXCEPTION())\r
- {\r
- PREPORTERROR();\r
- PRECOVER();\r
- }\r
-\r
-\r
- return ;\r
-}\r
-/* $ANTLR end decls */\r
-\r
-/** \r
- * $ANTLR start type\r
- * LangDumpDecl.g:21:1: type : INTTYPE ;\r
- */\r
-static void\r
-type(pLangDumpDecl ctx)\r
-{ \r
- /* Initialize rule variables\r
- */\r
-\r
-\r
- {\r
- // LangDumpDecl.g:21:6: ( INTTYPE )\r
- // LangDumpDecl.g:21:8: INTTYPE\r
- {\r
- MATCHT(INTTYPE, &FOLLOW_INTTYPE_in_type110); \r
- if (HASEXCEPTION())\r
- {\r
- goto ruletypeEx;\r
- }\r
-\r
-\r
- }\r
-\r
- }\r
- \r
-\r
- // This is where rules clean up and exit\r
- //\r
- goto ruletypeEx; /* Prevent compiler warnings */\r
- ruletypeEx: ;\r
-\r
- if (HASEXCEPTION())\r
- {\r
- PREPORTERROR();\r
- PRECOVER();\r
- }\r
-\r
-\r
- return ;\r
-}\r
-/* $ANTLR end type */\r
-\r
-/** \r
- * $ANTLR start declarator\r
- * LangDumpDecl.g:23:1: declarator : i= ID ;\r
- */\r
-static LangDumpDecl_declarator_return\r
-declarator(pLangDumpDecl ctx)\r
-{ \r
- LangDumpDecl_declarator_return retval;\r
-\r
- pANTLR3_BASE_TREE i;\r
-\r
- /* Initialize rule variables\r
- */\r
-\r
-\r
- i = NULL;\r
- retval.start = LT(1); retval.stop = retval.start;\r
-\r
- {\r
- // LangDumpDecl.g:24:6: (i= ID )\r
- // LangDumpDecl.g:24:8: i= ID\r
- {\r
- i = (pANTLR3_BASE_TREE) MATCHT(ID, &FOLLOW_ID_in_declarator126); \r
- if (HASEXCEPTION())\r
- {\r
- goto ruledeclaratorEx;\r
- }\r
-\r
-\r
- }\r
-\r
- }\r
- \r
-\r
- // This is where rules clean up and exit\r
- //\r
- goto ruledeclaratorEx; /* Prevent compiler warnings */\r
- ruledeclaratorEx: ;\r
-\r
- if (HASEXCEPTION())\r
- {\r
- PREPORTERROR();\r
- PRECOVER();\r
- }\r
-\r
-\r
- return retval;\r
-}\r
-/* $ANTLR end declarator */\r
-/* End of parsing rules\r
- * ==============================================\r
- */\r
-\r
-/* ==============================================\r
- * Syntactic predicates\r
- */\r
-/* End of syntactic predicates\r
- * ==============================================\r
- */\r
-\r
- \r
- \r
-\r
-\r
-\r
-/* End of code\r
- * =============================================================================\r
- */\r
+/** \file
+ * This C source file was generated by $ANTLR version 3.2 Sep 23, 2009 12:02:23
+ *
+ * - From the grammar source file : LangDumpDecl.g
+ * - On : 2010-02-24 13:30:09
+ * - for the tree parser : LangDumpDeclTreeParser *
+ * Editing it, at least manually, is not wise.
+ *
+ * C language generator and runtime by Jim Idle, jimi|hereisanat|idle|dotgoeshere|ws.
+ *
+ *
+*/
+// [The "BSD licence"]
+// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
+// http://www.temporal-wave.com
+// http://www.linkedin.com/in/jimidle
+//
+// 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.
+
+/* -----------------------------------------
+ * Include the ANTLR3 generated header file.
+ */
+#include "LangDumpDecl.h"
+/* ----------------------------------------- */
+
+
+
+
+
+/* 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 referring 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 inheritance.
+ */
+
+#define CTX ctx
+
+/* Aids in accessing scopes for grammar programmers
+ */
+#undef SCOPE_TYPE
+#undef SCOPE_STACK
+#undef SCOPE_TOP
+#define SCOPE_TYPE(scope) pLangDumpDecl_##scope##_SCOPE
+#define SCOPE_STACK(scope) pLangDumpDecl_##scope##Stack
+#define SCOPE_TOP(scope) ctx->pLangDumpDecl_##scope##Top
+#define SCOPE_SIZE(scope) ctx->pLangDumpDecl_##scope##Stack_limit
+#define SCOPE_INSTANCE(scope, i) (ctx->SCOPE_STACK(scope)->get(ctx->SCOPE_STACK(scope),i))
+
+/* 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
+#undef RULEMEMO
+#undef SEEK
+#undef INDEX
+#undef DBG
+
+#define PARSER ctx->pTreeParser
+#define RECOGNIZER PARSER->rec
+#define PSRSTATE RECOGNIZER->state
+#define HAVEPARSEDRULE(r) RECOGNIZER->alreadyParsedRule(RECOGNIZER, r)
+#define INPUT PARSER->ctnstream
+#define ISTREAM INPUT->tnstream->istream
+#define STRSTREAM INPUT->tnstream
+#define HASEXCEPTION() (PSRSTATE->error == ANTLR3_TRUE)
+#define EXCEPTION PSRSTATE->exception
+#define MATCHT(t, fs) RECOGNIZER->match(RECOGNIZER, t, fs)
+#define MATCHANYT() RECOGNIZER->matchAny(RECOGNIZER)
+#define FOLLOWSTACK PSRSTATE->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) ISTREAM->_LA(ISTREAM, n)
+#define LT(n) INPUT->tnstream->_LT(INPUT->tnstream, n)
+#define CONSTRUCTEX() RECOGNIZER->exConstruct(RECOGNIZER)
+#define CONSUME() ISTREAM->consume(ISTREAM)
+#define MARK() ISTREAM->mark(ISTREAM)
+#define REWIND(m) ISTREAM->rewind(ISTREAM, m)
+#define REWINDLAST() ISTREAM->rewindLast(ISTREAM)
+#define PERRORRECOVERY PSRSTATE->errorRecovery
+#define FAILEDFLAG PSRSTATE->failed
+#define HASFAILED() (FAILEDFLAG == ANTLR3_TRUE)
+#define BACKTRACKING PSRSTATE->backtracking
+#define RECOVERFROMMISMATCHEDSET(s) RECOGNIZER->recoverFromMismatchedSet(RECOGNIZER, s)
+#define RECOVERFROMMISMATCHEDELEMENT(e) RECOGNIZER->recoverFromMismatchedElement(RECOGNIZER, s)
+#define ADAPTOR INPUT->adaptor
+#define RULEMEMO PSRSTATE->ruleMemo
+#define SEEK(n) ISTREAM->seek(ISTREAM, n)
+#define INDEX() ISTREAM->index(ISTREAM)
+#define DBG RECOGNIZER->debugger
+
+
+#define TOKTEXT(tok, txt) tok, (pANTLR3_UINT8)txt
+
+/* 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.
+ */
+
+
+
+/* ============================================================================= */
+
+/* =============================================================================
+ * Start of recognizer
+ */
+
+
+
+/** \brief Table of all token names in symbolic order, mainly used for
+ * error reporting.
+ */
+pANTLR3_UINT8 LangDumpDeclTokenNames[7+4]
+ = {
+ (pANTLR3_UINT8) "<invalid>", /* String to print to indicate an invalid token */
+ (pANTLR3_UINT8) "<EOR>",
+ (pANTLR3_UINT8) "<DOWN>",
+ (pANTLR3_UINT8) "<UP>",
+ (pANTLR3_UINT8) "DECL",
+ (pANTLR3_UINT8) "ID",
+ (pANTLR3_UINT8) "INTTYPE",
+ (pANTLR3_UINT8) "FLOATTYPE",
+ (pANTLR3_UINT8) "INT",
+ (pANTLR3_UINT8) "WS",
+ (pANTLR3_UINT8) "';'"
+ };
+
+
+
+// Forward declare the locally static matching functions we have generated.
+//
+static void decl (pLangDumpDecl ctx);
+static void decls (pLangDumpDecl ctx);
+static void type (pLangDumpDecl ctx);
+static LangDumpDecl_declarator_return declarator (pLangDumpDecl ctx);
+static void LangDumpDeclFree(pLangDumpDecl ctx);
+/* For use in tree output where we are accumulating rule labels via label += ruleRef
+ * we need a function that knows how to free a return scope when the list is destroyed.
+ * We cannot just use ANTLR3_FREE because in debug tracking mode, this is a macro.
+ */
+static void ANTLR3_CDECL freeScope(void * scope)
+{
+ ANTLR3_FREE(scope);
+}
+
+/** \brief Name of the grammar file that generated this code
+ */
+static const char fileName[] = "LangDumpDecl.g";
+
+/** \brief Return the name of the grammar file that generated this code.
+ */
+static const char * getGrammarFileName()
+{
+ return fileName;
+}
+/** \brief Create a new LangDumpDecl parser and return a context for it.
+ *
+ * \param[in] instream Pointer to an input stream interface.
+ *
+ * \return Pointer to new parser context upon success.
+ */
+ANTLR3_API pLangDumpDecl
+LangDumpDeclNew (pANTLR3_COMMON_TREE_NODE_STREAM instream)
+{
+ // See if we can create a new parser with the standard constructor
+ //
+ return LangDumpDeclNewSSD(instream, NULL);
+}
+
+/** \brief Create a new LangDumpDecl parser and return a context for it.
+ *
+ * \param[in] instream Pointer to an input stream interface.
+ *
+ * \return Pointer to new parser context upon success.
+ */
+ANTLR3_API pLangDumpDecl
+LangDumpDeclNewSSD (pANTLR3_COMMON_TREE_NODE_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state)
+{
+ pLangDumpDecl ctx; /* Context structure we will build and return */
+
+ ctx = (pLangDumpDecl) ANTLR3_CALLOC(1, sizeof(LangDumpDecl));
+
+ if (ctx == NULL)
+ {
+ // Failed to allocate memory for parser context
+ //
+ return NULL;
+ }
+
+ /* -------------------------------------------------------------------
+ * Memory for basic structure is allocated, now to fill in
+ * the base ANTLR3 structures. We initialize the function pointers
+ * for the standard ANTLR3 parser function set, but upon return
+ * from here, the programmer may set the pointers to provide custom
+ * implementations of each function.
+ *
+ * We don't use the macros defined in LangDumpDecl.h here, in order that you can get a sense
+ * of what goes where.
+ */
+
+ /* Create a base Tree parser/recognizer, using the supplied tree node stream
+ */
+ ctx->pTreeParser = antlr3TreeParserNewStream(ANTLR3_SIZE_HINT, instream, state);
+ /* Install the implementation of our LangDumpDecl interface
+ */
+ ctx->decl = decl;
+ ctx->decls = decls;
+ ctx->type = type;
+ ctx->declarator = declarator;
+ ctx->free = LangDumpDeclFree;
+ ctx->getGrammarFileName = getGrammarFileName;
+
+ /* Install the scope pushing methods.
+ */
+
+
+
+
+
+ /* Install the token table
+ */
+ PSRSTATE->tokenNames = LangDumpDeclTokenNames;
+
+
+ /* Return the newly built parser to the caller
+ */
+ return ctx;
+}
+
+/** Free the parser resources
+ */
+ static void
+ LangDumpDeclFree(pLangDumpDecl ctx)
+ {
+ /* Free any scope memory
+ */
+
+
+ // Free this parser
+ //
+ ctx->pTreeParser->free(ctx->pTreeParser);
+ ANTLR3_FREE(ctx);
+
+ /* Everything is released, so we can return
+ */
+ return;
+ }
+
+/** Return token names used by this tree parser
+ *
+ * The returned pointer is used as an index into the token names table (using the token
+ * number as the index).
+ *
+ * \return Pointer to first char * in the table.
+ */
+static pANTLR3_UINT8 *getTokenNames()
+{
+ return LangDumpDeclTokenNames;
+}
+
+
+/* Declare the bitsets
+ */
+
+/** Bitset defining follow set for error recovery in rule state: FOLLOW_decls_in_decl58 */
+static ANTLR3_BITWORD FOLLOW_decls_in_decl58_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000012) };
+static ANTLR3_BITSET_LIST FOLLOW_decls_in_decl58 = { FOLLOW_decls_in_decl58_bits, 1 };
+/** Bitset defining follow set for error recovery in rule state: FOLLOW_DECL_in_decls71 */
+static ANTLR3_BITWORD FOLLOW_DECL_in_decls71_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000004) };
+static ANTLR3_BITSET_LIST FOLLOW_DECL_in_decls71 = { FOLLOW_DECL_in_decls71_bits, 1 };
+/** Bitset defining follow set for error recovery in rule state: FOLLOW_type_in_decls73 */
+static ANTLR3_BITWORD FOLLOW_type_in_decls73_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000020) };
+static ANTLR3_BITSET_LIST FOLLOW_type_in_decls73 = { FOLLOW_type_in_decls73_bits, 1 };
+/** Bitset defining follow set for error recovery in rule state: FOLLOW_declarator_in_decls77 */
+static ANTLR3_BITWORD FOLLOW_declarator_in_decls77_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000008) };
+static ANTLR3_BITSET_LIST FOLLOW_declarator_in_decls77 = { FOLLOW_declarator_in_decls77_bits, 1 };
+/** Bitset defining follow set for error recovery in rule state: FOLLOW_INTTYPE_in_type110 */
+static ANTLR3_BITWORD FOLLOW_INTTYPE_in_type110_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
+static ANTLR3_BITSET_LIST FOLLOW_INTTYPE_in_type110 = { FOLLOW_INTTYPE_in_type110_bits, 1 };
+/** Bitset defining follow set for error recovery in rule state: FOLLOW_ID_in_declarator126 */
+static ANTLR3_BITWORD FOLLOW_ID_in_declarator126_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
+static ANTLR3_BITSET_LIST FOLLOW_ID_in_declarator126 = { FOLLOW_ID_in_declarator126_bits, 1 };
+
+
+
+
+/* ==============================================
+ * Parsing rules
+ */
+/**
+ * $ANTLR start decl
+ * LangDumpDecl.g:10:1: decl : ( decls )+ ;
+ */
+static void
+decl(pLangDumpDecl ctx)
+{
+ /* Initialize rule variables
+ */
+
+
+ {
+ // LangDumpDecl.g:10:6: ( ( decls )+ )
+ // LangDumpDecl.g:10:8: ( decls )+
+ {
+ // LangDumpDecl.g:10:8: ( decls )+
+ {
+ int cnt1=0;
+
+ for (;;)
+ {
+ int alt1=2;
+ switch ( LA(1) )
+ {
+ case DECL:
+ {
+ alt1=1;
+ }
+ break;
+
+ }
+
+ switch (alt1)
+ {
+ case 1:
+ // LangDumpDecl.g:10:8: decls
+ {
+ FOLLOWPUSH(FOLLOW_decls_in_decl58);
+ decls(ctx);
+
+ FOLLOWPOP();
+ if (HASEXCEPTION())
+ {
+ goto ruledeclEx;
+ }
+
+
+ }
+ break;
+
+ default:
+
+ if ( cnt1 >= 1 )
+ {
+ goto loop1;
+ }
+ /* mismatchedSetEx()
+ */
+ CONSTRUCTEX();
+ EXCEPTION->type = ANTLR3_EARLY_EXIT_EXCEPTION;
+ EXCEPTION->name = (void *)ANTLR3_EARLY_EXIT_NAME;
+
+
+ goto ruledeclEx;
+ }
+ cnt1++;
+ }
+ loop1: ; /* Jump to here if this rule does not match */
+ }
+
+ }
+
+ }
+
+
+ // This is where rules clean up and exit
+ //
+ goto ruledeclEx; /* Prevent compiler warnings */
+ ruledeclEx: ;
+
+ if (HASEXCEPTION())
+ {
+ PREPORTERROR();
+ PRECOVER();
+ }
+
+
+ return ;
+}
+/* $ANTLR end decl */
+
+/**
+ * $ANTLR start decls
+ * LangDumpDecl.g:13:1: decls : ^( DECL type d= declarator ) ;
+ */
+static void
+decls(pLangDumpDecl ctx)
+{
+ LangDumpDecl_declarator_return d;
+ #undef RETURN_TYPE_d
+ #define RETURN_TYPE_d LangDumpDecl_declarator_return
+
+ /* Initialize rule variables
+ */
+
+
+ {
+ // LangDumpDecl.g:13:7: ( ^( DECL type d= declarator ) )
+ // LangDumpDecl.g:13:9: ^( DECL type d= declarator )
+ {
+ MATCHT(DECL, &FOLLOW_DECL_in_decls71);
+ if (HASEXCEPTION())
+ {
+ goto ruledeclsEx;
+ }
+
+
+ MATCHT(ANTLR3_TOKEN_DOWN, NULL);
+ if (HASEXCEPTION())
+ {
+ goto ruledeclsEx;
+ }
+
+ FOLLOWPUSH(FOLLOW_type_in_decls73);
+ type(ctx);
+
+ FOLLOWPOP();
+ if (HASEXCEPTION())
+ {
+ goto ruledeclsEx;
+ }
+
+ FOLLOWPUSH(FOLLOW_declarator_in_decls77);
+ d=declarator(ctx);
+
+ FOLLOWPOP();
+ if (HASEXCEPTION())
+ {
+ goto ruledeclsEx;
+ }
+
+
+ MATCHT(ANTLR3_TOKEN_UP, NULL);
+ if (HASEXCEPTION())
+ {
+ goto ruledeclsEx;
+ }
+
+ {
+
+ printf("int %s\n", (STRSTREAM->toStringSS(STRSTREAM, d.start, d.start))->chars);
+
+ }
+
+ }
+
+ }
+
+
+ // This is where rules clean up and exit
+ //
+ goto ruledeclsEx; /* Prevent compiler warnings */
+ ruledeclsEx: ;
+
+ if (HASEXCEPTION())
+ {
+ PREPORTERROR();
+ PRECOVER();
+ }
+
+
+ return ;
+}
+/* $ANTLR end decls */
+
+/**
+ * $ANTLR start type
+ * LangDumpDecl.g:21:1: type : INTTYPE ;
+ */
+static void
+type(pLangDumpDecl ctx)
+{
+ /* Initialize rule variables
+ */
+
+
+ {
+ // LangDumpDecl.g:21:6: ( INTTYPE )
+ // LangDumpDecl.g:21:8: INTTYPE
+ {
+ MATCHT(INTTYPE, &FOLLOW_INTTYPE_in_type110);
+ if (HASEXCEPTION())
+ {
+ goto ruletypeEx;
+ }
+
+
+ }
+
+ }
+
+
+ // This is where rules clean up and exit
+ //
+ goto ruletypeEx; /* Prevent compiler warnings */
+ ruletypeEx: ;
+
+ if (HASEXCEPTION())
+ {
+ PREPORTERROR();
+ PRECOVER();
+ }
+
+
+ return ;
+}
+/* $ANTLR end type */
+
+/**
+ * $ANTLR start declarator
+ * LangDumpDecl.g:23:1: declarator : i= ID ;
+ */
+static LangDumpDecl_declarator_return
+declarator(pLangDumpDecl ctx)
+{
+ LangDumpDecl_declarator_return retval;
+
+ pANTLR3_BASE_TREE i;
+
+ /* Initialize rule variables
+ */
+
+
+ i = NULL;
+ retval.start = LT(1); retval.stop = retval.start;
+
+ {
+ // LangDumpDecl.g:24:6: (i= ID )
+ // LangDumpDecl.g:24:8: i= ID
+ {
+ i = (pANTLR3_BASE_TREE) MATCHT(ID, &FOLLOW_ID_in_declarator126);
+ if (HASEXCEPTION())
+ {
+ goto ruledeclaratorEx;
+ }
+
+
+ }
+
+ }
+
+
+ // This is where rules clean up and exit
+ //
+ goto ruledeclaratorEx; /* Prevent compiler warnings */
+ ruledeclaratorEx: ;
+
+ if (HASEXCEPTION())
+ {
+ PREPORTERROR();
+ PRECOVER();
+ }
+
+
+ return retval;
+}
+/* $ANTLR end declarator */
+/* End of parsing rules
+ * ==============================================
+ */
+
+/* ==============================================
+ * Syntactic predicates
+ */
+/* End of syntactic predicates
+ * ==============================================
+ */
+
+
+
+
+
+
+/* End of code
+ * =============================================================================
+ */