YACC (Yet Another Compiler Compiler) is a computer program developed for the Unix operating system. It provides a tool to generate a parser for a given grammar. It is specifically designed to compile a LALR (1) grammar. YACC generates the source code for the syntactic analyzer of a language defined by a LALR (1) grammar. The input to YACC consists of the rules or grammar, and its output is a C program.

Compiler design is a complex yet fascinating field at the intersection of computer science and software engineering. At its core lies the intricate process of transforming human-readable code into machine-executable instructions. Among the multitude of tools and techniques employed in compiler construction, Yet Another Compiler Compiler (YACC) stands out as a powerful parsing tool that simplifies the development of parsers for programming languages.
In this article, we will dive into the world of YACC.
What is YACC?
YACC serves as a powerful grammar parser and generator. In essence, it functions as a tool that takes in a grammar specification and transforms it into executable code capable of meticulously structuring input tokens into a coherent syntactic tree, aligning seamlessly with the prescribed grammar rules.
YACC was developed by Stephen C. Johnson in the 1970s. Initially, the YACC was written in the B programming language and was soon rewritten in C. It was originally designed to be complemented by Lex.
In addition to that, YACC was also rewritten in OCaml, Ratfor, ML, ADA, Pascal, Java < Python, Ruby and Go.

The input of YACC in compiler design is the rule or grammar, and the output is a C program.
Parts of a YACC Program in Compiler Design
The parts of YACC program are divided into three sections:
/* definitions */
....
%%
/* rules */
....
%%
/* auxiliary routines */
....
Definitions: these include the header files and any token information used in the syntax. These are located at the top of the input file. Here, the tokens are defined using a modulus sign. In the YACC, numbers are automatically assigned for tokens.
Let us see some examples:
%token ID
{% #include <stdio.h> %}
Rules: The rules are defined between %% and %%. These rules define the actions for when the token is scanned and are executed when a token matches the grammar.
Auxiliary Routines: Auxiliary routines contain the function required in the rules section. This Auxiliary section includes the main() function, where the yyparse() function is always called.
This yyparse() function plays the role of reading the token, performing actions and then returning to the main() after the execution or in the case of an error.
0 is returned after successful parsing and 1 is returned after an unsuccessful parsing.
The YACC is responsible for converting these sections into subroutines which will examine the inputs. This process is made to work by a call to a low-level scanner and is named Parsing
Let us now study the working of YACC in compiler design.