[Solved]: regular expression: sum of positive fixed point decimal numbers

Problem Detail: I need help with this exercise. Indicate the regular expression for the following Languages. Explain your expression in one sentence and indicate the basis form of the alphabet. Indicate also every assumption you make. i) Sums of positive fixed-point decimal numbers. The following Strings should exist in the Language: e.g: 3.14 or also 3 + 4.2 + 7 + 1 I have a couple more exersices that are pretty similar but I guess if I get to understand this exercise I could try to do the others faster. I appreciate the help in advance.

Asked By : nubz0r

Answered By : Denis

The idea is to identify the different kind of subexpression you have, and the regular expression should write itself. Here you have a non-empty sum of decimal numbers, so the “outside shape” is $E=N(+N)^*$, where N is an expression for decimal numbers, and “+” is the symbol for addition. Now we just have to detail N: it is a non-empty sequence of digits, with possibly one dot, which does not start with $0$ and does not end with $0$ if there is a dot. For short let write D=0+1+2+…+9 the expression for 1 digit. here the “+” is the one from regular expression, meaning Union, not the addition symbol. Also, the first digit should not be 0, and if there is a point, the last one should not be 0. So let’s P=1+2+…+9 the expression for nonzero digits We are now ready to write N: N=PD*+PD*.D*P+0.D*P It means that either we don’t have a dot, and then we can end with 0, or we have a dot, and then we cannot ened with 0. There is also a special case for numbers like $0.345$. By substituting the letters with their explicit expressions, you get the full explicit one for E.
Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/24226 3.2K people like this

 Download Related Notes/Documents

Leave a Reply