The following EBNF rules describe the syntax of floating-pointconstants in Pytho
ID: 3614706 • Letter: T
Question
The following EBNF rules describe the syntax of floating-pointconstants in Python. Write a single Perl pattern that matches theseconstants. Simplify your pattern as much as possible.<floatnumner> --> <pointfloat> |<exponentfloat> <pointfloat> --> [<intpart>]<fraction> | <intpart> . <exponentfloat> --> (<intpart> |<pointfloat>) <exponent> <intpart> --> {<digit>}+ <fraction> --> .{<digit>}+ <exponent> --> (e | E) [+ | -]{<digit>}+ <digit> --> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |9
(, ), [, ], {, }, |, and + are metasymbols.
<floatnumner> --> <pointfloat> |<exponentfloat> <pointfloat> --> [<intpart>]<fraction> | <intpart> . <exponentfloat> --> (<intpart> |<pointfloat>) <exponent> <intpart> --> {<digit>}+ <fraction> --> .{<digit>}+ <exponent> --> (e | E) [+ | -]{<digit>}+ <digit> --> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |9
(, ), [, ], {, }, |, and + are metasymbols.
Explanation / Answer
The following EBNF rules describe the syntax of floating-pointconstants in Python. Write a single Perl pattern that matches theseconstants. Simplify your pattern as much as possible.
<floatnumner> --> <pointfloat> |<exponentfloat>
<pointfloat> --> [<intpart>]<fraction> | <intpart> .
<exponentfloat> --> (<intpart> |<pointfloat>) <exponent>
<intpart> --> {<digit>}+
<fraction> --> .{<digit>}+
<exponent> --> (e | E) [+ | -]{<digit>}+
<digit> --> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |9
(, ), [, ], {, }, |, and + are metasymbols.
Solution:
Single pattern perl expression is : d((_?d)?)((.d((_?d)?))?)((E((+|-)?)d((_?d)?))?)