Question: In C++, a programmer can declare several variables with the syntax: int col, row; This declaration can be described with the following grammar with start

In C++, a programmer can declare several variables with the syntax: int col, row; This declaration can be described with the following grammar with start symbol 'decl' and terminals: int, float, id. \[ \begin{array}{l} \text { decl } ightarrow \text { type id_list ; } \\ \text { type } ightarrow \text { int I float } \\ \text { id_list } ightarrow \text { id_list, id I id } \end{array} \] (a) Given the following attribute grammar for the above grammar. (i) Discuss each of the semantic rules for the associated syntax rules. (ii) Decide whether the attributes are synthesized or inherited. Explain. [2+1=3marks] (b) Why is the above grammar only applicable for bottom-up parsing but not suitable for top-down parsing? Explain. [2 marks] (c) Modify the original grammar so that it can be utilized for top-down parsing. Show the steps. [5 marks]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
