WorksheetsCompiler Design Lab Quiz
Total questions: 25
Worksheet time: 13mins
Name
Class
Date
1.
The output of a lexical analyzer is:
a)
a) Parse tree
b)
b) Tokens
c)
c) Intermediate code
d)
d) Machine code
2.
2. Which symbol denotes the empty string in regular expressions?
a)
a) ε
b)
b) ∞
c)
c) ∂
d)
d) λ only
3.
3. Which tool is commonly used to build lexical analyzers?
a)
a) YACC
b)
b) Flex
c)
c) GCC
d)
d) LLVM
4.
4. A token consists of:
a)
a) Only lexeme
b)
b) Only attribute
c)
c) Token name + optional attribute
d)
d) Only pattern
5.
5. Keywords are recognized by the lexer as:
a)
a) Operators
b)
b) Identifiers
c)
c) Reserved words
d)
d) Tokens without type
6.
6. Which of the following can cause lexical errors?
a)
a) Missing parenthesis
b)
b) Illegal character
c)
c) Unmatched else
d)
d) Type mismatch
7.
7. DFA is used in lexical analysis because it:
a)
a) Always reduces code size
b)
b) Guarantees no backtracking
c)
c) Supports recursion
d)
d) Handles syntax rules
8.
8. Which of the following is NOT a valid lexeme for an identifier?
a)
a) _count
b)
b) total2
c)
c) 9value
d)
d) value
9.
9. Syntax analysis checks:
a)
a) Meaning
b)
b) Structure
c)
c) Tokens only
d)
d) Data types
10.
10. LL parsers are:
a)
a) Top-down
b)
b) Bottom-up
c)
c) Operator-precedence
d)
d) Ambiguous
11.
11. Which of the following indicates a shift-reduce conflict?
a)
a) Ambiguous grammar
b)
b) Missing identifiers
c)
c) Invalid lexeme
d)
d) Missing semicolon
12.
12. FIRST sets contain:
a)
a) All terminal symbols that can start strings of a non-terminal
b)
b) All tokens in a program
c)
c) All leaf nodes
d)
d) All operators in an expression
13.
13. FOLLOW sets contain:
a)
a) All terminals that can appear before a non-terminal
b)
b) All terminals that can appear after a non-terminal
c)
c) All variables in the code
d)
d) All possible parse trees
14.
14. The output of the syntax analyzer is usually:
a)
a) Token stream
b)
b) Syntax Tree
c)
c) Machine code
d)
d) Intermediate code
15.
15. An LR parser reads input from:
a)
a) Left to right, leftmost derivation
b)
b) Left to right, rightmost derivation
c)
c) Right to left
d)
d) Random order
16.
16. Left recursion creates problems in:
a)
a) LR parsers
b)
b) LL parsers
c)
c) Both
d)
d) None
17.
17. Semantic analysis checks:
a)
a) Structure
b)
b) Meaning
c)
c) Token patterns
d)
d) Code optimization
18.
18. Type checking is performed during:
a)
a) Lexical analysis
b)
b) Syntax analysis
c)
c) Semantic analysis
d)
d) Code generation
19.
19. Which of the following is a semantic error?
a)
a) Missing brace
b)
b) Using undeclared variable
c)
c) Invalid token
d)
d) Mis-typed keyword
20.
20. An Abstract Syntax Tree (AST) differs from a parse tree because it:
a)
a) Contains more nodes
b)
b) Removes unnecessary syntactic details
c)
c) Represents tokens only
d)
d) Contains machine code
21.
21. Symbol tables are mainly used in:
a)
a) Lexical analysis
b)
b) Semantic analysis
c)
c) Code optimization
d)
d) Linking
22.
22. Which of the following is an example of implicit type conversion?
a)
a) float x = 5;
b)
b) int a = 10.67;
c)
c) Both a and b
d)
d) Neither
23.
23. Detecting "division by zero" at compile time is an example of:
a)
a) Lexical error
b)
b) Syntax error
c)
c) Semantic error
d)
d) Optimization error
24.
24. Attribute grammars help in:
a)
a) Token generation
b)
b) Type checking and semantic rules
c)
c) Register allocation
d)
d) Parsing table generation
25.
25. Which analysis phase is responsible for identifying scope-related errors?
a)
a) Lexical
b)
b) Syntax
c)
c) Semantic
d)
d) Optimization
100 %
