2080 5

Compiler Design and Construction20805 marksNumerical: SLR parsing string acceptanceLR parsing

Given the following grammar with SLR parsing table, test whether the string "int * (int + int)" will be accepted or rejected.

Given the following grammar with SLR parsing table, test whether the string "int * (int + int)" will be accepted or rejected.

$$ \begin{aligned} E &\to T + E \quad \ldots (1) \ E &\to T \quad \ldots (2) \ T &\to int * T \quad \ldots (3) \ T &\to int \quad \ldots (4) \ T &\to (E) \quad \ldots (5) \end{aligned} $$

$$\begin{array}{|c|c|c|c|c|c|c||c|c|}\hline & \text{ACTION} & & & & & & \text{GOTO} & \ \hline \text{STATE} & \text{int} & * & + & ( & ) & $ & E & T \ \hline 1 & S5 & & & S4 & & & 2 & 3 \ \hline 2 & & & & & & \text{ACC} & & \ \hline 3 & & S6 & & & R2 & R2 & & \ \hline 4 & S5 & & & S4 & & & 7 & 3 \ \hline 5 & & S8 & R4 & & R4 & R4 & & \ \hline 6 & S5 & & & S4 & & & 9 & 3 \ \hline 7 & & & & & S10 & & & \ \hline 8 & S5 & & & S4 & & & & 11 \ \hline 9 & & & & & R1 & R1 & & \ \hline 10 & & & R5 & & R5 & R5 & & \ \hline 11 & & & R3 & & R3 & R3 & & \ \hline \end{array} $$

Grammar: - (1) $E \rightarrow T + E$ - (2) $E \rightarrow T$ - (3) $T \rightarrow int T$ - (4) $T \rightarrow int$ - (5) $T \rightarrow (E)$ Input string: int ( int + int ) $ Parsing table (as given): STATE int + ( ) $ E T --------------------------- 1 S5 S4 2 3 2 ACC 3 S6 R2 R2 4 S5 S4 7 3 5 S8...

Up nextHow do you recognize basic block? Discuss about the factors that affect code generator.