COMPILER DESIGN LABORATORY PROGRAMS
1. Lex and Yacc
2. Operator Precedence Parser
3. Token Separation aka Lexical analysis
4. Symbol table implementation
5. Shift reduce parser
6. Pass 1 of assembler implementation in C
[ALL THE ABOVE PROGRAMS ARE TESTED AND WORKING]
HOW TO COMPILE LEX AND YACC?
IN WINDOWS (SOURCE)=>
Installing Softwares:
Download Flex 2.5.4a
Download Bison 2.4.1
Download DevC++
Install Flex at "C:\GnuWin32"
Install Bison at "C:\GnuWin32"
Install DevC++ at "C:\Dev-Cpp"
Open Environment Variables.
Add "C:\GnuWin32\bin;C:\Dev-Cpp\bin;" to
path.
Compilation & Execution of your Program:
Open Command prompt and switch to your working
directory where you have stored your lex file (".l") and yacc file
(".y")
Let your lex and yacc files be "hello.l"
and "hello.y". Now, follow the preceding steps to compile and run
your program.
For Compiling Lex file only:
flex hello.l
gcc lex.yy.c
For Compiling Lex & Yacc file both:
flex hello.l
bison -dy hello.y
gcc lex.yy.c y.tab.c
For Executing the Program
a.exe
VISIT SITE - SOURCE
IN LINUX =>
TO INSTALL LEX AND YACC
Open terminal and type:
$sudo -s
You will be asked to enter your password
then,
$sudo apt-get install flex (this installs lex)
TO INSTALL LEX AND YACC
Open terminal and type:
$sudo -s
You will be asked to enter your password
then,
$sudo apt-get install flex (this installs lex)
$sudo apt-get install bison (this installs yacc)
[NOTE - Installation requires Internet connection.]
COMPILE AND RUN
You will be shown something like
"do you want to install these packages? press "y". Hit
enter.
ONLY LEX
1.lex filename.l
2.gcc lex.yy.c
3. ./a.out
Instruction to run lex and yacc program
1.lex filename.l
2.yacc -d filename.y
3.gcc lex.yy.c y.tab.c -ll
4. ./a.out
[NOTE - yacc program doesn't work without lex program]
EXAMPLE - Running a Simple Lex Program
EXAMPLE 2 - Running Calculator Program (Includes both LEX AND YACC)
If you have any other queries ask in Comments below.