expression.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #if !defined(BOOST_SPIRIT_CONJURE_EXPRESSION_HPP)
  8. #define BOOST_SPIRIT_CONJURE_EXPRESSION_HPP
  9. ///////////////////////////////////////////////////////////////////////////////
  10. // Spirit v2.5 allows you to suppress automatic generation
  11. // of predefined terminals to speed up complation. With
  12. // BOOST_SPIRIT_NO_PREDEFINED_TERMINALS defined, you are
  13. // responsible in creating instances of the terminals that
  14. // you need (e.g. see qi::uint_type uint_ below).
  15. #define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
  16. ///////////////////////////////////////////////////////////////////////////////
  17. ///////////////////////////////////////////////////////////////////////////////
  18. // Uncomment this if you want to enable debugging
  19. // #define BOOST_SPIRIT_QI_DEBUG
  20. ///////////////////////////////////////////////////////////////////////////////
  21. #include <boost/spirit/include/qi.hpp>
  22. #include "ast.hpp"
  23. #include "error_handler.hpp"
  24. #include <vector>
  25. namespace client { namespace parser
  26. {
  27. namespace qi = boost::spirit::qi;
  28. namespace ascii = boost::spirit::ascii;
  29. ///////////////////////////////////////////////////////////////////////////////
  30. // The expression grammar
  31. ///////////////////////////////////////////////////////////////////////////////
  32. template <typename Iterator, typename Lexer>
  33. struct expression : qi::grammar<Iterator, ast::expression()>
  34. {
  35. typedef error_handler<typename Lexer::base_iterator_type, Iterator>
  36. error_handler_type;
  37. expression(error_handler_type& error_handler, Lexer const& l);
  38. Lexer const& lexer;
  39. qi::rule<Iterator, ast::expression()> expr;
  40. qi::rule<Iterator, ast::operand()> unary_expr, postfix_expr;
  41. qi::rule<Iterator, ast::function_call()> function_call;
  42. qi::rule<Iterator, std::list<ast::expression>()> argument_list;
  43. qi::rule<Iterator, std::string()> identifier;
  44. qi::rule<Iterator, ast::primary_expr()> primary_expr;
  45. };
  46. }}
  47. #endif