Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Multiple Choice Questions
Q891: In YACC, the %token directive is used to:
- A: Define tokens
- B: Define grammar rules
- C: Write C code
- D: Include libraries
View Answer
A
Q892: In the example YACC file for calculator, which tokens are defined?
- A: NUMBER, LPAREN, RPAREN, PLUS, MINUS, TIMES, DIVIDE
- B: IF, ELSE, WHILE
- C: INT, FLOAT, CHAR
- D: ADD, SUB, MUL, DIV
View Answer
A
Q893: The Flex input file usually includes which header file generated by YACC?
- A: y.tab.h
- B: y.lex.h
- C: yacc.tab.h
- D: parser.h
View Answer
A
Q894: In Flex, the regular expression [0-9]+ matches:
- A: A number
- B: An identifier
- C: A keyword
- D: A symbol
View Answer
A
Q895: The Flex rule {digit}+ {return NUMBER;} means:
- A: Return token NUMBER for digits
- B: Skip digits
- C: Return PLUS token
- D: Return error
View Answer
A
Q896: What is the file generated by YACC that contains parsing tables and parser code?
- A: y.tab.c
- B: lex.yy.c
- C: yacc.c
- D: flex.c
View Answer
A
Q897: What is the file generated by Lex or Flex containing the lexical analyzer?
- A: lex.yy.c
- B: y.tab.c
- C: lexer.c
- D: y.lex.c
View Answer
A
Q898: The process of combining YACC and Lex to build a compiler produces which executable?
- A: expr.exe
- B: yacc.exe
- C: lex.exe
- D: parser.exe
View Answer
A
Q899: The YACC rule "expr : expr PLUS expr ;" describes what kind of grammar production?
- A: Recursive production
- B: Terminal production
- C: Lexical production
- D: Non-recursive production
View Answer
A
Q900: In the YACC input file, C/C++ functions are written in which section?
- A: After second %%
- B: Before first %%
- C: Between first and second %%
- D: Nowhere
View Answer
A