Flex & Bison in Ubuntu


Instruction for flex & bison in Debian Linux (Ubuntu/Linux Mint)

PRE-REQUISITE

(A) Install flex from terminal: sudo apt-get install flex
(B) Install bison from terminal: sudo apt-get install bison
(C) If you dont have gcc installed, you can get it using sudo apt-get install gcc

+ +++++++++++++++++++++ +
+ PROCESSING +
+ +++++++++++++++++++++ +

(1) Process the .lex file with flex
————————————-
flex filename.lex
>> lex.yy.c will be created

(2) Process .y file with bison
————————————-
bison -yd filename.y
>> Two files: y.tab.c and y.tab.h will be created

(3) Compile all files with gcc
————————————-
gcc -Wall y.tab.c y.tab.h -ly lex.yy.c -lfl -o myexecutable
>> myexecutable is your desired executable file, run in in the terminal using command: ./myexecutable

Advertisements

3 thoughts on “Flex & Bison in Ubuntu

  1. I keep getting this error while compiling the yacc file –
    p6.y:23 parser name defined to default :”parse”

    What can it mean?

  2. I figured it out, after SO long. You need to include a statement just before the token declaration. It’s
    “%name parse” This definitely resolves the error I encountered above. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s