attempt to extend roman numerals example to include hexadecimal numbers failed
Juan Dent <[email protected]> Sat, 10 Oct 2020 13:36:50 +0000
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <BYAPR14MB3077C806CDA252AB6C8816849B090@BYAPR14MB3077.namprd14.prod.outlook.com> |
--===============3423310063273706745==
Content-Language: en-US
Content-Type: multipart/alternative;
boundary="_000_BYAPR14MB3077C806CDA252AB6C8816849B090BYAPR14MB3077namp_"
--_000_BYAPR14MB3077C806CDA252AB6C8816849B090BYAPR14MB3077namp_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
I have added a symbol table for hexadecimal support to the roman numerals e=
xample but it does not parse correctly unless I prepend a + to the hexa sym=
bol table, why? Why is the + unnecessary for the other tables?
Here is the table:
struct hexa_ : qi::symbols<char, unsigned>
{
hexa_()
{
add
("1", 1)
("2", 2)
("3", 3)
("4", 4)
("5", 5)
("6", 6)
("7", 7)
("8", 8)
("9", 9)
("a", 10)
("b",11)
("c" , 12)
("d",13)
("e", 14)
("f" , 15)
;
}
} hexa;
template <typename Iterator>
struct roman : qi::grammar<Iterator, unsigned()>
{
roman() : roman::base_type(start)
{
using qi::eps;
using qi::lit;
using qi::_val;
using qi::_1;
using ascii::char_;
start =3D eps[_val =3D 0] >>
(
+lit('M')[_val +=3D 1000]
|| hundreds[_val +=3D _1]
|| tens[_val +=3D _1]
|| ones[_val +=3D _1]
||
+hexa[_val +=3D _1] // THIS IS THE NEW=
ADDED TABLE
)
;
}
qi::rule<Iterator, unsigned()> start;
};
Also, why is +lit(=91M=92) necessary (why won=92t =91M=92 by itself work?)
Best regards,
Juan
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=3D550986> for Window=
s 10
--_000_BYAPR14MB3077C806CDA252AB6C8816849B090BYAPR14MB3077namp_
Content-Type: text/html; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" xmlns:w=3D"urn:sc=
hemas-microsoft-com:office:word" xmlns:m=3D"http://schemas.microsoft.com/of=
fice/2004/12/omml" xmlns=3D"http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1=
252">
<meta name=3D"Generator" content=3D"Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"#954F72">
<div class=3D"WordSection1">
<p class=3D"MsoNormal">I have added a symbol table for hexadecimal support =
to the roman numerals example but it does not parse correctly unless I prep=
end a + to the hexa symbol table, why? Why is the + unnecessary for the oth=
er tables?</p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Here is the table:</p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> struct hexa_ : qi::symbols<cha=
r, unsigned></p>
<p class=3D"MsoNormal"> {</p>
<p class=3D"MsoNormal"> hexa_()</=
p>
<p class=3D"MsoNormal"> {</p>
<p class=3D"MsoNormal"> &nbs=
p; add</p>
<p class=3D"MsoNormal"> &nbs=
p; ("1", 1)</p>
<p class=3D"MsoNormal"> &nbs=
p; ("2", 2)</p>
<p class=3D"MsoNormal"> &nbs=
p; ("3", 3)</p>
<p class=3D"MsoNormal"> &nbs=
p; ("4", 4)</p>
<p class=3D"MsoNormal"> &nbs=
p; ("5", 5)</p>
<p class=3D"MsoNormal"> &nbs=
p; ("6", 6)</p>
<p class=3D"MsoNormal"> &nbs=
p; ("7", 7)</p>
<p class=3D"MsoNormal"> &nbs=
p; ("8", 8)</p>
<p class=3D"MsoNormal"> &nbs=
p; ("9", 9)</p>
<p class=3D"MsoNormal"> &nb=
sp; ("a", 10)</p>
<p class=3D"MsoNormal"> &nb=
sp; ("b",11)</p>
<p class=3D"MsoNormal"> &nb=
sp; ("c" , 12)</p>
<p class=3D"MsoNormal"> &nb=
sp; ("d",13)</p>
<p class=3D"MsoNormal"> &nb=
sp; ("e", 14)</p>
<p class=3D"MsoNormal"> &nb=
sp; ("f" , 15)</p>
<p class=3D"MsoNormal"> &nbs=
p; ;</p>
<p class=3D"MsoNormal"> }</p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> } hexa;</p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> template <typename Iterator>=
;</p>
<p class=3D"MsoNormal"> struct roman : qi::grammar<Ite=
rator, unsigned()></p>
<p class=3D"MsoNormal"> {</p>
<p class=3D"MsoNormal"> roman() :=
roman::base_type(start)</p>
<p class=3D"MsoNormal"> {</p>
<p class=3D"MsoNormal"> &nbs=
p; using qi::eps;</p>
<p class=3D"MsoNormal"> &nbs=
p; using qi::lit;</p>
<p class=3D"MsoNormal"> &nbs=
p; using qi::_val;</p>
<p class=3D"MsoNormal"> &nbs=
p; using qi::_1;</p>
<p class=3D"MsoNormal"> &nbs=
p; using ascii::char_;</p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> &nb=
sp; start =3D eps[_val =3D 0] >></p>
<p class=3D"MsoNormal"> &nbs=
p; (</p>
<p class=3D"MsoNormal"> &nbs=
p; +lit('M')[_v=
al +=3D 1000]</p>
<p class=3D"MsoNormal"> &nbs=
p; || hundreds[=
_val +=3D _1]</p>
<p class=3D"MsoNormal"> &nbs=
p; || tens[_val=
+=3D _1]</p>
<p class=3D"MsoNormal"> &nbs=
p; || ones[_val=
+=3D _1]</p>
<p class=3D"MsoNormal"> &nbs=
p; || </p>
<p class=3D"MsoNormal" style=3D"margin-left:.5in;text-indent:.5in">+hexa[_v=
al +=3D _1] &nbs=
p; &=
nbsp; &nb=
sp; // THIS IS THE NEW ADDED TABLE</p>
<p class=3D"MsoNormal"> &nbs=
p; )</p>
<p class=3D"MsoNormal"> &nbs=
p; ;</p>
<p class=3D"MsoNormal"> }</p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> qi::rule&=
lt;Iterator, unsigned()> start;</p>
<p class=3D"MsoNormal"> };</p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Also, why is +lit(=91M=92) necessary (why won=92t =
=91M=92 by itself work?)</p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Best regards,</p>
<p class=3D"MsoNormal">Juan </p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Sent from <a href=3D"https://go.microsoft.com/fwlink=
/?LinkId=3D550986">
Mail</a> for Windows 10</p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>
--_000_BYAPR14MB3077C806CDA252AB6C8816849B090BYAPR14MB3077namp_--
--===============3423310063273706745==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
--===============3423310063273706745==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general
--===============3423310063273706745==--