00147 : identifier( c_ident_parser( self.ucn_, self.c_plus_plus_ ) ),
00148 c_strlit_p( c_strlit_parser( self.codeset_ ) ),
00149 c_chlit_p( c_chlit_parser( self.codeset_ ) )
00150 {
00151 using namespace boost::spirit;
00152 static const functor_parser<detail::c_integer_constant_parse_functor<boost::uintmax_t> > c_int_const_p;
00153 static const functor_parser<detail::c_integer_suffix_parse_functor> c_int_suffix_p;
00154
00155 primary_expression =
00156 identifier
00157 | constant
00158 | string_literal
00159 | ( '(' >> expression >> ')' );
00160 expression =
00161 assignment_expression % ',';
00162 constant_expression =
00163 conditional_expression;
00164 conditional_expression =
00165 logical_OR_expression >> *( '\?' >> expression >> ':' >> logical_OR_expression );
00166 assignment_expression =
00167 *( unary_expression >> assignment_operator ) >> conditional_expression;
00168 assignment_operator =
00169 ch_p( '=' ) | "*=" | "/=" | "%=" | "+=" | "?=" | "<<=" | ">>=" | "&=" | "^=" | "|=";
00170 postfix_expression =
00171 primary_expression >>
00172 *(
00173 ( '[' >> expression >> ']' )
00174 | ( '(' >> list_p( assignment_expression, ',' ) >> ')' )
00175 | ( '.' >> identifier )
00176 | ( "->" >> identifier )
00177 | "++"
00178 | "--"
00179 );
00180 unary_expression =
00181 *( str_p( "++" ) || "--" ) >>
00182 (
00183 ( "sizeof" >> unary_expression )
00184 | ( str_p( "sizeof" ) >> '(' >> type_name >> ')' )
00185 | postfix_expression
00186 | ( unary_operator >> cast_expression )
00187 );
00188 unary_operator =
00189 chset<>( "&*~!+-" );
00190 cast_expression =
00191 *( '(' >> type_name >> ')' ) >> unary_expression;
00192 multiplicative_expression =
00193 cast_expression >>
00194 *(
00195 ( '*' >> cast_expression )
00196 | ( '/' >> cast_expression )
00197 | ( '%' >> cast_expression )
00198 );
00199 additive_expression =
00200 multiplicative_expression >>
00201 *(
00202 ( '+' >> multiplicative_expression )
00203 | ( '-' >> multiplicative_expression )
00204 );
00205 shift_expression =
00206 additive_expression >>
00207 *(
00208 ( "<<" >> additive_expression )
00209 | ( ">>" >> additive_expression )
00210 );
00211 relational_expression =
00212 shift_expression >>
00213 *(
00214 ( '<' >> shift_expression )
00215 | ( '>' >> shift_expression )
00216 | ( "<=" >> shift_expression )
00217 | ( ">=" >> shift_expression )
00218 );
00219 equality_expression =
00220 relational_expression >>
00221 *(
00222 ( "==" >> relational_expression )
00223 | ( "!=" >> relational_expression )
00224 );
00225 AND_expression =
00226 equality_expression >> *( '&' >> equality_expression );
00227 exclusive_OR_expression =
00228 AND_expression >> *( '^' >> AND_expression );
00229 inclusive_OR_expression =
00230 exclusive_OR_expression >> *( '|' >> exclusive_OR_expression );
00231 logical_AND_expression =
00232 inclusive_OR_expression >> *( "&&" >> inclusive_OR_expression );
00233 logical_OR_expression =
00234 logical_AND_expression >> *( "||" >> logical_AND_expression );
00235 string_literal =
00236 c_strlit_p
00237 | lexeme_d[ 'L' >> c_strlit_p ];
00238 constant =
00239 floating_constant
00240 | integer_constant
00241 | identifier
00242 | character_constant;
00243 floating_constant =
00244 decimal_floating_constant
00245 | hexadecimal_floating_constant;
00246 decimal_floating_constant =
00247 lexeme_d
00248 [
00249 as_lower_d
00250 [
00251 ( ( *digit_p >> '.' >> +digit_p ) | ( +digit_p >> '.' ) ) >>
00252 'e' >> !chset<>( "+-" ) >> +digit_p >>
00253 !chset<>( "fl" )
00254 ]
00255 ];
00256 hexadecimal_floating_constant =
00257 lexeme_d
00258 [
00259 as_lower_d
00260 [
00261 "0x" >>
00262 ( ( *xdigit_p >> '.' >> +xdigit_p ) | ( +xdigit_p >> '.' ) ) >>
00263 'p' >> !chset<>( "+-" ) >> +digit_p >>
00264 !chset<>( "fl" )
00265 ]
00266 ];
00267 integer_constant =
00268 lexeme_d[ c_int_const_p >> !c_int_suffix_p ];
00269 character_constant =
00270 c_chlit_p
00271 | lexeme_d[ 'L' >> c_chlit_p ];
00272 declaration_specifiers =
00273 +( storage_class_specifier | type_specifier | type_qualifier );
00274 type_name =
00275 specifier_qualifier_list >> !abstract_declarator;
00276 specifier_qualifier_list =
00277 +( type_specifier | type_qualifier );
00278 storage_class_specifier =
00279 str_p( "auto" )
00280 | "register"
00281 | "static"
00282 | "extern"
00283 | "typedef";
00284 type_specifier =
00285 str_p( "void" ) | "char" | "short" | "int" | "long" | "float" | "double"
00286 | "signed" | "unsigned"
00287 | identifier
00288 | struct_or_union_specifier
00289 | enum_specifier;
00290 type_qualifier =
00291 str_p( "const" ) | "volatile" | "restrict";
00292 declarator =
00293 !pointer >> direct_declarator;
00294 direct_declarator =
00295 ( identifier | ( '(' >> declarator >> ')' ) )
00296 >>
00297 *(
00298 ( '[' >> !constant_expression >> ']' )
00299 | ( '(' >> parameter_type_list >> ')' )
00300 | ( '(' >> !( identifier % ',' ) >> ')' )
00301 );
00302 struct_or_union_specifier =
00303 lexeme_d[ ( str_p( "struct" ) | "union" ) >> +space_p >> identifier ]
00304 | ( lexeme_d[ ( str_p( "struct" ) | "union" ) >> +space_p >> !identifier ] >> '{' >> +struct_declaration >> '}' );
00305 struct_declaration =
00306 specifier_qualifier_list >> !list_p( struct_declarator, ',' ) >> ';';
00307
00308
00309
00310 struct_declarator =
00311 ( !declarator >> ':' >> constant_expression )
00312 | declarator;
00313 enum_specifier =
00314 ( lexeme_d[ "enum" >> +space_p >> !identifier ] >> '{' >> list_p( enumerator, ',', ',' ) >> '}' )
00315 | lexeme_d[ "enum" >> +space_p >> identifier ];
00316 enumerator =
00317 identifier >> !( '=' >> constant_expression );
00318 abstract_declarator =
00319 ( !pointer >> direct_abstract_declarator )
00320 | pointer;
00321 pointer =
00322 +( '*' >> *type_qualifier );
00323 parameter_type_list =
00324 parameter_list >> !( ch_p( ',' ) >> "..." );
00325 parameter_list =
00326 parameter_declaration % ',';
00327 parameter_declaration =
00328 ( declaration_specifiers >> declarator )
00329 | ( declaration_specifiers >> !abstract_declarator );
00330 direct_abstract_declarator =
00331 (
00332 !( '(' >> abstract_declarator >> ')' ) >>
00333 +(
00334 ( '[' >> !constant_expression >> ']' )
00335 | ( '(' >> !parameter_type_list >> ')' )
00336 )
00337 )
00338 | ( '(' >> abstract_declarator >> ')' );
00339 }