Compiler Design Tools and Techniques MCQs December 19, 2025December 14, 2024 by u930973931_answers 30 min Score: 0 Attempted: 0/30 Subscribe 1. What is the main purpose of a compiler? (A) To execute programs directly (B) To manage operating system resources (C) To store data in memory (D) To translate source code into machine code 2. Which phase of a compiler checks the syntax of the source code? (A) Syntax analysis (B) Lexical analysis (C) Semantic analysis (D) Code generation 3. What is the function of a lexical analyzer? (A) To generate intermediate code (B) To optimize machine code (C) To break source code into tokens (D) To allocate memory 4. Which tool is commonly used for lexical analysis? (A) Yacc (B) Lex (C) GCC (D) GDB 5. Which tool is commonly used for syntax analysis (parsing)? (A) Lex (B) Yacc (C) Flex (D) Make 6. What does a symbol table store? (A) Source code (B) Tokens only (C) Machine code instructions (D) Information about identifiers and their attributes 7. Which phase of a compiler performs type checking? (A) Lexical analysis (B) Semantic analysis (C) Syntax analysis (D) Code generation 8. Which form of grammar is commonly used for parsing in compilers? (A) Context-free grammar (B) Context-sensitive grammar (C) Regular grammar (D) Unrestricted grammar 9. What is an intermediate code in a compiler? (A) Machine code (B) Tokens (C) Source code (D) A language-independent code generated after semantic analysis 10. Which of the following is a type of parser used in compiler design? (A) LL parser (B) LR parser (C) All of the above (D) Recursive descent parser 11. What is the main goal of code optimization? (A) Reduce compilation time (B) Identify syntax errors (C) Improve the efficiency of generated code (D) Allocate registers 12. Which data structure is often used in syntax-directed translation? (A) Parse tree (B) Queue (C) Linked list (D) Stack 13. What is the function of a symbol table in semantic analysis? (A) Generate tokens (B) Store variable types, scopes, and attributes (C) Translate code to assembly (D) Optimize loops 14. What is the output of lexical analysis? (A) Machine code (B) Abstract syntax tree (C) Tokens (D) Source code 15. Which of the following is NOT a phase of a compiler? (A) Lexical analysis (B) Semantic analysis (C) Linking (D) Code generation 16. What is backpatching in compiler design? (A) Filling addresses of forward jumps after code generation (B) A code optimization technique (C) Parsing errors detection (D) Memory allocation 17. Which phase removes comments and white spaces from source code? (A) Semantic analysis (B) Syntax analysis (C) Lexical analysis (D) Code generation 18. What is a finite automaton used for in compiler design? (A) Syntax analysis (B) Lexical analysis for recognizing tokens (C) Semantic checking (D) Code generation 19. Which type of grammar is easiest to parse using top-down parsing techniques? (A) Left-recursive grammar (B) Right-recursive grammar (C) Unrestricted grammar (D) LL(1) grammar 20. What does a parser do? (A) Checks semantic errors only (B) Converts tokens into intermediate representation (C) Generates machine code (D) Optimizes source code 21. What is a first set in parsing? (A) Set of all error messages (B) Set of all symbols in the grammar (C) Set of all keywords (D) Set of terminals that begin the derivations of a non-terminal 22. What is peephole optimization? (A) Optimizing small sequences of instructions (B) Optimizing loops (C) Optimizing recursive functions (D) Optimizing lexical analysis 23. Which technique is used to handle ambiguity in grammar? (A) Left factoring (B) Operator precedence parsing (C) All of the above (D) Grammar rewriting 24. Which of the following is a target of semantic analysis? (A) Syntax tree generation (B) Lexical tokenization (C) Code generation (D) Type checking and scope resolution 25. What is the purpose of intermediate code generation? (A) Reduce compiler size (B) Detect syntax errors (C) Serve as a bridge between high-level code and machine code (D) Optimize memory usage only 26. Which of the following is an example of intermediate code? (A) Three-address code (B) Machine code (C) Source code (D) Object code 27. Which parsing method uses a stack to predict production rules? (A) Top-down parsing (B) Bottom-up parsing (C) Both A and B (D) None of the above 28. Which compiler phase deals with register allocation? (A) Code generation (B) Syntax analysis (C) Lexical analysis (D) Semantic analysis 29. Which type of errors are detected during lexical analysis? (A) Syntax errors (B) Semantic errors (C) Invalid tokens and illegal characters (D) Runtime errors 30. Which tool converts a formal grammar into a parser? (A) Lex (B) Make (C) GCC (D) Yacc