]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/example/lex/static_lexer/word_count_generate.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / example / lex / static_lexer / word_count_generate.cpp
1 // Copyright (c) 2001-2010 Hartmut Kaiser
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 // The purpose of this example is to show, how it is possible to use a lexer
7 // token definition for two purposes:
8 //
9 // . To generate C++ code implementing a static lexical analyzer allowing
10 // to recognize all defined tokens (this file)
11 // . To integrate the generated C++ lexer into the /Spirit/ framework.
12 // (see the file: word_count_static.cpp)
13
14 // #define BOOST_SPIRIT_LEXERTL_DEBUG
15
16 #include <boost/config/warning_disable.hpp>
17 #include <boost/spirit/include/lex_lexertl.hpp>
18 #include <boost/spirit/include/lex_generate_static_lexertl.hpp>
19
20 #include <fstream>
21
22 #include "word_count_tokens.hpp"
23
24 using namespace boost::spirit;
25
26 ///////////////////////////////////////////////////////////////////////////////
27 //[wc_static_generate_main
28 int main(int argc, char* argv[])
29 {
30 // create the lexer object instance needed to invoke the generator
31 word_count_tokens<lex::lexertl::lexer<> > word_count; // the token definition
32
33 // open the output file, where the generated tokenizer function will be
34 // written to
35 std::ofstream out(argc < 2 ? "word_count_static.hpp" : argv[1]);
36
37 // invoke the generator, passing the token definition, the output stream
38 // and the name suffix of the tables and functions to be generated
39 //
40 // The suffix "wc" used below results in a type lexertl::static_::lexer_wc
41 // to be generated, which needs to be passed as a template parameter to the
42 // lexertl::static_lexer template (see word_count_static.cpp).
43 return lex::lexertl::generate_static_dfa(word_count, out, "wc") ? 0 : -1;
44 }
45 //]