1
(这一切首先是不是硬件,我知道所有的答案)BNF语法和操作关联性
我有一个简单的BNF语法
<UNIT> ::= (<CLAUSE>) | a | b | c
<ITEM> ::= not <UNIT> | <UNIT>
<CLAUSE> ::= <CLAUSE> and <PHRASE> | <PHRASE>
<PHRASE> ::= <ITEM> | <ITEM> or <PHRASE>
and
运算符是左关联的(左手递归) or
运算符是右结合(这一次,它是右手递归)
鉴于表达c and b or not a and (not b or c)
,为什么是最合适的“和”是在分析树高?
的方式,我看到c **and** b or not a and (not b or c)
左边最高应该是在解析树中更高。
我们的教授提供了这样的回答:
这里是在lispy符号解析树。
(clause (clause (clause (phrase (item (unit 'c'))))
'and'
(phrase (item (unit 'b'))
'or'
(phrase (item 'not'
(unit 'a')))))
**'and'** // is higher in parse tree
(phrase (item (unit '('
(clause (phrase (item 'not’(unit 'b'))
'or'
(phrase (item (unit 'c')))))
')'))))