lundi 21 mai 2018

Parsing hexidecimal and binary nums

I'm using boost spirit for parsing some complicated expression such as "0b111 << (0x111 + 1) * ....", the problem is parsing hex and bin values, syntax analyzer found 0 before 'b' or 'x' first and takes it as num, but i want to take "0b1111". Tried to do that, but there is no effect.

            ............
            factor =
            num                                  [ qi::_val =    qi::_1  ]
            |   '('  >> expr                     [ qi::_val =    qi::_1  ] >>')'
            |   '-'  >> num                      [ qi::_val =   -qi::_1  ]
            |   '+'  >> num                      [ qi::_val =    qi::_1  ]
            |   '~'  >> num                      [ qi::_val =   ~qi::_1  ]
            ;


            num =
            qi::uint_                           [ qi::_val =    qi::_1  ]
            |   hexOrBinNum                     [  qi::_val =   qi::_1  ]
            ;


            hexOrBinNum =
            "0x"    >>    qi::int_parser<int, 16>{}        [ qi::_val =    qi::_1  ]
            |   "0b" >>    qi::int_parser<int, 2>{}         [ qi::_val =    qi::_1  ]
            ;

Aucun commentaire:

Enregistrer un commentaire