Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65088 - trunk/libs/spirit/example/qi/mini_c
From: hartmut.kaiser_at_[hidden]
Date: 2010-08-28 11:50:44


Author: hkaiser
Date: 2010-08-28 11:50:42 EDT (Sat, 28 Aug 2010)
New Revision: 65088
URL: http://svn.boost.org/trac/boost/changeset/65088

Log:
Spirit: fixing mini_c example for VS2010 and fixing a operator precedence bug there
Text files modified:
   trunk/libs/spirit/example/qi/mini_c/mini_cb.hpp | 24 ++++++++++++------------
   trunk/libs/spirit/example/qi/mini_c/mini_cc.hpp | 22 ++++++++++++----------
   trunk/libs/spirit/example/qi/mini_c/mini_cd.hpp | 12 +++++++-----
   3 files changed, 31 insertions(+), 27 deletions(-)

Modified: trunk/libs/spirit/example/qi/mini_c/mini_cb.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_c/mini_cb.hpp (original)
+++ trunk/libs/spirit/example/qi/mini_c/mini_cb.hpp 2010-08-28 11:50:42 EDT (Sat, 28 Aug 2010)
@@ -28,25 +28,25 @@
         ;
 
     equality_expr =
- relational_expr
- >> *( ("==" > relational_expr [op(op_eq)])
- | ("!=" > relational_expr [op(op_neq)])
+ logical_expr
+ >> *( ("==" > logical_expr [op(op_eq)])
+ | ("!=" > logical_expr [op(op_neq)])
             )
         ;
 
- relational_expr =
- logical_expr
- >> *( ("<=" > logical_expr [op(op_lte)])
- | ('<' > logical_expr [op(op_lt)])
- | (">=" > logical_expr [op(op_gte)])
- | ('>' > logical_expr [op(op_gt)])
+ logical_expr =
+ relational_expr
+ >> *( ("&&" > relational_expr [op(op_and)])
+ | ("||" > relational_expr [op(op_or)])
             )
         ;
 
- logical_expr =
+ relational_expr =
         additive_expr
- >> *( ("&&" > additive_expr [op(op_and)])
- | ("||" > additive_expr [op(op_or)])
+ >> *( ("<=" > additive_expr [op(op_lte)])
+ | ('<' > additive_expr [op(op_lt)])
+ | (">=" > additive_expr [op(op_gte)])
+ | ('>' > additive_expr [op(op_gt)])
             )
         ;
 

Modified: trunk/libs/spirit/example/qi/mini_c/mini_cc.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_c/mini_cc.hpp (original)
+++ trunk/libs/spirit/example/qi/mini_c/mini_cc.hpp 2010-08-28 11:50:42 EDT (Sat, 28 Aug 2010)
@@ -23,6 +23,8 @@
   , add_var(var_adder(vars, nvars))
   , op(code)
 {
+ namespace phx = boost::phoenix;
+
     identifier %=
         raw[lexeme[alpha >> *(alnum | '_')]]
         ;
@@ -42,7 +44,7 @@
             ]
> !var_ref // make sure the variable isn't redeclared
> identifier [add_var(_1)]
- > (';' | '=' > assignment_rhs(ref(nvars)-1))
+ > (';' | '=' > assignment_rhs(phx::ref(nvars)-1))
         ;
 
     assignment =
@@ -61,12 +63,12 @@
>> '('
> expr [
                                 op(op_jump_if, 0), // we shall fill this (0) in later
- _a = size(ref(code))-1 // mark its position
+ _a = size(phx::ref(code))-1 // mark its position
                             ]
> ')'
> statement_ [
                                 // now we know where to jump to (after the if branch)
- ref(code)[_a] = size(ref(code))
+ phx::ref(code)[_a] = size(phx::ref(code))
                             ]
>>
            -(
@@ -74,31 +76,31 @@
                     "else"
>> !(alnum | '_') // make sure we have whole words
                 ] [
- ref(code)[_a] += 2, // adjust for the "else" jump
+ phx::ref(code)[_a] += 2, // adjust for the "else" jump
                                 op(op_jump, 0), // we shall fill this (0) in later
- _a = size(ref(code))-1 // mark its position
+ _a = size(phx::ref(code))-1 // mark its position
                             ]
> statement_ [
                                 // now we know where to jump to (after the else branch)
- ref(code)[_a] = size(ref(code))
+ phx::ref(code)[_a] = size(phx::ref(code))
                             ]
             )
         ;
 
     while_statement =
             lit("while") [
- _a = size(ref(code)) // mark our position
+ _a = size(phx::ref(code)) // mark our position
                             ]
>> '('
> expr [
                                 op(op_jump_if, 0), // we shall fill this (0) in later
- _b = size(ref(code))-1 // mark its position
+ _b = size(phx::ref(code))-1 // mark its position
                             ]
> ')'
> statement_ [
                                 op(op_jump, _a), // loop back
                                 // now we know where to jump to (to exit the loop)
- ref(code)[_b] = size(ref(code))
+ phx::ref(code)[_b] = size(phx::ref(code))
                             ]
         ;
 
@@ -112,7 +114,7 @@
>> !(alnum | '_') // make sure we have whole words
             ]
>> -(
- eps(ref(has_return)) > expr [op(op_return)]
+ eps(phx::ref(has_return)) > expr [op(op_return)]
             )
> ';'
         ;

Modified: trunk/libs/spirit/example/qi/mini_c/mini_cd.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_c/mini_cd.hpp (original)
+++ trunk/libs/spirit/example/qi/mini_c/mini_cd.hpp 2010-08-28 11:50:42 EDT (Sat, 28 Aug 2010)
@@ -21,6 +21,8 @@
   , state_reset(function_state_reset(code, statement_.vars, statement_.nvars))
   , op(code)
 {
+ namespace phx = boost::phoenix;
+
     bool& has_return = statement_.has_return;
     int& nvars = statement_.nvars;
     boost::phoenix::function<var_adder>& add_var = statement_.add_var;
@@ -31,8 +33,8 @@
 
     function =
             (
- lit("void") [ref(has_return) = false]
- | lit("int") [ref(has_return) = true]
+ lit("void") [phx::ref(has_return) = false]
+ | lit("int") [phx::ref(has_return) = true]
             )
>> !functions // no duplicate functions!
>> identifier [_a = _1]
@@ -43,11 +45,11 @@
             )
> ')'
> lit('{') [
- _b = size(ref(code)),
+ _b = size(phx::ref(code)),
                                                     add_function(
                                                         _a // function name
- , ref(nvars) // arity
- , size(ref(code)) // address
+ , phx::ref(nvars) // arity
+ , size(phx::ref(code)) // address
                                                     ),
                                                     op(op_stk_adj, 0) // adjust this later
                                                 ]


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