📜  门|门 IT 2005 |第 87 题

📅  最后修改于: 2021-09-26 04:07:46             🧑  作者: Mango

Q 83_B 部分

考虑上下文无关文法

E → E + E
E → (E * E)
E → id

其中 E 为起始符号,终结符集为 {id, (,+,),*},非终结符集为 {E}。
对于终端字符串id + id + id + id,可能有多少个解析树?

(一) 5
(乙) 4
(三) 3
(四) 2答案:(一)
说明:解决问题所需的背景知识 – 解析树构建。

Explanation : In order to produce the yield id + id + id + id , 
we only required 3 productions of type E → E + E  as 3 ‘+’ are 
required in the final string. This can be done in 5 ways as shown 
in the picture given below:

解析树1

此解释由Pranjul Ahuja提供这个问题的测验