r17921 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17920‎ | r17921 | r17922 >
Date:07:41, 25 November 2006
Author:river
Status:old
Tags:
Comment:
need to unify related rules in grammar for correct operator precedence
Modified paths:
  • /trunk/willow/src/willow/expr.cc (modified) (history)

Diff [purge]

Index: trunk/willow/src/willow/expr.cc
@@ -87,10 +87,8 @@
8888 const &start(void) const { return top; }
8989
9090 rule<scanner, expr_closure::context_t>
91 - add_expr, atom, mod_expr, eq_expr, neq_expr,
92 - mul_expr, div_expr, sub_expr, land_expr, lor_expr,
93 - lt_expr, gt_expr, le_expr, ge_expr, band_expr,
94 - bxor_expr, bor_expr, lsht_expr, rsht_expr, expr;
 91+ add_expr, atom, eq_expr, mul_expr, land_expr, lor_expr,
 92+ lt_expr, band_expr, bxor_expr, bor_expr, lsht_expr, expr;
9593 rule<scanner> top, identifier;
9694
9795 definition(expression_parser_impl const &self) {
@@ -112,48 +110,37 @@
113111 bxor_expr = bor_expr[bxor_expr.val = arg1]
114112 >> *('^' >> bor_expr[bxor_expr.val ^= arg1]);
115113
116 -bor_expr = lt_expr[bor_expr.val = arg1]
117 - >> *('|' >> lt_expr[bor_expr.val |= arg1]);
 114+bor_expr = eq_expr[bor_expr.val = arg1]
 115+ >> *('|' >> eq_expr[bor_expr.val |= arg1]);
118116
119 -lt_expr = gt_expr[lt_expr.val = arg1]
120 - >> *('<' >> gt_expr[lt_expr.val = lt_expr.val < arg1]);
 117+eq_expr = lt_expr[eq_expr.val = arg1]
 118+ >> *( ("==" >> lt_expr[eq_expr.val = (eq_expr.val == arg1)])
 119+ | ("!=" >> lt_expr[eq_expr.val = (eq_expr.val != arg1)])
 120+ );
121121
122 -gt_expr = le_expr[gt_expr.val = arg1]
123 - >> *('>' >> le_expr[gt_expr.val = gt_expr.val > arg1]);
 122+lt_expr = lsht_expr[lt_expr.val = arg1]
 123+ >> *( ('<' >> lsht_expr[lt_expr.val = (lt_expr.val < arg1)])
 124+ | ('>' >> lsht_expr[lt_expr.val = (lt_expr.val > arg1)])
 125+ | ("<=" >> lsht_expr[lt_expr.val = (lt_expr.val <= arg1)])
 126+ | (">=" >> lsht_expr[lt_expr.val = (lt_expr.val >= arg1)])
 127+ );
124128
125 -le_expr = ge_expr[le_expr.val = arg1]
126 - >> *("<=" >> ge_expr[le_expr.val = le_expr.val <= arg1]);
 129+lsht_expr = add_expr[lsht_expr.val = arg1]
 130+ >> *( ("<<" >> add_expr[lsht_expr.val <<= arg1])
 131+ | (">>" >> add_expr[lsht_expr.val >>= arg1])
 132+ );
127133
128 -ge_expr = neq_expr[ge_expr.val = arg1]
129 - >> *(">=" >> neq_expr[ge_expr.val = ge_expr.val >= arg1]);
 134+add_expr = mul_expr[add_expr.val = arg1]
 135+ >> *( ('+' >> mul_expr[add_expr.val += arg1])
 136+ | ('-' >> mul_expr[add_expr.val -= arg1])
 137+ );
130138
131 -neq_expr = eq_expr[neq_expr.val = arg1]
132 - >> *("!=" >> eq_expr[neq_expr.val = neq_expr.val != arg1]);
 139+mul_expr = atom[mul_expr.val = arg1]
 140+ >> *( ('*' >> atom[mul_expr.val *= arg1])
 141+ | ('%' >> atom[mul_expr.val %= arg1])
 142+ | ('/' >> atom[mul_expr.val /= arg1])
 143+ );
133144
134 -eq_expr = lsht_expr[eq_expr.val = arg1]
135 - >> *("==" >> lsht_expr[eq_expr.val = eq_expr.val == arg1]);
136 -
137 -lsht_expr = rsht_expr[lsht_expr.val = arg1]
138 - >> *("<<" >> rsht_expr[lsht_expr.val <<= arg1]);
139 -
140 -rsht_expr = add_expr[rsht_expr.val = arg1]
141 - >> *(">>" >> add_expr[rsht_expr.val >>= arg1]);
142 -
143 -add_expr = sub_expr[add_expr.val = arg1]
144 - >> *('+' >> sub_expr[add_expr.val += arg1]);
145 -
146 -sub_expr = mul_expr[sub_expr.val = arg1]
147 - >> *('-' >> mul_expr[sub_expr.val -= arg1]);
148 -
149 -mul_expr = mod_expr[mul_expr.val = arg1]
150 - >> *('*' >> mod_expr[mul_expr.val *= arg1]);
151 -
152 -mod_expr = div_expr[mod_expr.val = arg1]
153 - >> *('%' >> div_expr[mod_expr.val %= arg1]);
154 -
155 -div_expr = atom[div_expr.val = arg1]
156 - >> *('/' >> atom[div_expr.val /= arg1]);
157 -
158145 atom = int_p[atom.val = arg1]
159146 | ( '(' >> expr[atom.val = arg1] >> ')' )
160147 | ( '-' >> expr[atom.val = -arg1])
@@ -174,18 +161,10 @@
175162 BOOST_SPIRIT_DEBUG_RULE(bxor_expr);
176163 BOOST_SPIRIT_DEBUG_RULE(bor_expr);
177164 BOOST_SPIRIT_DEBUG_RULE(lt_expr);
178 -BOOST_SPIRIT_DEBUG_RULE(gt_expr);
179 -BOOST_SPIRIT_DEBUG_RULE(le_expr);
180 -BOOST_SPIRIT_DEBUG_RULE(ge_expr);
181 -BOOST_SPIRIT_DEBUG_RULE(neq_expr);
182165 BOOST_SPIRIT_DEBUG_RULE(eq_expr);
183166 BOOST_SPIRIT_DEBUG_RULE(lsht_expr);
184 -BOOST_SPIRIT_DEBUG_RULE(rsht_expr);
185167 BOOST_SPIRIT_DEBUG_RULE(add_expr);
186 -BOOST_SPIRIT_DEBUG_RULE(sub_expr);
187168 BOOST_SPIRIT_DEBUG_RULE(mul_expr);
188 -BOOST_SPIRIT_DEBUG_RULE(mod_expr);
189 -BOOST_SPIRIT_DEBUG_RULE(div_expr);
190169 BOOST_SPIRIT_DEBUG_RULE(atom);
191170
192171 }