|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r69814 - in trunk/libs/spirit/example/qi/compiler_tutorial: conjure mini_c
From: joel_at_[hidden]
Date: 2011-03-09 20:19:00
Author: djowel
Date: 2011-03-09 20:18:58 EST (Wed, 09 Mar 2011)
New Revision: 69814
URL: http://svn.boost.org/trac/boost/changeset/69814
Log:
- fixed mini_c precedence
- prelude to adding more operators in conjure
Text files modified:
trunk/libs/spirit/example/qi/compiler_tutorial/conjure/ast.hpp | 53 +++++++++++++++++++++---
trunk/libs/spirit/example/qi/compiler_tutorial/conjure/compiler.cpp | 84 +++++++++++++++++++++++++++++++--------
trunk/libs/spirit/example/qi/compiler_tutorial/conjure/expression_def.hpp | 4
trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression.hpp | 6 +
trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression_def.hpp | 35 ++++++++++------
5 files changed, 141 insertions(+), 41 deletions(-)
Modified: trunk/libs/spirit/example/qi/compiler_tutorial/conjure/ast.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/conjure/ast.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure/ast.hpp 2011-03-09 20:18:58 EST (Wed, 09 Mar 2011)
@@ -51,31 +51,70 @@
enum optoken
{
// precedence 1
+ op_comma,
+
+ // precedence 2
+ op_assign,
+ op_plus_assign,
+ op_minus_assign,
+ op_times_assign,
+ op_divide_assign,
+ op_mod_assign,
+ op_bit_and_assign,
+ op_bit_xor_assign,
+ op_bitor_assign,
+ op_shift_left_assign,
+ op_shift_right_assign,
+
+ // precedence 3
+ op_logical_or,
+
+ // precedence 4
+ op_logical_and,
+
+ // precedence 5
+ op_bit_or,
+
+ // precedence 6
+ op_bit_xor,
+
+ // precedence 7
+ op_bit_and,
+
+ // precedence 8
op_equal,
op_not_equal,
- // precedence 2
+ // precedence 9
op_less,
op_less_equal,
op_greater,
op_greater_equal,
- // precedence 3
- op_and,
- op_or,
+ // precedence 10
+ op_shift_left,
+ op_shift_right,
- // precedence 4
+ // precedence 11
op_plus,
op_minus,
- // precedence 5
+ // precedence 12
op_times,
op_divide,
+ op_mod,
- // precedence 6
+ // precedence 13
op_positive,
op_negative,
+ op_pre_incr,
+ op_pre_decr,
+ op_compl,
op_not,
+
+ // precedence 14
+ op_post_incr,
+ op_post_decr,
};
struct unary
Modified: trunk/libs/spirit/example/qi/compiler_tutorial/conjure/compiler.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/conjure/compiler.cpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure/compiler.cpp 2011-03-09 20:18:58 EST (Wed, 09 Mar 2011)
@@ -261,8 +261,8 @@
case ast::op_greater: current->op(op_gt); break;
case ast::op_greater_equal: current->op(op_gte); break;
- case ast::op_and: current->op(op_and); break;
- case ast::op_or: current->op(op_or); break;
+ case ast::op_logical_or: current->op(op_or); break;
+ case ast::op_logical_and: current->op(op_and); break;
default: BOOST_ASSERT(0); return false;
}
return true;
@@ -321,21 +321,71 @@
namespace
{
int precedence[] = {
- 1, // op_equal
- 1, // op_not_equal
- 2, // op_less
- 2, // op_less_equal
- 2, // op_greater
- 2, // op_greater_equal
- 3, // op_and
- 3, // op_or
- 4, // op_plus
- 4, // op_minus
- 5, // op_times
- 5, // op_divide
- 6, // op_positive
- 6, // op_negative
- 6 // op_not
+ // precedence 1
+ 1, // op_comma
+
+ // precedence 2
+ 2, // op_assign
+ 2, // op_plus_assign
+ 2, // op_minus_assign
+ 2, // op_times_assign
+ 2, // op_divide_assign
+ 2, // op_mod_assign
+ 2, // op_bit_and_assign
+ 2, // op_bit_xor_assign
+ 2, // op_bitor_assign
+ 2, // op_shift_left_assign
+ 2, // op_shift_right_assign
+
+ // precedence 3
+ 3, // op_logical_or
+
+ // precedence 4
+ 4, // op_logical_and
+
+ // precedence 5
+ 5, // op_bit_or
+
+ // precedence 6
+ 6, // op_bit_xor
+
+ // precedence 7
+ 7, // op_bit_and
+
+ // precedence 8
+ 8, // op_equal
+ 8, // op_not_equal
+
+ // precedence 9
+ 9, // op_less
+ 9, // op_less_equal
+ 9, // op_greater
+ 9, // op_greater_equal
+
+ // precedence 10
+ 10, // op_shift_left
+ 10, // op_shift_right
+
+ // precedence 11
+ 11, // op_plus
+ 11, // op_minus
+
+ // precedence 12
+ 12, // op_times
+ 12, // op_divide
+ 12, // op_mod
+
+ // precedence 13
+ 13, // op_positive
+ 13, // op_negative
+ 13, // op_pre_incr
+ 13, // op_pre_decr
+ 13, // op_compl
+ 13, // op_not
+
+ // precedence 14
+ 14, // op_post_incr
+ 14 // op_post_decr
};
}
Modified: trunk/libs/spirit/example/qi/compiler_tutorial/conjure/expression_def.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/conjure/expression_def.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure/expression_def.hpp 2011-03-09 20:18:58 EST (Wed, 09 Mar 2011)
@@ -40,14 +40,14 @@
///////////////////////////////////////////////////////////////////////
// Tokens
binary_op.add
+ ("||", ast::op_logical_or)
+ ("&&", ast::op_logical_and)
("==", ast::op_equal)
("!=", ast::op_not_equal)
("<", ast::op_less)
("<=", ast::op_less_equal)
(">", ast::op_greater)
(">=", ast::op_greater_equal)
- ("&&", ast::op_and)
- ("||", ast::op_or)
("+", ast::op_plus)
("-", ast::op_minus)
("*", ast::op_times)
Modified: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression.hpp 2011-03-09 20:18:58 EST (Wed, 09 Mar 2011)
@@ -42,7 +42,8 @@
qi::rule<Iterator, ast::expression(), skipper<Iterator> >
expr, equality_expr, relational_expr,
- logical_expr, additive_expr, multiplicative_expr
+ logical_or_expr, logical_and_expr,
+ additive_expr, multiplicative_expr
;
qi::rule<Iterator, ast::operand(), skipper<Iterator> >
@@ -62,7 +63,8 @@
;
qi::symbols<char, ast::optoken>
- equality_op, relational_op, logical_op,
+ logical_or_op, logical_and_op,
+ equality_op, relational_op,
additive_op, multiplicative_op, unary_op
;
Modified: trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression_def.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression_def.hpp (original)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/mini_c/expression_def.hpp 2011-03-09 20:18:58 EST (Wed, 09 Mar 2011)
@@ -39,6 +39,14 @@
///////////////////////////////////////////////////////////////////////
// Tokens
+ logical_or_op.add
+ ("||", ast::op_or)
+ ;
+
+ logical_and_op.add
+ ("&&", ast::op_and)
+ ;
+
equality_op.add
("==", ast::op_equal)
("!=", ast::op_not_equal)
@@ -51,11 +59,6 @@
(">=", ast::op_greater_equal)
;
- logical_op.add
- ("&&", ast::op_and)
- ("||", ast::op_or)
- ;
-
additive_op.add
("+", ast::op_plus)
("-", ast::op_minus)
@@ -86,7 +89,17 @@
///////////////////////////////////////////////////////////////////////
// Main expression grammar
expr =
- equality_expr.alias()
+ logical_or_expr.alias()
+ ;
+
+ logical_or_expr =
+ logical_and_expr
+ >> *(logical_or_op > logical_and_expr)
+ ;
+
+ logical_and_expr =
+ equality_expr
+ >> *(logical_and_op > equality_expr)
;
equality_expr =
@@ -95,13 +108,8 @@
;
relational_expr =
- logical_expr
- >> *(relational_op > logical_expr)
- ;
-
- logical_expr =
additive_expr
- >> *(logical_op > additive_expr)
+ >> *(relational_op > additive_expr)
;
additive_expr =
@@ -144,9 +152,10 @@
// Debugging and error handling and reporting support.
BOOST_SPIRIT_DEBUG_NODES(
(expr)
+ (logical_or_expr)
+ (logical_and_expr)
(equality_expr)
(relational_expr)
- (logical_expr)
(additive_expr)
(multiplicative_expr)
(unary_expr)
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk