2 * This C source file was generated by $ANTLR version 3.2 Sep 23, 2009 12:02:23
4 * - From the grammar source file : LangDumpDecl.g
5 * - On : 2010-02-24 13:30:09
6 * - for the tree parser : LangDumpDeclTreeParser *
7 * Editing it, at least manually, is not wise.
9 * C language generator and runtime by Jim Idle, jimi|hereisanat|idle|dotgoeshere|ws.
13 // [The "BSD licence"]
14 // Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
15 // http://www.temporal-wave.com
16 // http://www.linkedin.com/in/jimidle
18 // All rights reserved.
20 // Redistribution and use in source and binary forms, with or without
21 // modification, are permitted provided that the following conditions
23 // 1. Redistributions of source code must retain the above copyright
24 // notice, this list of conditions and the following disclaimer.
25 // 2. Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 // 3. The name of the author may not be used to endorse or promote products
29 // derived from this software without specific prior written permission.
31 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
32 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
35 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 /* -----------------------------------------
43 * Include the ANTLR3 generated header file.
45 #include "LangDumpDecl.h"
46 /* ----------------------------------------- */
52 /* MACROS that hide the C interface implementations from the
53 * generated code, which makes it a little more understandable to the human eye.
54 * I am very much against using C pre-processor macros for function calls and bits
55 * of code as you cannot see what is happening when single stepping in debuggers
56 * and so on. The exception (in my book at least) is for generated code, where you are
57 * not maintaining it, but may wish to read and understand it. If you single step it, you know that input()
58 * hides some indirect calls, but is always referring to the input stream. This is
59 * probably more readable than ctx->input->istream->input(snarfle0->blarg) and allows me to rejig
60 * the runtime interfaces without changing the generated code too often, without
61 * confusing the reader of the generated output, who may not wish to know the gory
62 * details of the interface inheritance.
67 /* Aids in accessing scopes for grammar programmers
72 #define SCOPE_TYPE(scope) pLangDumpDecl_##scope##_SCOPE
73 #define SCOPE_STACK(scope) pLangDumpDecl_##scope##Stack
74 #define SCOPE_TOP(scope) ctx->pLangDumpDecl_##scope##Top
75 #define SCOPE_SIZE(scope) ctx->pLangDumpDecl_##scope##Stack_limit
76 #define SCOPE_INSTANCE(scope, i) (ctx->SCOPE_STACK(scope)->get(ctx->SCOPE_STACK(scope),i))
78 /* Macros for accessing things in the parser
102 #undef PERRORRECOVERY
105 #undef RECOVERFROMMISMATCHEDSET
106 #undef RECOVERFROMMISMATCHEDELEMENT
114 #define PARSER ctx->pTreeParser
115 #define RECOGNIZER PARSER->rec
116 #define PSRSTATE RECOGNIZER->state
117 #define HAVEPARSEDRULE(r) RECOGNIZER->alreadyParsedRule(RECOGNIZER, r)
118 #define INPUT PARSER->ctnstream
119 #define ISTREAM INPUT->tnstream->istream
120 #define STRSTREAM INPUT->tnstream
121 #define HASEXCEPTION() (PSRSTATE->error == ANTLR3_TRUE)
122 #define EXCEPTION PSRSTATE->exception
123 #define MATCHT(t, fs) RECOGNIZER->match(RECOGNIZER, t, fs)
124 #define MATCHANYT() RECOGNIZER->matchAny(RECOGNIZER)
125 #define FOLLOWSTACK PSRSTATE->following
126 #define FOLLOWPUSH(x) FOLLOWSTACK->push(FOLLOWSTACK, ((void *)(&(x))), NULL)
127 #define FOLLOWPOP() FOLLOWSTACK->pop(FOLLOWSTACK)
128 #define PRECOVER() RECOGNIZER->recover(RECOGNIZER)
129 #define PREPORTERROR() RECOGNIZER->reportError(RECOGNIZER)
130 #define LA(n) ISTREAM->_LA(ISTREAM, n)
131 #define LT(n) INPUT->tnstream->_LT(INPUT->tnstream, n)
132 #define CONSTRUCTEX() RECOGNIZER->exConstruct(RECOGNIZER)
133 #define CONSUME() ISTREAM->consume(ISTREAM)
134 #define MARK() ISTREAM->mark(ISTREAM)
135 #define REWIND(m) ISTREAM->rewind(ISTREAM, m)
136 #define REWINDLAST() ISTREAM->rewindLast(ISTREAM)
137 #define PERRORRECOVERY PSRSTATE->errorRecovery
138 #define FAILEDFLAG PSRSTATE->failed
139 #define HASFAILED() (FAILEDFLAG == ANTLR3_TRUE)
140 #define BACKTRACKING PSRSTATE->backtracking
141 #define RECOVERFROMMISMATCHEDSET(s) RECOGNIZER->recoverFromMismatchedSet(RECOGNIZER, s)
142 #define RECOVERFROMMISMATCHEDELEMENT(e) RECOGNIZER->recoverFromMismatchedElement(RECOGNIZER, s)
143 #define ADAPTOR INPUT->adaptor
144 #define RULEMEMO PSRSTATE->ruleMemo
145 #define SEEK(n) ISTREAM->seek(ISTREAM, n)
146 #define INDEX() ISTREAM->index(ISTREAM)
147 #define DBG RECOGNIZER->debugger
150 #define TOKTEXT(tok, txt) tok, (pANTLR3_UINT8)txt
152 /* The 4 tokens defined below may well clash with your own #defines or token types. If so
153 * then for the present you must use different names for your defines as these are hard coded
154 * in the code generator. It would be better not to use such names internally, and maybe
155 * we can change this in a forthcoming release. I deliberately do not #undef these
156 * here as this will at least give you a redefined error somewhere if they clash.
158 #define UP ANTLR3_TOKEN_UP
159 #define DOWN ANTLR3_TOKEN_DOWN
160 #define EOR ANTLR3_TOKEN_EOR
161 #define INVALID ANTLR3_TOKEN_INVALID
164 /* =============================================================================
165 * Functions to create and destroy scopes. First come the rule scopes, followed
166 * by the global declared scopes.
171 /* ============================================================================= */
173 /* =============================================================================
174 * Start of recognizer
179 /** \brief Table of all token names in symbolic order, mainly used for
182 pANTLR3_UINT8 LangDumpDeclTokenNames[7+4]
184 (pANTLR3_UINT8) "<invalid>", /* String to print to indicate an invalid token */
185 (pANTLR3_UINT8) "<EOR>",
186 (pANTLR3_UINT8) "<DOWN>",
187 (pANTLR3_UINT8) "<UP>",
188 (pANTLR3_UINT8) "DECL",
189 (pANTLR3_UINT8) "ID",
190 (pANTLR3_UINT8) "INTTYPE",
191 (pANTLR3_UINT8) "FLOATTYPE",
192 (pANTLR3_UINT8) "INT",
193 (pANTLR3_UINT8) "WS",
194 (pANTLR3_UINT8) "';'"
199 // Forward declare the locally static matching functions we have generated.
201 static void decl (pLangDumpDecl ctx);
202 static void decls (pLangDumpDecl ctx);
203 static void type (pLangDumpDecl ctx);
204 static LangDumpDecl_declarator_return declarator (pLangDumpDecl ctx);
205 static void LangDumpDeclFree(pLangDumpDecl ctx);
206 /* For use in tree output where we are accumulating rule labels via label += ruleRef
207 * we need a function that knows how to free a return scope when the list is destroyed.
208 * We cannot just use ANTLR3_FREE because in debug tracking mode, this is a macro.
210 static void ANTLR3_CDECL freeScope(void * scope)
215 /** \brief Name of the grammar file that generated this code
217 static const char fileName[] = "LangDumpDecl.g";
219 /** \brief Return the name of the grammar file that generated this code.
221 static const char * getGrammarFileName()
225 /** \brief Create a new LangDumpDecl parser and return a context for it.
227 * \param[in] instream Pointer to an input stream interface.
229 * \return Pointer to new parser context upon success.
231 ANTLR3_API pLangDumpDecl
232 LangDumpDeclNew (pANTLR3_COMMON_TREE_NODE_STREAM instream)
234 // See if we can create a new parser with the standard constructor
236 return LangDumpDeclNewSSD(instream, NULL);
239 /** \brief Create a new LangDumpDecl parser and return a context for it.
241 * \param[in] instream Pointer to an input stream interface.
243 * \return Pointer to new parser context upon success.
245 ANTLR3_API pLangDumpDecl
246 LangDumpDeclNewSSD (pANTLR3_COMMON_TREE_NODE_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state)
248 pLangDumpDecl ctx; /* Context structure we will build and return */
250 ctx = (pLangDumpDecl) ANTLR3_CALLOC(1, sizeof(LangDumpDecl));
254 // Failed to allocate memory for parser context
259 /* -------------------------------------------------------------------
260 * Memory for basic structure is allocated, now to fill in
261 * the base ANTLR3 structures. We initialize the function pointers
262 * for the standard ANTLR3 parser function set, but upon return
263 * from here, the programmer may set the pointers to provide custom
264 * implementations of each function.
266 * We don't use the macros defined in LangDumpDecl.h here, in order that you can get a sense
267 * of what goes where.
270 /* Create a base Tree parser/recognizer, using the supplied tree node stream
272 ctx->pTreeParser = antlr3TreeParserNewStream(ANTLR3_SIZE_HINT, instream, state);
273 /* Install the implementation of our LangDumpDecl interface
278 ctx->declarator = declarator;
279 ctx->free = LangDumpDeclFree;
280 ctx->getGrammarFileName = getGrammarFileName;
282 /* Install the scope pushing methods.
289 /* Install the token table
291 PSRSTATE->tokenNames = LangDumpDeclTokenNames;
294 /* Return the newly built parser to the caller
299 /** Free the parser resources
302 LangDumpDeclFree(pLangDumpDecl ctx)
304 /* Free any scope memory
310 ctx->pTreeParser->free(ctx->pTreeParser);
313 /* Everything is released, so we can return
318 /** Return token names used by this tree parser
320 * The returned pointer is used as an index into the token names table (using the token
321 * number as the index).
323 * \return Pointer to first char * in the table.
325 static pANTLR3_UINT8 *getTokenNames()
327 return LangDumpDeclTokenNames;
331 /* Declare the bitsets
334 /** Bitset defining follow set for error recovery in rule state: FOLLOW_decls_in_decl58 */
335 static ANTLR3_BITWORD FOLLOW_decls_in_decl58_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000012) };
336 static ANTLR3_BITSET_LIST FOLLOW_decls_in_decl58 = { FOLLOW_decls_in_decl58_bits, 1 };
337 /** Bitset defining follow set for error recovery in rule state: FOLLOW_DECL_in_decls71 */
338 static ANTLR3_BITWORD FOLLOW_DECL_in_decls71_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000004) };
339 static ANTLR3_BITSET_LIST FOLLOW_DECL_in_decls71 = { FOLLOW_DECL_in_decls71_bits, 1 };
340 /** Bitset defining follow set for error recovery in rule state: FOLLOW_type_in_decls73 */
341 static ANTLR3_BITWORD FOLLOW_type_in_decls73_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000020) };
342 static ANTLR3_BITSET_LIST FOLLOW_type_in_decls73 = { FOLLOW_type_in_decls73_bits, 1 };
343 /** Bitset defining follow set for error recovery in rule state: FOLLOW_declarator_in_decls77 */
344 static ANTLR3_BITWORD FOLLOW_declarator_in_decls77_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000008) };
345 static ANTLR3_BITSET_LIST FOLLOW_declarator_in_decls77 = { FOLLOW_declarator_in_decls77_bits, 1 };
346 /** Bitset defining follow set for error recovery in rule state: FOLLOW_INTTYPE_in_type110 */
347 static ANTLR3_BITWORD FOLLOW_INTTYPE_in_type110_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
348 static ANTLR3_BITSET_LIST FOLLOW_INTTYPE_in_type110 = { FOLLOW_INTTYPE_in_type110_bits, 1 };
349 /** Bitset defining follow set for error recovery in rule state: FOLLOW_ID_in_declarator126 */
350 static ANTLR3_BITWORD FOLLOW_ID_in_declarator126_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
351 static ANTLR3_BITSET_LIST FOLLOW_ID_in_declarator126 = { FOLLOW_ID_in_declarator126_bits, 1 };
356 /* ==============================================
361 * LangDumpDecl.g:10:1: decl : ( decls )+ ;
364 decl(pLangDumpDecl ctx)
366 /* Initialize rule variables
371 // LangDumpDecl.g:10:6: ( ( decls )+ )
372 // LangDumpDecl.g:10:8: ( decls )+
374 // LangDumpDecl.g:10:8: ( decls )+
394 // LangDumpDecl.g:10:8: decls
396 FOLLOWPUSH(FOLLOW_decls_in_decl58);
418 EXCEPTION->type = ANTLR3_EARLY_EXIT_EXCEPTION;
419 EXCEPTION->name = (void *)ANTLR3_EARLY_EXIT_NAME;
426 loop1: ; /* Jump to here if this rule does not match */
434 // This is where rules clean up and exit
436 goto ruledeclEx; /* Prevent compiler warnings */
448 /* $ANTLR end decl */
452 * LangDumpDecl.g:13:1: decls : ^( DECL type d= declarator ) ;
455 decls(pLangDumpDecl ctx)
457 LangDumpDecl_declarator_return d;
459 #define RETURN_TYPE_d LangDumpDecl_declarator_return
461 /* Initialize rule variables
466 // LangDumpDecl.g:13:7: ( ^( DECL type d= declarator ) )
467 // LangDumpDecl.g:13:9: ^( DECL type d= declarator )
469 MATCHT(DECL, &FOLLOW_DECL_in_decls71);
476 MATCHT(ANTLR3_TOKEN_DOWN, NULL);
482 FOLLOWPUSH(FOLLOW_type_in_decls73);
491 FOLLOWPUSH(FOLLOW_declarator_in_decls77);
501 MATCHT(ANTLR3_TOKEN_UP, NULL);
509 printf("int %s\n", (STRSTREAM->toStringSS(STRSTREAM, d.start, d.start))->chars);
518 // This is where rules clean up and exit
520 goto ruledeclsEx; /* Prevent compiler warnings */
532 /* $ANTLR end decls */
536 * LangDumpDecl.g:21:1: type : INTTYPE ;
539 type(pLangDumpDecl ctx)
541 /* Initialize rule variables
546 // LangDumpDecl.g:21:6: ( INTTYPE )
547 // LangDumpDecl.g:21:8: INTTYPE
549 MATCHT(INTTYPE, &FOLLOW_INTTYPE_in_type110);
561 // This is where rules clean up and exit
563 goto ruletypeEx; /* Prevent compiler warnings */
575 /* $ANTLR end type */
578 * $ANTLR start declarator
579 * LangDumpDecl.g:23:1: declarator : i= ID ;
581 static LangDumpDecl_declarator_return
582 declarator(pLangDumpDecl ctx)
584 LangDumpDecl_declarator_return retval;
588 /* Initialize rule variables
593 retval.start = LT(1); retval.stop = retval.start;
596 // LangDumpDecl.g:24:6: (i= ID )
597 // LangDumpDecl.g:24:8: i= ID
599 i = (pANTLR3_BASE_TREE) MATCHT(ID, &FOLLOW_ID_in_declarator126);
602 goto ruledeclaratorEx;
611 // This is where rules clean up and exit
613 goto ruledeclaratorEx; /* Prevent compiler warnings */
625 /* $ANTLR end declarator */
626 /* End of parsing rules
627 * ==============================================
630 /* ==============================================
631 * Syntactic predicates
633 /* End of syntactic predicates
634 * ==============================================
643 * =============================================================================