GATE Computer ScienceHardGATE CS
For the statement a = b * (−c) + b * (−c), common subexpressions are shared (so −c and b * (−c) are each computed once) and the code is stored in indirect-triples form: a triple table plus an instruction list of pointers into it. Counting every row of both tables, how many entries are stored?
- A. 8
- B. 10
- C. 12
- D. 6
Correct answer: A. 8
With sharing the operations are (0) uminus c, (1) * b, (0), (2) + (1), (1), and (3) = a, (2): 4 triples. The instruction list holds one pointer per triple, 4 more: 4 + 4 = 8. Without sharing there would be 6 triples and 6 pointers, 12 rows.
More Compiler Design questions
- Grammar: E → E + T | T; T → T F | F; F → ( E ) | id. An SLR(1) parser parses id + id ( id + id ) id. Counting every shift, every reduce…
- A table-driven predictive parser for E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id parses ( id + id ) id + id. One…
- An array A[2..6][−1..4][0..5] of 4-byte elements has base address 1000. The address of A[4][2][3] is computed in row-major order and…
- A scanner discards comments, which begin with / and end at the FIRST / (comments do not nest). Identifiers are letters, and and / are…
- A C lexer uses maximal munch. How many tokens does it produce for the line int x = a++ + --b >= 3 ? 1 : 0; (whitespace is ignored)?
- For the grammar S → A B c; A → a A | ε; B → b B | ε, how many terminals are in FIRST(S)?