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