expression.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  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. #if !defined(BOOST_SPIRIT_CALC8_EXPRESSION_HPP)
  7. #define BOOST_SPIRIT_CALC8_EXPRESSION_HPP
  8. ///////////////////////////////////////////////////////////////////////////////
  9. // Spirit v2.5 allows you to suppress automatic generation
  10. // of predefined terminals to speed up complation. With
  11. // BOOST_SPIRIT_NO_PREDEFINED_TERMINALS defined, you are
  12. // responsible in creating instances of the terminals that
  13. // you need (e.g. see qi::uint_type uint_ below).
  14. #define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
  15. ///////////////////////////////////////////////////////////////////////////////
  16. ///////////////////////////////////////////////////////////////////////////////
  17. // Uncomment this if you want to enable debugging
  18. // #define BOOST_SPIRIT_QI_DEBUG
  19. ///////////////////////////////////////////////////////////////////////////////
  20. #include <boost/spirit/include/qi.hpp>
  21. #include "ast.hpp"
  22. #include "error_handler.hpp"
  23. #include <vector>
  24. namespace client { namespace parser
  25. {
  26. namespace qi = boost::spirit::qi;
  27. namespace ascii = boost::spirit::ascii;
  28. ///////////////////////////////////////////////////////////////////////////////
  29. // The expression grammar
  30. ///////////////////////////////////////////////////////////////////////////////
  31. template <typename Iterator>
  32. struct expression : qi::grammar<Iterator, ast::expression(), ascii::space_type>
  33. {
  34. expression(error_handler<Iterator>& error_handler);
  35. qi::rule<Iterator, ast::expression(), ascii::space_type>
  36. expr, equality_expr, relational_expr,
  37. logical_expr, additive_expr, multiplicative_expr
  38. ;
  39. qi::rule<Iterator, ast::operand(), ascii::space_type>
  40. unary_expr, primary_expr
  41. ;
  42. qi::rule<Iterator, std::string(), ascii::space_type>
  43. identifier
  44. ;
  45. qi::symbols<char, ast::optoken>
  46. equality_op, relational_op, logical_op,
  47. additive_op, multiplicative_op, unary_op
  48. ;
  49. qi::symbols<char>
  50. keywords
  51. ;
  52. };
  53. }}
  54. #endif