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?
+lit('M') *lit('M') . , (), , 1000 _val, one, . , , 1000 _val , . 1000 _val , *lit('M'), , (, ).
+lit('M')
*lit('M')
1000
_val
one
, +lit('M') .
. . CCLLIX . , ? 309? , CCCIX? 309, . . , , *lit('M'). , , +lit('M') .
CCLLIX
309
CCCIX
a || b Spirit a b, b a, a. , M, ( M ). , *lit('M'), , , NO M? , _val 1000.
a || b
a
b
M
( Ms) OR OR. (Zero Ms) OR, Ms aka 1000.
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.
A || B
A
B
A followed by B
+lit('M') || hundreds
hundreds
+lit('M')followed by hundreds