Parsing
Q21.
Consider the following grammar: stmt\rightarrow if expr then else expr; stmt| \dot{O} expr\rightarrowterm relop term|term term\rightarrow id|number if\rightarrowa|b|c number\rightarrow [0-9] where relop is a relational operate (e.g \lt ,\gt,...), \dot{O} refers to the empty statement, and if ,then, else are terminals. Consider a program P following the above grammar containing ten if terminals. The number of control flows paths in P is ____________. For example the program if e_1 then e_3 else e_3 has 2 controls flow paths e_{1} \rightarrow e_{2} and e_{1} \rightarrow e_{3}.Q22.
Given the grammars \rightarrow T^{*} S \mid TT \rightarrow U+T \mid UU \rightarrow a \mid bWhich of the following statements is wrong?Q23.
C onsider the following parse tree for the expression a#b$c$d#e#f, involving two binary operators $ and #. Which one of the following is correct for the given parse tree?Q24.
Consider the following grammar. S\rightarrow aSB|d B\rightarrow b The number of reduction steps taken by a bottom-up parser while accepting the string aaadbbb is___________.Q28.
Consider the following Syntax Directed Translation Scheme(SDTS),with non-terminals {S, A} and terminals {a, b}. S \rightarrow aA {print 1} S \rightarrow a { print 2} A \rightarrow Sb { print 3} Using the above SDTS, the output printed by a bottom-up parser, for the input aab is:Q29.
A student wrote two context-free grammars G1 and G2 for generating a single C-like array declaration. The dimension of the array is at least one. For example, int a[10][3]; The grammars use D as the start symbol,and use six terminal symbols int ;id[]num. Which of the grammars correctly generate the declaration mentioned above?