Creating a parser with the yacc program

The yacc program creates parsers that define and enforce structure for character input to a computer program.

To use this program, you must supply the following inputs:
grammar file
A source file that contains the specifications for the language to recognize. This file also contains the main, yyerror, and yylex subroutines. You must supply these subroutines.
main
A C language subroutine that, as a minimum, contains a call to the yyparse subroutine generated by the yacc program. A limited form of this subroutine is available in the yacc library.
yyerror
A C language subroutine to handle errors that can occur during parser operation. A limited form of this subroutine is available in the yacc library.
yylex
A C language subroutine to perform lexical analysis on the input stream and pass tokens to the parser. You can use the lex command to generate this lexical analyzer subroutine.

When the yacc command gets a specification, it generates a file of C language functions called y.tab.c. When compiled using the cc command, these functions form the yyparse subroutine and return an integer. When called, the yyparse subroutine calls the yylex subroutine to get input tokens. The yylex subroutine continues providing input until either the parser detects an error or the yylex subroutine returns an end-marker token to indicate the end of operation. If an error occurs and the yyparse subroutine cannot recover, it returns a value of 1 to the main subroutine. If it finds the end-marker token, the yyparse subroutine returns a value of 0 to the main subroutine.