The following questions have been asked in the GATE CS exam.
1. Given the following expression grammar:
E -> E * F | F+E | F
F -> F-F | id which of the following is true? (GATE CS 2000)
(a) * has higher precedence than +
(b) – has higher precedence than *
(c) + and — have same precedence
(d) + has higher precedence than *
Answer(b)
Precedence in grammar is enforced by making sure that a production rule with a higher precedence operator will never produce an expression with an operator with lower precedence.
In the given grammar ‘-’ has higher precedence than ‘*’
2. Consider a program P that consists of two source modules M1 and M2 contained in two different files. If M1 contains a reference to a function defined in M2 the reference will be resolved at (GATE CS 2004)
a) Edit time
b) Compile time
c) Link time
d) Load time
Answer (c)
The compiler transforms source code into the target language. The target language is generally in a binary form known as object code. Typically, an object file can contain three kinds of symbols:
* defined symbols, which allow it to be called by other modules,
* undefined symbols, which call the other modules where these symbols are defined, and
* local symbols used internally within the object file to facilitate relocation.
When a program comprises multiple object files, the linker combines these files into a unified executable program, resolving the symbols as it goes along.
http://en.wikipedia.org/wiki/Compiler
http://en.wikipedia.org/wiki/Linker_%28computing%29
3. Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar? (GATE CS 2003)
(a) Removing left recursion alone
(b) Factoring the grammar alone
(c) Removing left recursion and factoring the grammar
(d) None of the above
Answer(d)
Removing left recursion and factoring the grammar does not suffice to convert an arbitrary CFG to LL(1) grammar.
http://pages.cpsc.ucalgary.ca/~robin/class/411/LL1.3.html
4. Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states. The relationship between n1 and n2 is (GATE CS 2003)
(a) n1 is necessarily less than n2
(b) n1 is necessarily equal to n2
(c) n1 is necessarily greater than n2
(d) none of the above
Answer (b)
http://parasol.tamu.edu/people/rwerger/Courses/434/lec10.pdf
http://dragonbook.stanford.edu/lecture-notes/Stanford-CS143/11-LALR-Parsing.pdf
Please see GATE Corner for all previous year papers/solutions/explanations, syllabus, important dates, notes, etc.
Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above.