Tutorial for lex and yacc
Running lex (flex) for Windows users (basic example):
- Create lex file with extension .l
- Run
flex lexfile.l
. This creates a file called 'lex.yy.c'. - Run
gcc lex.yy.c -L "C:\MinGW\msys\1.0\lib\" -lfl
. The directory contains the 'libfl.a' file, which is necessary for running '-lfl'. - Run
.\a.exe
(or whatever the .exe file is called). - Enter input in corresponding lines, or redirect input from file. Note: input redirection '<' does not work in Powershell. Switch to Command Prompt to use that.
Running yacc (bison) for Windows users:
- Create yacc file with extension .y
- Run
bison -dy yaccfile.y
. This creates two files called 'y.tab.c' and 'y.tab.h'. - Create lex file with extension .l and run as instructed above.
- Run
gcc lex.yy.c y.tab.c -o output
, to create output file 'output.exe'. - Run
.\output.exe
(or whatever the .exe file is called). - Enter input in corresponding lines.