Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Yacc still used in the industry?

Tags:

parsing

yacc

The software base I am developing for uses a signficant amount of yacc which I don't need to deal with. Some times I think it would be helpful in understanding some problems I find but most of the time I can get away with my complete ignorance of yacc.

My question are there enough new projects out there that still use yacc to warrant the time I'll need to learn it?

Edit: Given the response is mostly in favour of learning Yacc, is there a similar language that you would recommend over yacc?

like image 787
hhafez Avatar asked Dec 02 '08 01:12

hhafez


People also ask

Is yacc and bison same?

Bison is the GNU implementation/extension of Yacc, Flex is the successor of Lex.

What is GNU bison used for?

Bison is a general-purpose parser generator that converts an annotated context-free grammar into a deterministic LR or generalized LR (GLR) parser employing LALR (1) parser tables. As an experimental feature, Bison can also generate IELR (1) or canonical LR(1) parser tables.

What is yacc and bison?

Bison originated as a workalike of a program called Yacc — Yet Another Compiler Compiler. 9. Yacc was written at Bell Labs as part of the very early development of Unix; one of its first uses was to develop the original Portable C Compiler, pcc. The same person, Steven C. Johnson, wrote Yacc and the original pcc.

What are the tools yacc and bison?

Introduction. YACC and Bison are tools used to generate parsers. For a language to parsed by YACC or Bison, it has to be described by a context-free grammar and only those languages that are LALR(1) can be parsed by YACC or Bison.


2 Answers

Yes, these tools are worth learning if you ever need to create or modify code that parses a grammar.

For many years the de facto tool for generating code to parse a grammar was yacc, or its GNU cousin, bison.

Lately I've heard there are a couple of new kids on the block, but the principle is the same: you write a declarative grammar in a format that is more or less in Backus-Naur Form (BNF) and yacc/bison/whatever generates some code for you that would be extremely tedious to write by hand.

Also, the principles behind grammars can be very useful to learn even if you don't need to work on such code directly. I haven't worked with parsers much since taking a course on Compiler Design in college, but understanding runtime stacks, lookahead parsers, expression evaluation, and a lot of other related things has helped me immensely to write and debug my code effectively.

edit: Given your followup question about other tools, Yacc/Bison of course are best for C/C++ projects, since they generate C code. There are similar tools for other languages. Not all grammars are equivalent, and some parser generators can only grok grammars of a certain complexity. So you might need to find a tool that can parse your grammar. See http://en.wikipedia.org/wiki/Comparison_of_parser_generators

like image 126
Bill Karwin Avatar answered Sep 27 '22 20:09

Bill Karwin


I don't know about new projects using it but I'm involved in seven different maintenance jobs that use lex and yacc for processing configuration files.

No XML for me, no-sir-ee :-).

Solutions using lex/yacc are a step up from the old configuration files of key=val lines since they allow better hierarchical structures like:

server = "mercury" {
    ip = "172.3.5.13"
    gateway = "172.3.5.1"
}
server = "venus" {
    ip = "172.3.5.21"
    gateway = "172.3.5.1"
}

And, yes, I know you can do that with XML, but these are primarily legacy applications written in C and, to be honest, I'd probably use lex/yacc for new (non-Java) jobs as well.

That's because I prefer delivering software on time and budget rather than delivering the greatest new whizz-bang technology - my clients won't pay for my education, they want results first and foremost and I'm already expert at lex/yacc and have all the template code for doing it quickly.

like image 20
paxdiablo Avatar answered Sep 27 '22 20:09

paxdiablo