conjure_static_lexer_generate.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2001-2011 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. // This small utility program generates the 2 static lexers, the static table
  6. // driven and the static switch based lexer.
  7. #include <fstream>
  8. #include <iostream>
  9. #include "lexer_def.hpp"
  10. #include <boost/spirit/include/lex_generate_static_lexertl.hpp>
  11. int main()
  12. {
  13. typedef std::string::const_iterator base_iterator_type;
  14. typedef client::lexer::conjure_tokens<base_iterator_type> lexer_type;
  15. lexer_type lexer;
  16. // first generate the static switch based lexer
  17. std::ofstream out_static("conjure_static_switch_lexer.hpp");
  18. bool result = boost::spirit::lex::lexertl::generate_static_switch(
  19. lexer, out_static, "conjure_static_switch");
  20. if (!result) {
  21. std::cerr << "Failed to generate static switch based lexer\n";
  22. return -1;
  23. }
  24. // now generate the static table based lexer
  25. std::ofstream out("conjure_static_lexer.hpp");
  26. result = boost::spirit::lex::lexertl::generate_static(
  27. lexer, out, "conjure_static");
  28. if (!result) {
  29. std::cerr << "Failed to generate static table based lexer\n";
  30. return -1;
  31. }
  32. return 0;
  33. }