📜  门| GATE-CS-2006 |第59章

📅  最后修改于: 2021-06-28 20:58:47             🧑  作者: Mango

考虑以下翻译方案。
S→ER
R→* E {print(“ *”);} R | ε
E→F + E {print(“ +”);} | F
F→(S)| id {print(id.value);}
id是代表整数的令牌,而id.value代表相应的整数值。对于输入“ 2 * 3 + 4”,此转换方案将打印
(A) 2 * 3 + 4
(B) 2 * +3 4
(C) 2 3 * 4 +
(D) 2 3 4 + *答案: (D)
说明:解决问题所需的背景–语法定向翻译和
解析树结构。

Explanation : We are given L-Attributed Syntax Directed Translation as
semantic actions like printf statements are inserted anywhere on the 
RHS of production (R → *E{print(“*”);}R). After constructing the parse tree 
as shown below from the given grammar, we will follow depth first order left 
to right evaluation in order to generate the final output.

解析树:
解析树

Just follow the arrows in the picture (This is actually Depth first 
left to right evaluation ) and the moment we take exit from any child 
which is printf statement in this question, we print that symbol which 
can be a integer value or ‘*’ or ‘+’.

评估 :
语法指导的翻译

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