The Tech Addas

The Tech Addas
Subscribe For Free Updates!

We'll not spam mate! We promise.

Sunday 11 August 2013

[How-To] Easily Configure Lex and Yacc in Ubuntu

Hello folks, This time we'll let you know how to configure Lex and Yacc. Sorry its off topic but just came across it so thought of sharing with you. Talking about Lex , "Lex is a computer program that generates lexical analyzers "- wikipedia . Lex and yacc are tools used to generate lexical analyzers and parsers for more information you visit Lex and Yacc Tutorials.

This tools are not shipped in Any version Ubuntu . So we'll show you how to can get them working in your ubuntu laced machine.

What You will need ?

  •  Ubuntu Machine with Internet Connection.
Actually In Ubuntu,  Lex and Yacc are having alternatives Flex and Bison.

Steps to Get Lex and Yacc :

Step #1: Open Terminal , which would look something like this.(for demo we are kubuntu but dont wory its much similar to ubuntu.)
                   
  
Step #2: Now Type sudo apt-get install flex , it will connect to repository and do all stuff of installation for you . then type sudo apt-get install bison , this will install yacc alternative .

Step #3: To make sure your lex(~flex) and yacc(~bison) are installed properly just type in termianl which lex and then which yacc , it would look similar to this.

LEX and YACC in ubuntu

Now your ubuntu machine is ready for Lex and Yacc programs .

For Compiling And Running Lex Proprams:  

1) lex sample.l
2) gcc -lfl lex.yy.c
3) ./a.out

Hope you find it usefull , Stay Tuned to The Tech Addas.

Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

2 comments :

  1. After Compiling Lex and Yacc Proprams m getting the following error :
    shraddha@ubuntu:~$ cd Desktop
    shraddha@ubuntu:~/Desktop$ lex ass4l.l
    shraddha@ubuntu:~/Desktop$ yacc -d ass4y.y
    shraddha@ubuntu:~/Desktop$ gcc lex.yy.c y.tab.c -ll -ly -lm
    /usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/liby.a(yyerror.o): In function `yyerror':
    (.text+0x1c): undefined reference to `rpl_fprintf'
    collect2: error: ld returned 1 exit status

    Please help in removing the above error

    ReplyDelete
    Replies
    1. @pooja: This error is due to the reason that you have not provided your own yyerror() . To resolve you should include yyerror() explicitly like this

      void yyerror(char *s)
      {
      fprintf (stderr, "%s\n", s);
      }

      Delete