What is the difference between Flex/Lex and Yacc/Bison?

53,214

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

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.

Solution 5

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.

Share:
53,214
Dumb Questioner
Author by

Dumb Questioner

Updated on July 08, 2022

Comments

  • Dumb Questioner
    Dumb Questioner almost 2 years

    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
      
    • Chris Dodd
      Chris Dodd about 9 years
      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'
  • Michael Ekstrand
    Michael Ekstrand almost 15 years
    Additionally, byacc, the Berkeley implementation of yacc, is widely available (I see it in my Debian repository list).
  • Daniel C. Sobral
    Daniel C. Sobral over 14 years
    The information about Yacc is incorrect. Berkeley has a Yacc, which is present and available under the BSD license on all open source BSD operating systems. I downvoted on this account, but if the answer is corrected quickly enough I'll remove the downvote.
  • Jonathan Leffler
    Jonathan Leffler over 14 years
    @Daniel: AFAIK, AT&T Yacc can't be obtained from Berkeley - what you get from Berkeley is the Berkeley Yacc. I'll clarify the answer to reflect that.
  • Danilo Bargen
    Danilo Bargen about 12 years
    On my system (Arch Linux), the two binaries don't behave the same way. Probably a lex compatibility feature.
  • vonbrand
    vonbrand over 11 years
    In flex you certainly can switch input buffers painlessly (I did it once to handle essentially #include). My O'Reilly book on lex & yacc (not at hand here, sorry) said that it only was possible in lex through disgusting hacks.
  • vonbrand
    vonbrand over 11 years
    flex is called that because it is (was?) much faster than lex. It has several extensions, and the generated files don't llok at all similar (i.e., ugly hacks in lex don't work with flex and viceversa).
  • user207421
    user207421 about 3 years
    Is, not was. Nobody has ever fixed lex(1). @vonbrand.