开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜