MCQs Answers

Tools for Syntax Analysis (e.g., YACC, Bison) MCQs

1. What does YACC stand for?

A) Yet Another Compiler Compiler
B) Yet Another Context-free Compiler
C) Your Automated Compiler Compiler
D) Your Advanced Compiler Creation

Answer: A) Yet Another Compiler Compiler


2. Which of the following tools is used for generating parsers based on context-free grammars?

A) YACC
B) Lex
C) GCC
D) Git

Answer: A) YACC


3. Which of the following is a primary use of YACC and Bison?

A) Generating tokenizers
B) Generating parsers from a formal grammar
C) Performing syntax analysis
D) Compiling source code into machine code

Answer: B) Generating parsers from a formal grammar


4. Which of the following tools is a free software replacement for YACC?

A) Bison
B) Lex
C) Flex
D) GCC

Answer: A) Bison


5. Which of the following is a feature of the Bison tool?

A) It is only compatible with C programming language.
B) It generates parsers for deterministic context-free grammars (DCFG).
C) It is used for lexical analysis.
D) It is used for memory management in programming languages.

Answer: B) It generates parsers for deterministic context-free grammars (DCFG).


6. In YACC/Bison, the syntax of a grammar rule is defined using:

A) Regular expressions
B) Backus-Naur Form (BNF)
C) Object-Oriented Programming (OOP)
D) Regular grammar

Answer: B) Backus-Naur Form (BNF)


7. What is the output of a YACC/Bison parser?

A) A lexer
B) An Abstract Syntax Tree (AST)
C) Machine code
D) A syntax error report

Answer: B) An Abstract Syntax Tree (AST)


8. Which of the following is the role of the yacc command in Unix-based systems?

A) Generate a lexical analyzer
B) Generate machine code
C) Generate a parser from grammar specifications
D) Compile source code into object code

Answer: C) Generate a parser from grammar specifications


9. What is the purpose of the flex tool, often used in combination with YACC/Bison?

A) To optimize the performance of a parser
B) To generate a lexer from regular expressions
C) To handle memory management in parsers
D) To analyze syntax errors in grammar rules

Answer: B) To generate a lexer from regular expressions


10. Which of the following programming languages are commonly used with YACC and Bison?

A) Python and Java
B) C and C++
C) JavaScript and PHP
D) Ruby and Perl

Answer: B) C and C++


11. What does the yyparse() function do in YACC/Bison?

A) It initializes the parser.
B) It analyzes the input to ensure it matches the grammar rules.
C) It creates a lexical analyzer.
D) It compiles the source code into machine code.

Answer: B) It analyzes the input to ensure it matches the grammar rules.


12. Which of the following is a key difference between YACC and Bison?

A) Bison is the modern, open-source version of YACC.
B) YACC supports more advanced grammar types than Bison.
C) YACC is written in C++, while Bison is written in C.
D) There is no difference; they are the same tool.

Answer: A) Bison is the modern, open-source version of YACC.


13. In YACC/Bison, the action code (e.g., C code) is written:

A) Between the %{ and %} symbols
B) Between the << and >> symbols
C) In the %% section
D) In the grammar rule section

Answer: A) Between the %{ and %} symbols


14. Which of the following is true about error handling in YACC/Bison?

A) YACC/Bison automatically handles errors without the need for additional code.
B) YACC/Bison requires explicit error-handling rules to detect and report syntax errors.
C) YACC/Bison cannot detect errors in the grammar rules.
D) Error handling in YACC/Bison is only available for lexical analysis, not syntax analysis.

Answer: B) YACC/Bison requires explicit error-handling rules to detect and report syntax errors.


15. Which of the following is used in Bison to define precedence and associativity for operators?

A) %prec directive
B) %left and %right directives
C) %type directive
D) %token directive

Answer: B) %left and %right directives

Exit mobile version