Compiler Theory | Set 2 Last Updated : 13 Dec, 2022 Comments Improve Suggest changes Like Article Like Report 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. Comment More infoAdvertise with us Next Article Compiler Theory | Set 2 K kartik Follow Improve Article Tags : Compiler Design MCQ Similar Reads Phases of a Compiler A compiler is a software tool that converts high-level programming code into machine code that a computer can understand and execute. It acts as a bridge between human-readable code and machine-level instructions, enabling efficient program execution. The process of compilation is divided into six p 10 min read Compiler Design Tutorial A compiler is software that translates or converts a program written in a high-level language (Source Language) into a low-level language (Machine Language or Assembly Language). Compiler design is the process of developing a compiler.It involves many stages like lexical analysis, syntax analysis (p 3 min read Source to Source Compiler A compiler is a software program that transforms a program or code written in a high-level programming language into a low-level machine-readable language. When we write a program or code which can be in a high-level language, such as C, C++ or such as the one given below. //Simple Java program publ 6 min read Compiler construction tools The compiler writer can use some specialized tools that help in implementing various phases of a compiler. These tools assist in the creation of an entire compiler or its parts. Some commonly used compiler construction tools include: Parser Generator - It produces syntax analyzers (parsers) from the 4 min read Last Minute Notes - Compiler Design In computer science, compiler design is the study of how to build a compiler, which is a program that translates high-level programming languages (like Python, C++, or Java) into machine code that a computer's hardware can execute directly. The focus is on how the translation happens, ensuring corre 13 min read Like