Thursday 29 January 2015

Filled Under:

How To Compile Lex and Yacc in Windows

Post By - Tanmay | 1/29/2015 06:42:00 am



Being a Compiler fan or just got to do a silly Compiler Design Project ?
Don't worry, I know that feel :( 

Bookmark this page, because you're gonna need this one and Share it too.

So, if you are going to make a partition in your heart sorry, disk (that just slipped away) to install any LINUX or LINUX based OS just for sake of few projects to compile Lex ("#.l") or Yacc ("#.y") don't you think it will be wastage of your effing time. Run them in Windows Kernels with my help (balance of probability) :p

So, the Beans are going to spill one method by which you can compile and run them into Windows OS :

Download few software :

These are small apps so, no need for IDM, Yeppiieee!!!

1: Dev-CPP : You've heard about it. No Description Required.
2: Flex : Lex Analyzer and Generator
3: Bison : For including Yacc Files, yuck!!!

Have you downloaded them already ? Great !!

Now Install Them:

4 : Flex should be installed in "C:/GnuWin32"
5 : Bison should be installed in "C:/GnuWin32"
6 : DevCPP Hmm at "C:/Dev-Cpp"

 You'll have to set Environment Variable's path to "C:\GnuWin32\bin;C:\Dev-Cpp\MinGW64\bin;"

Problem 1: Basically a problem will be there. Already there is something ? Ohh you people, use a semicolon ";" to separate them and add ahead it.

Problem 2: I am fed up of this, really. It's 'yywrap'. It's returning Id returned 1 exit status.
Solution: Add yywrap() {   } as a function in your '.lex' file before main() 

Great ?

Now Use it :

Open CMD in your directory, where you've stored all your files with extensions (".l") and (".y") and,

Consider your file as "hey.l" and "foo.y"

For files with ".l" extension only :
  -   flex hey.l
  -   gcc lex.yy.c


For files with ".y" extension only :
  -   flex hey.l
  -   bison -dy foo.y
  -   gcc lex.yy.c y.tab.c
  

Don't you want to see some output
  -   a.exe 

Great !! But I would like to prefer Labs. Thanks to my Professor who suggested me this thing.
Do Share It.
 

0 comments:

Post a Comment