开发者

Why would there be two operands in a EBNF sentence?

开发者 https://www.devze.com 2023-01-18 01:12 出处:网络
Have this EBNF grammar < calculation>-><expr> = <expr> -> <term>(+ | -) <expr>

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

精彩评论

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

关注公众号