Compiler design is a field of computer science that focuses on the development of software tools known as compilers. A compiler is a program that translates source code written in a high-level programming language into a low-level language (such as machine code) that can be executed by a computer. It involves various stages, including lexical analysis, syntax analysis, semantic analysis, code generation, and code optimization. MCQs on compiler design cover topics such as lexical analysis, parsing techniques (such as LL and LR parsing), symbol table management, intermediate code generation, optimization techniques, and error handling. These MCQs assess knowledge of compiler architecture, compiler phases, compiler construction techniques, and compiler optimization strategies. Find out how much you know about this compiler and its uses by solving the given Compiler Design MCQs.
Phase 3 of a typical 6-phase compiler is _____.
The correct answer is Semantic Analysis.
Key Points
Additional Information
A token is a sequence of characters that can be treated as a single logical entity. C tokens are the basic building blocks in C language which are constructed together to write a C program.
● Each and every smallest individual unit in a C program are known as C tokens.
● C tokens are of six types. They are,
1.Keywords (eg: int, while),
2.Identifiers (eg: main, total, MAX),
3.Constants (eg: 10, 20, 1.02e+2),
4.Strings (eg: “total”, “hello”, "Testbook"),
5.Special symbols (eg: (), <>),
#define is C Preprocessor, which is not part of the compiler but is a separate step in the compilation process. So it is not a token.
India’s #1 Learning Platform Start Complete Exam Preparation Daily Live MasterClasses Practice Question Bank Mock Tests & Quizzes Trusted by 6.1 Crore+ StudentsLIST - I | LIST - II |
A. P vs NP Problem | I. Undecidable Problems |
B. Chomsky Hierarchy | II. Polynomial-Time Verification |
C. Rice's Theorem | III. Classes of Formal Grammars |
D. Savitch's Theorem | IV. Space Complexity |
The correct answer is A - II, B - III, C - I, D - IV
Key Points
Therefore, the correct matching is: A - II, B - III, C - I, D - IV.
India’s #1 Learning Platform Start Complete Exam Preparation Daily Live MasterClasses Practice Question Bank Mock Tests & Quizzes Trusted by 6.1 Crore+ StudentsThe number of tokens in the following line: int main()
int a = 1, b = 2;
printf("Sum is:%d",a+b);
return 0;
>
The correct answer is 27
Explanation:
Total number of tokens = 4 + 1 + 9 + 9 + 3 + 1 = 27 tokens
India’s #1 Learning Platform Start Complete Exam Preparation Daily Live MasterClasses Practice Question Bank Mock Tests & Quizzes Trusted by 6.1 Crore+ StudentsArrange the following stages of the lexical analysis process in the correct order: A. Token classification
B. Tokenization
C. Input preprocessing
D. Output generation
E. Token validation
The correct answer is C, B, A, E, D
Key Points
Programs written in high-level languages are translated into assembly language or machine language by a compiler. Every CPU has its unique machine language.
Share on Whatsapp
India’s #1 Learning Platform Start Complete Exam Preparation Daily Live MasterClasses Practice Question Bank Mock Tests & Quizzes Trusted by 6.1 Crore+ StudentsConcept:
A token is a sequence of characters that can be treated as a unit in the grammar of the programming languages.
Lexical Analysis is the first phase of compiler also known as scanner. It converts the High level input program into a sequence of Tokens.
Explanation
Analysing the given code for tokens, we get
Counting all the boxes, the total number of tokens comes out to be 26.
Important Point:
For example, printf(“Testbook has tests for GATE, ISRO, etc.”); has 5 tokens.
printf, (, “Testbook has tests for GATE, ISRO, etc.”, ), and ;
Share on Whatsapp
India’s #1 Learning Platform Start Complete Exam Preparation Daily Live MasterClasses Practice Question Bank Mock Tests & Quizzes Trusted by 6.1 Crore+ Students(P) | Lexical analysis | (i) | Leftmost derivation |
(Q) | Top down parsing | (ii) | Type checking |
(R) | Semantic analysis | (iii) | Regular expressions |
(S) | Runtime environments | (iv) | Activation records |
Lexical analysis: Lexical analysis is the first phase of a compiler. It takes the modified source code from language pre-processors that are written in the form of sentences. Lexical analyser breaks these syntaxes into a series of tokens. Lexical analysis uses regular expression to recognize identifiers.
Top down parsing: Top down parsing technique parses the input by starts constructing a parse tree from the root node moving down to the leaf nodes. Top down parser uses the left most derivation to generate the string.
Semantic analysis: Semantic analysis is the task of ensuring that declarations and statements of a program are semantically correct. For this, it uses type casting.
Run time environments: Run time environment is a state of the target machine, which may include software libraries, environment variables etc. to provide services to the processes running in the system. Activation records of a function are loaded into stack at runtime.