expression.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_MINIC_EXPRESSION_HPP)
  7. #define BOOST_SPIRIT_MINIC_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 "skipper.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>
  33. struct expression : qi::grammar<Iterator, ast::expression(), skipper<Iterator> >
  34. {
  35. expression(error_handler<Iterator>& error_handler);
  36. qi::rule<Iterator, ast::expression(), skipper<Iterator> >
  37. expr, equality_expr, relational_expr,
  38. logical_or_expr, logical_and_expr,
  39. additive_expr, multiplicative_expr
  40. ;
  41. qi::rule<Iterator, ast::operand(), skipper<Iterator> >
  42. unary_expr, primary_expr
  43. ;
  44. qi::rule<Iterator, ast::function_call(), skipper<Iterator> >
  45. function_call
  46. ;
  47. qi::rule<Iterator, std::list<ast::expression>(), skipper<Iterator> >
  48. argument_list
  49. ;
  50. qi::rule<Iterator, std::string(), skipper<Iterator> >
  51. identifier
  52. ;
  53. qi::symbols<char, ast::optoken>
  54. logical_or_op, logical_and_op,
  55. equality_op, relational_op,
  56. additive_op, multiplicative_op, unary_op
  57. ;
  58. qi::symbols<char>
  59. keywords
  60. ;
  61. };
  62. }}
  63. #endif