Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following EBNF rules describe the syntax of floating-point constants in PYTH

ID: 3682145 • Letter: T

Question

The following EBNF rules describe the syntax of floating-point constants in PYTHON. Write a single Perl pattern that matches these constants. Simplify your pattern as much as possible.

<floatnumber> -> <pointfloat> | <exponentfloat>

     < pointfloat > -> [ <intpart> ] <fraction> | <inpart> .

     < exponentfloat > -> ( <intpart> | <pointfloat> ) <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

BNF:

expr expr + term | expr - term | term term term * factor | term / factor | factor factor ( expr ) | number number number digit | digit digit 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

EBNF:

expr term { (+ | -) term } term factor { (* | /) factor } factor ( expr ) | number number digit { digit } digit 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

In the EBNF we have used parentheses to group operations within pairs of brackets in the first two rules. This makes parentheses into new metasymbols. An alternative is to write expr term { addop term } term factor { mulop factor } addop + | - mulop * | /

expr term { + term } | term { - term }