Write the pattern based on regular extensions for real numbers.

39 Views Asked by At

I'm currently working in the following excercise:

Write the pattern based on regular extensions for real numbers.

$$letter → [A-Za-z] $$ $$digit→ [0-9]$$ $$id→letter(letter|digit)$$

I'm defining the pattern as a regular definition:

$$digit \rightarrow [0-9]$$ $$number \rightarrow digit(digit|\epsilon)^{*}$$

I'm not sure about my approximation and how much I'm missing in the definition of the pattern.

I would really appreciate any hint or help and thank you for taking the time to read my question.

1

There are 1 best solutions below

0
On BEST ANSWER

Regular expressions for numbers.
(+|-)digit*.digit** expresses the reals as infinite decimals.
(+|-)digit*.digit* expresses only the reals that are finite decimals.
(+|-)digit*.(digit*|digit**) expresses the reals as infinite and finite decimals.

Context free grammar for numbers.
S -> (+|-)digitD
D -> (digitD|.E)
E -> (digitE|digit)