Lex and yacc-Linux general technology-Linux programming and kernel information. The following is a detailed description. Author: brilliant and dusty
I recently read GCC-the-Complete-Reference-fly to know that there are two interesting tools, lex and yacc, and these two tools are installed by default in fedora core 8, so I would like to take this opportunity to learn about the yacc term when I used to learn compilation principles. But I never thought about what yacc is. There are too many things to learn, it's really hard to learn.
Start with lex. Lex, also known as Lexical Analyzar, performs Lexical analysis on the source program. If you have learned how to compile, you will know the process of converting the source code from a text file to an executable binary file. The first two steps are lexical analysis and syntax analysis. Lex matches the input according to the specified mode. When a rule is matched, the corresponding action is executed.
A Lex program is divided into three sections: the first section is the global declaration of C and Lex, the second section includes the mode (C code), and the third section is the supplementary C function. For example, the third section usually contains the main () function. These segments are separated by %.
The following is a lex program for counting words.