Role of Lexical and Syntax Analysis Tools MCQs January 8, 2026December 14, 2024 by u930973931_answers 30 min Score: 0 Attempted: 0/30 Subscribe 1. What is the primary function of a lexical analyzer? (A) To generate machine code (B) To optimize loops (C) To break source code into tokens (D) To check semantic errors 2. Which tool is commonly used for lexical analysis? (A) Lex (B) Yacc (C) GCC (D) Make 3. What is a token in lexical analysis? (A) A machine code instruction (B) A symbol table entry (C) A basic unit of source code like keywords, identifiers, and operators (D) A parse tree node 4. Which phase removes comments and white spaces from the source code? (A) Lexical analysis (B) Syntax analysis (C) Semantic analysis (D) Code generation 5. What does a lexical analyzer use to recognize tokens? (A) Context-free grammar (B) Finite automata (C) Symbol tables (D) Intermediate code 6. What is the main output of lexical analysis? (A) Machine code (B) Parse tree (C) Intermediate code (D) Tokens 7. What is the purpose of a syntax analyzer (parser)? (A) To break code into tokens (B) To perform type checking (C) To optimize assembly code (D) To check the source code for grammatical structure 8. Which tool is commonly used for syntax analysis? (A) Yacc (B) Lex (C) Flex (D) GDB 9. What is an Abstract Syntax Tree (AST)? (A) A linear representation of tokens (B) A hierarchical tree structure representing the syntactic structure of the source code (C) Machine code instructions (D) Lexical tokens 10. Which grammar type is typically used for parsing in compilers? (A) Regular grammar (B) Context-sensitive grammar (C) Context-free grammar (D) Unrestricted grammar 11. What is a symbol table? (A) A storage for machine code (B) An error reporting table (C) A parser output (D) A data structure storing information about identifiers, types, and scopes 12. Which of the following is an input to a syntax analyzer? (A) Optimization rules (B) Machine code (C) Symbol table entries (D) Tokens from lexical analysis 13. What type of errors are detected by lexical analysis? (A) Syntax errors (B) Semantic errors (C) Invalid tokens and illegal characters (D) Runtime errors 14. What type of errors are detected by syntax analysis? (A) Lexical errors (B) Syntax errors like missing semicolons or mismatched parentheses (C) Runtime errors (D) Logical errors 15. What does a finite state machine do in lexical analysis? (A) Generates intermediate code (B) Performs optimization (C) Allocates memory (D) Recognizes patterns corresponding to tokens 16. Which parsing method reads input from left to right and constructs a leftmost derivation? (A) LR parsing (B) Bottom-up parsing (C) LL parsing (D) SLR parsing 17. Which parsing method is bottom-up and constructs a rightmost derivation in reverse? (A) LR parsing (B) LL parsing (C) Recursive descent parsing (D) Predictive parsing 18. What is the role of operator-precedence parsing? (A) To handle lexical errors (B) To parse expressions based on operator precedence (C) To generate tokens (D) To allocate registers 19. What is a lookahead in parsing? (A) Tokens already parsed (B) A symbol table entry (C) The next input token used to decide which production to apply (D) The generated machine code 20. Which parser is easy to implement using recursive procedures? (A) Bottom-up parser (B) SLR parser (C) LL parser / Recursive descent parser (D) LR parser 21. What is left recursion in grammar? (A) Grammar where a non-terminal appears on the right side first (B) Grammar with multiple terminals (C) Grammar where a non-terminal appears on the left side first in its production (D) Grammar that cannot generate strings 22. What is left factoring in syntax analysis? (A) Removing syntax errors (B) Optimizing parse tree (C) Refactoring grammar to remove common prefixes for predictive parsing (D) Generating tokens 23. What is the main goal of syntax-directed translation? (A) Generate tokens (B) Check lexical errors (C) Generate intermediate code based on parse tree (D) Optimize machine code 24. Which phase of compiler design handles the declaration of variables and their types? (A) Lexical analysis (B) Semantic analysis (C) Syntax analysis (D) Code generation 25. What is an example of a tool that combines lexical and syntax analysis? (A) Flex + Bison (B) GCC alone (C) Make (D) GDB 26. What is the output of syntax analysis? (A) Abstract syntax tree or parse tree (B) Tokens (C) Machine code (D) Lexemes 27. What is the difference between Lex and Yacc? (A) Lex is for syntax, Yacc is for lexical analysis (B) Both perform code optimization (C) Lex is for lexical analysis, Yacc is for syntax analysis (D) Both generate machine code 28. What is an attribute grammar used for? (A) Representing machine instructions (B) Associating semantic rules with grammar symbols (C) Generating tokens (D) Allocating registers 29. What is predictive parsing? (A) Bottom-up parsing (B) Top-down parsing using lookahead to choose productions (C) Lexical analysis (D) Intermediate code generation 30. Why is error recovery important in lexical and syntax analysis? (A) To skip compilation (B) To allow compilers to continue parsing and report multiple errors (C) To generate machine code (D) To optimize runtime performance