Boost Spirit Arc Number Parsing Example

Trying to learn a strong spirit, and the example given in the documents confused me a little.

Referring to this code:

http://www.boost.org/doc/libs/1_46_1/libs/spirit/example/qi/roman.cpp

In particular, this grammar segment:

        start = eps             [_val = 0] >>
            (
                +lit('M')       [_val += 1000]
                ||  hundreds    [_val += _1]
                ||  tens        [_val += _1]
                ||  ones        [_val += _1]
            )

Can someone explain to me why it + burns ("M") and not "burns" ("M"). Because in the end there cannot be zero or more M in comparison with one or several M?

+5
source share
4 answers

+lit('M') *lit('M') . , (), , 1000 _val, one, . , , 1000 _val , . 1000 _val , *lit('M'), , (, ).

, +lit('M') .


. . CCLLIX . , ? 309? , CCCIX? 309, . . , , *lit('M'). , , +lit('M') .

0

a || b Spirit a b, b a, a. , M, ( M ). , *lit('M'), , , NO M? , _val 1000.

+2

( Ms) OR OR. (Zero Ms) OR, Ms aka 1000.

0

Matching an expression A || Bin Qi means either matching only A, or simply Bor A followed by B. Therefore, in your case, it +lit('M') || hundredsmeans +lit('M')either hundredsor +lit('M')followed by hundreds. For this reason, the grammar allows you to match any Roman numbers, not even starting with M.

0
source

All Articles