Yacc and Bison are tools used in compiler design. What is their main function?
Think about which part of the compiler deals with grammar rules and structure.
Yacc and Bison generate parsers that analyze the grammatical structure of input based on a defined grammar. Lexical analyzers are generated by tools like Lex.
After processing a grammar specification, what kind of file does Yacc/Bison generate?
Consider what Yacc/Bison outputs that you can compile further.
Yacc/Bison generates a C source file that contains the parser code. This file is then compiled with a C compiler to create an executable.
Consider a grammar with ambiguous rules. How does Yacc/Bison handle this situation?
Think about how parser generators inform users about grammar problems.
Yacc/Bison detects ambiguous grammar by reporting conflicts like shift/reduce or reduce/reduce. It still generates a parser but warns the user to resolve these conflicts.
Both Yacc and Bison are parser generators. What is a key difference between them?
Consider licensing and availability differences.
Bison is a free and open-source replacement for Yacc, which was originally proprietary. Bison also adds some features and improvements over Yacc.
In a Bison grammar file, what does the %token directive specify?
Think about how the parser knows what tokens to expect from the lexer.
The %token directive declares token names that the lexer returns. This lets Bison know what tokens it should expect when parsing.
