(First of all this is not HW, I have all the answers)
I have a simple BNF grammar
<UNIT> ::= ( <CLAUSE> ) | a | b | c
<ITEM> ::= not <UNIT> | <UNIT>
<CLAUSE> ::= <CLAUSE> and <PHRASE> | <PHRASE>
<PHRASE> ::= <ITEM> | <ITEM> or <PHRASE>
and
operator is Left associative (left-hand recursive )
or
operator is Right associative (this time, it is right-hand recursive )
Given expression c and b or not a and ( not b or c )
, why is most right "and" is higher in the parse tree ?
The way, I see c **and** b or not a and ( not b or c )
left most should be higher in the parse tree.
Our professor provided this answer:
Here is the parse tree in a lispy notation.
(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')))))
')' ))))