-- Sep 1 In-Class Exercise
integer --> digit digit*
digit --> 0|1|2|3|4|5|6|7|8|9
integer --> (0|1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)*
number --> integer|real
real --> integer exponent|decimal(exponent|empty string)
exponent --> (e|E)(+|-|empty string)integer
1E-4 is a number. Because it has "E" in it, it does not match the regular expression for integer, so it must be a real.
1 matches the first integer.
Because there is no decimal, E-4 must match the exponent regular expression.
E matches e or E.
- matches +, -, or empty string
4 matches integer, so E-4 matches the exponent regular expression.
The string ends, so empty string matches exponent or empty string.
So 1E-4 matches the regular expression for a real, which means it also matches the regular expression for a number.
(
Edited: 2021-09-01)
<pre>
integer --> digit digit*
digit --> 0|1|2|3|4|5|6|7|8|9
integer --> (0|1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)*
number --> integer|real
real --> integer exponent|decimal(exponent|empty string)
exponent --> (e|E)(+|-|empty string)integer
1E-4 is a number. Because it has "E" in it, it does not match the regular expression for integer, so it must be a real.
1 matches the first integer.
Because there is no decimal, E-4 must match the exponent regular expression.
E matches e or E.
- matches +, -, or empty string
4 matches integer, so E-4 matches the exponent regular expression.
The string ends, so empty string matches exponent or empty string.
So 1E-4 matches the regular expression for a real, which means it also matches the regular expression for a number.
</pre>