org.antlr.codegen.templates.Cpp.Cpp.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 Gokulakannan Somasundaram,
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 Cpp runtime was produced by:
* Gokulakannan Somasundaram ( heavy lifting from C Run-time by Jim Idle )
*/
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
"bool" : "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 Gokulakannan Somasundaram ( heavy lifting from C Run-time by Jim Idle )
*
*
>>
/** 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 Gokulakannan Somasundaram, ElectronDB
//
// 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 ".hpp"
#include \
// Include delegator definition header files
//
.hpp" }; separator="\n">
/* ----------------------------------------- */
/** 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">
/* ============================================================================= */
/* =============================================================================
* Start of recognizer
*/
/* End of code
* =============================================================================
*/
>>
headerFileExtension() ::= ".hpp"
beginNamespace(actions) ::= <%
namespace {
%>
endNamespace(actions) ::= <%
}
%>
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 has the callable functions (rules) shown below,
* The lexer has the callable functions (rules) shown below,
* 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 "BSD license"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram.
//
// 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
* =============================================================================
*/
// Include delegate definition header files
//
.hpp"}; separator="\n">
#ifdef WIN32
// 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 classes
//
; }; separator="\n">
typedef Traits ImplTraits;
struct {\}; }; separator="\n">
class Tokens
{
public:
/** 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 ANTLR_TOKEN_EOF.
*/
enum Tokens
{
EOF_TOKEN = ImplTraits::CommonTokenType::TOKEN_EOF
= }; separator="\n">
};
};
/** Context tracking structure for
*/
class : public , public Tokens
{
public:
typedef ImplTraits ImplTraits;
typedef ComponentType;
typedef ComponentType::StreamType StreamType;
typedef BaseType;
typedef ImplTraits::RecognizerSharedStateType\ RecognizerSharedStateType;
typedef StreamType InputType;
static const bool IsFiltered = true;
static const bool IsFiltered = false;
}>
}>
private:
* m_;}; separator="\n">
* m_;}; separator="\n">
}; separator="\n\n">
}>
<@members>
<@end>
public:
(InputType* instream* }>);
(InputType* instream, RecognizerSharedStateType* state* }>);
void init(InputType* instream * }> );
void memoize(ANTLR_MARKER ruleIndex, ANTLR_MARKER ruleParseStart);
bool alreadyParsedRule(ANTLR_MARKER ruleIndex);
m( );}; separator="\n">
msynpred( antlr3::ClassForwarder\< > );
void m_fragment ();}; separator="\n">
}>
(); }; separator="\n">
msynpred( antlr3::ClassForwarder\< > );
void m_fragment ();}; separator="\n">
// Delegated rules
();}; separator="\n">
const char * getGrammarFileName();
void reset();
~();
};
// Function protoypes for the constructor functions that external translation units
// such as delegators and delegates may wish to call.
//
extern ANTLR_UINT8* TokenNames[];
/* End of token definitions for
* =============================================================================
*/
#endif
/* END - Note:Keep extra line feed to satisfy UNIX systems */
>>
grammarType() ::= <%
parser
lexer
tree parser
%>
componentType() ::= <<
ImplTraits::ParserType
ImplTraits::LexerType
ImplTraits::TreeParserType
>>
componentBaseType() ::= <%
ImplTraits::BaseParserType
ImplTraits::BaseLexerType
ImplTraits::BaseTreeParserType
%>
streamType() ::= <<
ImplTraits::ParserType::StreamType
ImplTraits::LexerType::StreamType
ImplTraits::TreeParserType::StreamType
>>
mainName() ::= <%
%>
headerReturnScope(ruleDescriptor) ::= ""
headerReturnType(ruleDescriptor) ::= <%
void
%>
// Produce the lexer output
//
lexer( grammar,
name,
tokens,
scopes,
rules,
numRules,
filterMode,
superClass,
labelType="ImplTraits::CommonTokenType*") ::= <<
using namespace antlr3;
/* 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.
*/
void ::memoize(ANTLR_MARKER ruleIndex, ANTLR_MARKER ruleParseStart)
{
BaseType* base = this;
if ( this->get_backtracking()>1 )
base->memoize( ruleIndex, ruleParseStart );
}
bool ::alreadyParsedRule(ANTLR_MARKER ruleIndex)
{
BaseType* base = this;
if ( this->get_backtracking() > 1 )
return base->haveParsedRule(ruleIndex);
return false;
}
/* =========================================================================
* Lexer matching rules end.
* =========================================================================
*/
}>
::~()
{
RuleMemoType* rulememo = this->getRuleMemo();
if(rulememo != NULL)
{
delete rulememo;
this->setRuleMemo(NULL);
}
// Free the lexers that we delegated to
// functions to. NULL the state so we only free it once.
//
->set_lexstate(NULL);
delete m_; }; separator="\n">
}
void
::reset()
{
this->get_rec()->reset();
}
/** \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.
*/
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
*/
::(StreamType* instream* }>)
:ImplTraits::BaseLexerType(ANTLR_SIZE_HINT, instream, NULL)
{
// See if we can create a new lexer with the standard constructor
//
this->init(instream }>);
}
/** \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
*/
::(StreamType* instream, RecognizerSharedStateType* state* }>)
:ImplTraits::BaseLexerType(ANTLR_SIZE_HINT, instream, state)
{
this->init(instream } >);
}
void ::init(StreamType* instream* } >)
{
/* -------------------------------------------------------------------
* 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 LIST for recording rule memos.
//
this->setRuleMemo( new IntTrie(15) ); /* 16 bit depth is enough for 32768 rules! */