tags:

views:

25

answers:

1

Have this EBNF grammar

< calculation>  ->   <expr> =
         <expr> -> <term>  (+ | -) <expr>
                         |   <term>
         <term> -> <factor>  (*  |  /) <term>
                         |   <factor>
         <factor> -> ( <expr> )
                         |   <value>
            <value>     ->   [ <sign>  ]  <unsigned>  [ .  <unsigned>  ]
            <unsigned>  ->   <digit>  { <digit> }
            <digit>     ->  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
            <sign>      ->  + | -

WHy would you have the option to enter something like this in 4*+3.5= ? Would this sentence even be in this grammar? How do you figure it out if it is?

+1  A: 

It's in the grammar. The + is a unary operator. Consider 4*-3.5, 4 times -3.5.

Your parser will figure it out.

EJP