How to add decimals to formal grammar?
To properly produce a formal grammar, you should designate a non-terminal for each different part of a decimal. Here is a sample grammar in Backus–Naur form that also uses square brackets for optional items.

            &lt;decimal&gt; ::= [&lt;sign&gt;]&lt;nonnegative_decimal&gt;
               &lt;sign&gt; ::= - | +
&lt;nonnegative_decimal&gt; ::= &lt;nonnegative_integer&gt;[&lt;fractional_part&gt;]
&lt;nonnegative_integer&gt; ::= &lt;positive_integer&gt; | 0
   &lt;positive_integer&gt; ::= &lt;nonzero_digit&gt;[&lt;digits&gt;]
    &lt;fractional_part&gt; ::= .&lt;digits&gt;
             &lt;digits&gt; ::= &lt;digit&gt;[&lt;digits&gt;]
              &lt;digit&gt; ::= &lt;nonzero_digit&gt; | 0
      &lt;nonzero_digit&gt; ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 


It can be made more compact as the following.

            &lt;decimal&gt; ::= [ - | + ]&lt;nonnegative_decimal&gt;
&lt;nonnegative_decimal&gt; ::= &lt;nonnegative_integer&gt;[.&lt;digits&gt;]
&lt;nonnegative_integer&gt; ::= &lt;nonzero_digit&gt;[&lt;digits&gt;] | 0
             &lt;digits&gt; ::= &lt;digit&gt;[&lt;digits&gt;]
              &lt;digit&gt; ::= &lt;nonzero_digit&gt; | 0
      &lt;nonzero_digit&gt; ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 


Please note that the above grammar defines a decimal as a string that starts with a possible sign followed by an integer, possibly followed by a dot and some digits, where only 0,1,2,3,4,5,6,7,8 and 9 are allowed in an integer or digits and where an integer must not start with 0. Many other kinds of decimals are used, too.