Why would there be two operands in a EBNF sentence?
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?
It's in the grammar. The + is a unary operator. Consider 4*-3.5, 4 times -3.5.
Your parser will figure it out.
精彩评论