org.antlr.codegen.templates.C.C.stg Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of antlr-complete Show documentation
Show all versions of antlr-complete Show documentation
Complete distribution for ANTLR 3
/*
[The "BSD license"]
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.
*/
/*
* This code generating template and the associated C runtime was produced by:
* Jim Idle jimi|hereisanat|idle|dotgoeshere|ws.
* If it causes the destruction of the Universe, it will be pretty cool so long as
* I am in a different one at the time.
*/
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
]
leadIn(type) ::=
<<
/** \file
* This file was generated by $ANTLR version
*
* - From the grammar source file :
* - On :
* - for the lexer : Lexer
* - for the parser : Parser
* - for the tree parser : TreeParser
*
* Editing it, at least manually, is not wise.
*
* C language generator and runtime by Jim Idle, jimi|hereisanat|idle|dotgoeshere|ws.
*
*
>>
/** 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,
rewriteMode,
profile,
backtracking,
synpreds,
memoize,
numRules,
fileName,
ANTLRVersion,
generatedTimestamp,
trace,
scopes,
superClass,
literals
) ::=
<<
*/
// [The "BSD license"]
// 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.
/* =============================================================================
* This is what the grammar programmer asked us to put at the top of every file.
*/
/* End of Header action.
* =============================================================================
*/
/* -----------------------------------------
* Include the ANTLR3 generated header file.
*/
#include ".h"
/* ----------------------------------------- */
/** String literals used by 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.
*/
[] = ;}; separator="\n">
/* 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) p_##scope##_SCOPE
#define SCOPE_STACK(scope) p_##scope##Stack
#define SCOPE_TOP(scope) ctx->p_##scope##Top
#define SCOPE_SIZE(scope) ctx->p_##scope##Stack_limit
#define SCOPE_INSTANCE(scope, i) (ctx->SCOPE_STACK(scope)->get(ctx->SCOPE_STACK(scope),i))
/* 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
#undef PUSHSTREAM
#undef POPSTREAM
#undef SETTEXT
#undef SETTEXT8
#define LEXER ctx->pLexer
#define RECOGNIZER LEXER->rec
#define LEXSTATE RECOGNIZER->state
#define TOKSOURCE LEXSTATE->tokSource
#define GETCHARINDEX() LEXER->getCharIndex(LEXER)
#define GETLINE() LEXER->getLine(LEXER)
#define GETTEXT() LEXER->getText(LEXER)
#define GETCHARPOSITIONINLINE() LEXER->getCharPositionInLine(LEXER)
#define EMIT() LEXSTATE->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 LEXSTATE->token
#define HASFAILED() (LEXSTATE->failed == ANTLR3_TRUE)
#define BACKTRACKING LEXSTATE->backtracking
#define FAILEDFLAG LEXSTATE->failed
#define INPUT LEXER->input
#define STRSTREAM INPUT
#define ISTREAM INPUT->istream
#define INDEX() ISTREAM->index(ISTREAM)
#define SEEK(n) ISTREAM->seek(ISTREAM, n)
#define EOF_TOKEN &(LEXSTATE->tokSource->eofToken)
#define HASEXCEPTION() (LEXSTATE->error == ANTLR3_TRUE)
#define EXCEPTION LEXSTATE->exception
#define CONSTRUCTEX() RECOGNIZER->exConstruct(RECOGNIZER)
#define LRECOVER() LEXER->recover(LEXER)
#define MARK() ISTREAM->mark(ISTREAM)
#define REWIND(m) ISTREAM->rewind(ISTREAM, m)
#define REWINDLAST() ISTREAM->rewindLast(ISTREAM)
#define MEMOIZE(ri,si) RECOGNIZER->memoize(RECOGNIZER, ri, si)
#define HAVEPARSEDRULE(r) RECOGNIZER->alreadyParsedRule(RECOGNIZER, r)
#define PUSHSTREAM(str) LEXER->pushCharStream(LEXER, str)
#define POPSTREAM() LEXER->popCharStream(LEXER)
#define SETTEXT(str) LEXSTATE->text = str
#define SKIP() LEXSTATE->token = &(TOKSOURCE->skipToken)
#define USER1 LEXSTATE->user1
#define USER2 LEXSTATE->user2
#define USER3 LEXSTATE->user3
#define CUSTOM LEXSTATE->custom
#define RULEMEMO LEXSTATE->ruleMemo
#define DBG RECOGNIZER->debugger
/* If we have been told we can rely on the standard 8 bit or UTF16 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 with 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_8BIT) || defined(ANTLR3_INLINE_INPUT_UTF16)
# ifdef ANTLR3_INLINE_INPUT_8BIT
/* 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
/* 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
#undef SEEK
#undef RULEMEMO
#undef DBG
#define PARSER ctx->pParser
#define RECOGNIZER PARSER->rec
#define PSRSTATE RECOGNIZER->state
#define HAVEPARSEDRULE(r) RECOGNIZER->alreadyParsedRule(RECOGNIZER, r)
#define MEMOIZE(ri,si) RECOGNIZER->memoize(RECOGNIZER, ri, si)
#define INPUT PARSER->tstream
#define STRSTREAM INPUT
#define ISTREAM INPUT->istream
#define INDEX() ISTREAM->index(INPUT->istream)
#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
#ifdef SKIP_FOLLOW_SETS
#define FOLLOWPUSH(x)
#define FOLLOWPOP()
#else
#define FOLLOWPUSH(x) FOLLOWSTACK->push(FOLLOWSTACK, ((void *)(&(x))), NULL)
#define FOLLOWPOP() FOLLOWSTACK->pop(FOLLOWSTACK)
#endif
#define PRECOVER() RECOGNIZER->recover(RECOGNIZER)
#define PREPORTERROR() RECOGNIZER->reportError(RECOGNIZER)
#define LA(n) INPUT->istream->_LA(ISTREAM, n)
#define LT(n) INPUT->_LT(INPUT, 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 SEEK(n) ISTREAM->seek(ISTREAM, n)
#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 ctx->adaptor
#define RULEMEMO PSRSTATE->ruleMemo
#define DBG RECOGNIZER->debugger
/* 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
*/
/* End of code
* =============================================================================
*/
>>
headerFileExtension() ::= ".h"
headerFile( LEXER,
PARSER,
TREE_PARSER,
actionScope,
actions,
docComment,
recognizer,
name,
tokens,
tokenNames,
rules,
cyclicDFAs,
bitsets,
buildTemplate,
buildAST,
rewriteMode,
profile,
backtracking,
synpreds,
memoize,
numRules,
fileName,
ANTLRVersion,
generatedTimestamp,
trace,
scopes,
superClass,
literals
) ::=
<<
* The parser
* The lexer
* The tree parser
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, which is returned from a call to New().
*
* As this is a generated lexer, it is unlikely you will call it 'manually'. However
* the methods are provided anyway.
*
* The methods in p are as follows:
*
* - p->(p)}; separator="\n * ">
*
* The return type for any particular rule is of course determined by the source
* grammar file.
*/
// [The "BSD license"]
// 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.
#ifndef __H
#define __H
/* =============================================================================
* Standard antlr3 C runtime definitions
*/
#include \
/* End of standard antlr 3 runtime definitions
* =============================================================================
*/
#ifdef __cplusplus
extern "C" {
#endif
// Forward declare the context typedef so that we can use it before it is
// properly defined. Delegators and delegates (from import statements) are
// interdependent and their context structures contain pointers to each other
// C only allows such things to be declared if you pre-declare the typedef.
//
typedef struct _Ctx_struct , * p;
// Include delegate definition header files
//
.h>}; separator="\n">
#ifdef ANTLR3_WINDOWS
// 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 variables declared but not needed
// Unreferenced local variable - lexer rule declares but does not always use _type
// potentially unitialized variable used - retval always returned from a rule
// unreferenced local function has been removed - susually getTokenNames or freeScope, they can go without warnigns
//
// These are only really displayed at warning 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 : 4101 )
#pragma warning( disable : 4127 )
#pragma warning( disable : 4189 )
#pragma warning( disable : 4505 )
#pragma warning( disable : 4701 )
#endif
/* ========================
* BACKTRACKING IS ENABLED
* ========================
*/
}>
}>
}>
// Include delegator definition header files
//
.h>}; separator="\n">
/** Context tracking structure for
*/
struct _Ctx_struct
{
/** Built in ANTLR3 context tracker contains all the generic elements
* required for context tracking.
*/
pANTLR3_PARSER pParser;
pANTLR3_LEXER pLexer;
pANTLR3_TREE_PARSER pTreeParser;
;}; separator="\n">
;}; separator="\n">
}; separator="\n\n">
}>
(*m) (struct _Ctx_struct * ctx, );}; separator="\n">
(*) (struct _Ctx_struct * ctx, );}; separator="\n">
// Delegated rules
(*)(struct _Ctx_struct * ctx, );}; separator="\n">
const char * (*getGrammarFileName)();
void (*reset) (struct _Ctx_struct * ctx);
void (*free) (struct _Ctx_struct * ctx);
<@members>
<@end>
};
// Function protoypes for the constructor functions that external translation units
// such as delegators and delegates may wish to call.
//
ANTLR3_API p New ( instream }>);
ANTLR3_API p NewSSD ( instream, pANTLR3_RECOGNIZER_SHARED_STATE state }>);
extern pANTLR3_UINT8 TokenNames[];
/** Symbolic definitions of all the tokens that the 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
}; separator="\n">
#ifdef EOF
#undef EOF
#define EOF ANTLR3_TOKEN_EOF
#endif
#ifndef TOKENSOURCE
#define TOKENSOURCE(lxr) lxr->pLexer->rec->state->tokSource
#endif
/* End of token definitions for
* =============================================================================
*/
/** \} */
#ifdef __cplusplus
}
#endif
#endif
/* END - Note:Keep extra line feed to satisfy UNIX systems */
>>
inputType() ::=<<
pANTLR3_INPUT_STREAM
pANTLR3_COMMON_TOKEN_STREAM
pANTLR3_COMMON_TREE_NODE_STREAM
>>
grammarType() ::= <<
parser
lexer
tree parser
>>
mainName() ::= <<
>>
headerReturnScope(ruleDescriptor) ::= ""
headerReturnType(ruleDescriptor) ::= <<
void
>>
// Produce the lexer output
//
lexer( grammar,
name,
tokens,
scopes,
rules,
numRules,
filterMode,
superClass,
labelType="pANTLR3_COMMON_TOKEN") ::= <<
/* Forward declare implementation function for ANTLR3_TOKEN_SOURCE interface when
* this is a filter mode lexer.
*/
static pANTLR3_COMMON_TOKEN NextToken (pANTLR3_TOKEN_SOURCE toksource);
/* Override the normal MEMOIZE and HAVEALREADYPARSED macros as this is a filtering
* lexer. In filter mode, the memoizing and backtracking are gated at BACKTRACKING > 1 rather
* than just BACKTRACKING. In some cases this might generate code akin to:
* if (BACKTRACKING) if (BACKTRACKING > 1) memoize.
* However, I assume that the C compilers/optimizers are smart enough to work this one out
* these days - Jim
*/
#undef MEMOIZE
#define MEMOIZE(ri,si) if (BACKTRACKING>1) { RECOGNIZER->memoize(RECOGNIZER, ri, si) }
#undef HAVEPARSEDRULE
#define HAVEPARSEDRULE(r) if (BACKTRACKING>1) { RECOGNIZER->alreadyParsedRule(RECOGNIZER, r) }
/* Forward declare the locally static matching functions we have generated and any predicate functions.
*/
m (p ctx, );}; separator="\n">
static void Free(p ctx);
/* =========================================================================
* Lexer matching rules end.
* =========================================================================
*/
}>
static void
Free (p ctx)
{
if (RULEMEMO != NULL)
{
RULEMEMO->free(RULEMEMO);
RULEMEMO = NULL;
}
// Free the lexers that we delegated to
// functions to. NULL the state so we only free it once.
//
->pLexer->rec->state = NULL;
ctx->->free(ctx->);}; separator="\n">
LEXER->free(LEXER);
ANTLR3_FREE(ctx);
}
static void
Reset (p ctx)
{
RECOGNIZER->reset(RECOGNIZER);
}
/** \brief Name of the grammar file that generated this code
*/
static const char fileName[] = "";
/** \brief Return the name of the grammar file that generated this code.
*/
static const char * getGrammarFileName()
{
return fileName;
}
/** \brief Create a new lexer called
*
* \param[in] instream Pointer to an initialized input stream
* \return
* - Success p initialized for the lex start
* - Fail NULL
*/
ANTLR3_API p New
( instream }>)
{
// See if we can create a new lexer with the standard constructor
//
return NewSSD(instream, NULL}>);
}
/** \brief Create a new lexer called
*
* \param[in] instream Pointer to an initialized input stream
* \param[state] state Previously created shared recognizer stat
* \return
* - Success p initialized for the lex start
* - Fail NULL
*/
ANTLR3_API p NewSSD
(pANTLR3_INPUT_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state }>)
{
p ctx; // Context structure we will build and return
ctx = (p) ANTLR3_CALLOC(1, sizeof());
if (ctx == NULL)
{
// Failed to allocate memory for lexer context
return NULL;
}
/* -------------------------------------------------------------------
* Memory for basic structure is allocated, now to fill in
* in base ANTLR3 structures. We initialize the function pointers
* for the standard ANTLR3 lexer 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 .h here so you can get a sense
* of what goes where.
*/
/* Create a base lexer, using the supplied input stream
*/
ctx->pLexer = antlr3LexerNewStream(ANTLR3_SIZE_HINT, instream, state);
/* Check that we allocated the memory correctly
*/
if (ctx->pLexer == NULL)
{
ANTLR3_FREE(ctx);
return NULL;
}
// Create a LIST for recording rule memos.
//
ctx->pLexer->rec->ruleMemo = antlr3IntTrieNew(15); /* 16 bit depth is enough for 32768 rules! */
/* Install the implementation of our interface
*/
ctx->m = m;}; separator="\n">
/** When the nextToken() call is made to this lexer's pANTLR3_TOKEN_SOURCE
* it will call mTokens() in this generated code, and will pass it the ctx
* pointer of this lexer, not the context of the base lexer, so store that now.
*/
ctx->pLexer->ctx = ctx;
/**Install the token matching function
*/
ctx->pLexer->mTokens = (void (*) (void *))(mTokens);
ctx->getGrammarFileName = getGrammarFileName;
ctx->free = Free;
ctx->reset = Reset;
// Initialize the lexers that we are going to delegate some
// functions to.
//
= NewSSD(instream, ctx->pLexer->rec->state, ctx