132
votes

What is the difference between Flex & Lex and Yacc & Bison. I searched the Internet wildly and I didn't find any solid answer.

Can I install pure Lex and Yacc on Ubuntu, or I can install only flex and bison. I am confused.

  • Is Lex or Yacc still being maintained by someone?
  • Are all of them free?
  • If Lex is not free why do I have it installed on my Ubuntu distribution?

    lex --version
    lex 2.5.35
    
5
There is no lex version 2.5.35 -- you're running flex version 2.5.35, it just identifies itself as 'lex' if you invoke it as 'lex'Chris Dodd

5 Answers

85
votes

There are some differences between Lex and Flex, but you have to be abusing Lex to run into the problems with Flex. (I have a program which abuses Lex and doesn't work under Flex, therefore.) This is primarily in the area of input lookahead; in Lex, you can provide your own input code and modify the character stream; Flex won't let you do that.

Yacc and Bison are pretty closely compatible, though Bison has some extra tricks it can do.

You probably can't find legitimate copies of (the original, AT&T versions of) Lex and Yacc to install on Ubuntu. I wouldn't necessarily say it is impossible, but I'm not aware of such. Flex and Bison are readily available and are equivalent for most purposes. You may also find various alternative and approximately equivalent programs from the BSD world.

Lex and Yacc are maintained by the Unix SVRx licencees - companies such as IBM (AIX), HP (HP-UX) and Sun (Solaris) have modified versions of Lex and Yacc at their command. MKS also provides MKS Lex and MKS Yacc; however, the Yacc at least has some non-standard extensions.

Flex and Bison are free. (AT&T) Lex and Yacc are not.

35
votes

Bison is the GNU implementation/extension of Yacc, Flex is the successor of Lex. In either case, it's fine (and recommended) to use bison / flex.

11
votes

On most (all?) Linux systems, "Lex" is actually a symbolic link to flex. Basically, it's only a different name to the free version.

10
votes

YACC is available under open source licenses from both Plan 9 and Open Solaris. Also, there is also Berkeley YACC, which is compatible with the original YACC, but does not share source code. Berkeley YACC can be found on any of the open source BSD operating systems.

2
votes

Bison in a part of the GNU project. And yacc is used as a utility on Berkeley Software Distribution (BSD).Though its compatible with yacc, but Lex and Yacc are a thing of the past. Flex and bison are widely used today.