Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Wave: a Standard conformant C++ preprocessor library

, 10 Jan 2004
Describes a free and fully Standard conformant C++ preprocessor library
wave_preprocessor_demo.zip
wave_preprocessor_demo1.zip
wave_preprocessor_src.zip
wave
doc
theme
bkd.gif
bkd2.gif
bullet.gif
l_arr.gif
l_arr_disabled.gif
r_arr.gif
r_arr_disabled.gif
uc.gif
u_arr.gif
wave.gif
test
boost-build.jam
cpp_tokens
Jamfile.v2
list_includes
project-root.jam
wave
Jamfile
Jamfile.v2
runtests.sh
test_files
wave
cpplexer
re2clex
cpp.re
test
lextest.in
lextest.output
run_tests.sh
test_lexer.in
test_lexer.output
slex
test
lextest.in
lextest.re2c.output
lextest.slex.output
run_tests.sh
grammars
idllexer
re2clex
idl.re
util
wave_preprocessor_src1.zip
bkd.gif
bkd2.gif
bullet.gif
l_arr.gif
l_arr_disabled.gif
r_arr.gif
r_arr_disabled.gif
u_arr.gif
uc.gif
wave.gif
boost-build.jam
Jamfile.v2
project-root.jam
Jamfile
Jamfile.v2
runtests.sh
cpp.re
lextest.in
lextest.output
run_tests.sh
test_lexer.in
test_lexer.output
lextest.in
lextest.re2c.output
lextest.slex.output
run_tests.sh
/*=============================================================================
    Wave: A Standard compliant C++ preprocessor

    Copyright (c) 2001-2004 Hartmut Kaiser
    http://spirit.sourceforge.net/

    Use, modification and distribution is subject to the Boost Software
    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    http://www.boost.org/LICENSE_1_0.txt)

    See Copyright.txt for full acknowledgements.
=============================================================================*/

#if !defined(CPP_GRAMMAR_GEN_HPP_80CB8A59_5411_4E45_B406_62531A12FB99_INCLUDED)
#define CPP_GRAMMAR_GEN_HPP_80CB8A59_5411_4E45_B406_62531A12FB99_INCLUDED

#include <boost/spirit/tree/parse_tree.hpp>

#include "wave/lex_iterator.hpp"
#include "wave/language_support.hpp"

///////////////////////////////////////////////////////////////////////////////
namespace wave {
namespace grammars {

///////////////////////////////////////////////////////////////////////////////
//  
//  store parser_id's of all rules of the cpp_grammar here for later access
//
///////////////////////////////////////////////////////////////////////////////
struct cpp_grammar_rule_ids {
    std::size_t pp_statement_id;
    std::size_t include_file_id;       // #include "..."
    std::size_t sysinclude_file_id;    // #include <...>
    std::size_t macroinclude_file_id;  // #include ...
    std::size_t plain_define_id;       // #define
    std::size_t macro_parameters_id;
    std::size_t macro_definition_id;
    std::size_t undefine_id;           // #undef
    std::size_t ifdef_id;              // #ifdef
    std::size_t ifndef_id;             // #ifndef
    std::size_t if_id;                 // #if
    std::size_t elif_id;               // #elif
    std::size_t else_id;               // #else
    std::size_t endif_id;              // #endif
    std::size_t line_id;               // #line
    std::size_t error_id;              // #error
    std::size_t warning_id;            // #warning
    std::size_t pragma_id;             // #pragma
    std::size_t illformed_id;
    std::size_t ppspace_id;
#if defined(WAVE_ENABLE_CPP0X_EXTENSIONS)
    std::size_t pp_regionsupport_id;
    std::size_t ppregion_id;           // #region
    std::size_t ppendregion_id;        // #endregion
    std::size_t ppimport_id;           // #import
#endif // defined(WAVE_ENABLE_CPP0X_EXTENSIONS)
    std::size_t ppqualifiedname_id;
};

///////////////////////////////////////////////////////////////////////////////
//  
//  cpp_grammar_gen template class
//
//      This template helps separating the compilation of the cpp_grammar 
//      class from the compilation of the main pp_iterator. This is done to
//      safe compilation time.
//
///////////////////////////////////////////////////////////////////////////////

template <typename TokenT>
struct cpp_grammar_gen
{
    typedef WAVE_LEXER_NS::lex_iterator<TokenT>    iterator_t;
    typedef typename TokenT::position_t             position_t;
    
//  the parser_id's of all rules of the cpp_grammar are stored here
//  note: these are valid only after the first call to parse_cpp_grammar
    static cpp_grammar_rule_ids rule_ids;

//  the actual position of the last matched T_NEWLINE is stored here into the
//  member 'pos_of_newline'
    static position_t pos_of_newline;

//  the found_eof flag is set to true during the parsing, if the directive 
//  under inspection terminates with a T__EOF token
    static bool found_eof;

//  the found_directive contains the token_id of the recognized pp directive
    static WAVE_LEXER_NS::token_id found_directive;
        
//  parse the cpp_grammar and return the resulting parse tree    
    static boost::spirit::tree_parse_info<iterator_t> 
    parse_cpp_grammar (iterator_t const &first, iterator_t const &last,
        bool &found_eof_, position_t const &act_pos);
};

///////////////////////////////////////////////////////////////////////////////
//  definitions of the static members
template <typename TokenT>
cpp_grammar_rule_ids cpp_grammar_gen<TokenT>::rule_ids;

template <typename TokenT>
typename TokenT::position_t cpp_grammar_gen<TokenT>::pos_of_newline;

template <typename TokenT>
bool cpp_grammar_gen<TokenT>::found_eof = false;

template <typename TokenT>
typename WAVE_LEXER_NS::token_id cpp_grammar_gen<TokenT>::found_directive = 
    WAVE_LEXER_NS::T_EOF;

///////////////////////////////////////////////////////////////////////////////
}   // namespace grammars
}   // namespace wave

#endif // !defined(CPP_GRAMMAR_GEN_HPP_80CB8A59_5411_4E45_B406_62531A12FB99_INCLUDED)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Hartmut Kaiser

United States United States
Actively involved in Boost and the development of the Spirit parser construction framework.

| Advertise | Privacy | Mobile
Web03 | 2.8.140902.1 | Last Updated 11 Jan 2004
Article Copyright 2003 by Hartmut Kaiser
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid