Environment configuration for Lex and Yacc Learning (I), lexyacc learning environment
Abstract
In the process of developing programs, we often encounter text parsing problems, such as parsing C-language source programs and writing script engines. There are many ways to solve this problem, one way is to manually write a parsing program using C or C ++, which is not a problem for text information in a simple format, however, for parsing a slightly more complex text information, writing a parser manually will be a long, painful and error-prone task. This series of documents is specifically used to introduce two famous Unix tools, Lex and Yacc, we will explain in detail how to use these two tools to implement the parsing program for any function we want. In order to facilitate understanding and application, in this series of articles, I will try to use practical instances to illustrate them, and such instances are as far as possible irrelevant to the specific system platform, therefore, I use the command line program as the final result of our parsing program.
1. Environment configuration Article 1.1 Essential tools (Note: all required tools can be found in my resource files)
Programs to be installed in the Lex and Yacc development environments on Windows:
(1)Lex(flex.exe)
(2policyacc(bison.exe)
(3) C/C ++ Compiler
1.2 flex and bison Installation
Flex.exeand bison.exe are files in the UnxUtils package. They have transplanted Many Unix/Linux programs to the Windows platform and can be downloaded directly from the UnxUtils website, after downloading and decompressing, add the directory of all the UnxUtils exe files in the PATH environment variable of the system, so that the doscommand line can directly search for flex.exeand bison.exe. In addition, you also need to download the bison required by bison from the network. simple and bison. hairy files, and you must set the environment variable BISON_HAIRY to bison respectively. hairy, BISON_SIMPLE points to bison. simple.
Run cmd to check whether the installation is successful, as shown in:
1.3 C/C ++ Compiler
The flex and bison we use are GNU tools. For convenience, the c/c ++ compiler is also the GNU Compiler GCC, which requires the WINDOWS MinGW compiler, you can download and install the package from the MinGW homepage.
After installation, add the bin directory under MinGW to the Path of the system environment variable.
The configuration is complete.