ArticleslgStudy

biology

Yacc

Yacc is a biology topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Yacc rather than just read about it. In short: Yacc (Yet Another Compiler-Compiler) is a computer program for the Unix operating system developed by Stephen C. Johnson.

Key takeaways

  • Yacc belongs to biology; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Yacc to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Yacc from memory before moving on to harder problems.

Reference excerpt

Yacc (Yet Another Compiler-Compiler) is a computer program for the Unix operating system developed by Stephen C. Johnson. It is a lookahead left-to-right rightmost derivation (LALR) parser generator, generating a LALR parser (the part of a compiler that tries to make syntactic sense of the source code) based on a formal grammar, written in a notation similar to Backus–Naur form (BNF). Yacc is supplied as a standard utility on BSD and AT&T Unix. GNU-based Linux distributions include Bison, a forward-compatible Yacc replacement.

History In the early 1970s, Stephen C. Johnson, a computer scientist at Bell Labs / AT&T, developed Yacc because he wanted to insert an exclusive or operator into a B language compiler (developed using McIlroy's TMG compiler-compiler), but it turned out to be a hard task. As a result, he was directed by his colleague at Bell Labs Al Aho to Donald Knuth's work on LR parsing, which served as the basis for Yacc. Yacc was influenced by and received its name in reference to TMG compiler-compiler. Yacc was originally written in the B programming language, but was soon rewritten in C by Alan Snyder. It appeared as part of Version 3 Unix, and a full description of Yacc was published in 1975. Johnson used Yacc to create the Portable C Compiler. Bjarne Stroustrup also attempted to use Yacc to create a formal specification of C++, but "was defeated by C's syntax". While finding it unsuitable for a formal specification of the language, Stroustrup did proceed to use Yacc to implement Cfront, the first implementation of C++. In a 2008 interview, Johnson reflected that "the contribution Yacc made to the spread of Unix and C is what I'm proudest of".

Description The input to Yacc is a grammar with snippets of C code (called "actions") attached to its rules. Its output is a shift-reduce parser in C that executes the C snippets associated with each rule as soon as the rule is recognized. Typical actions involve the construction of parse trees. Using an example from Johnson, if the call node(label, left, right) constructs a binary parse tree node with the specified label and children, then the rule

expr : expr '+' expr { $$ = node('+', $1, $3); } recognizes summation expressions and constructs nodes for them. The special identifiers $$, $1 and $3 refer to items on the parser's stack. Yacc produces only a parser (phrase analyzer) which can be used alone in the case of scannerless parsing however, full syntactic analysis typically requires an external lexical analyzer to perform a tokenization stage first (word analysis), which is then followed by the parsing stage proper. Lexical analyzer generators, such as Lex or Flex, are widely available for this purpose. The IEEE POSIX P1003.2 standard defines the functionality and requirements for both Lex and Yacc. Some versions of AT&T Yacc have become open source. For example, source code is available with the standard distributions of Plan 9.

Impact Yacc and similar programs (largely reimplementations) have been very popular. Yacc itself used to be available as the default parser generator on most Unix systems, though it has since been supplanted by more recent, largely compatible, programs such as Berkeley Yacc, GNU Bison, MKS Yacc, and Abraxas PCYACC. An updated version of the original AT&T Yacc is included as part of Sun's OpenSolaris project. Each offers slight improvements and additional features over the original Yacc, but the concept and basic syntax have remained the same. Yacc was also one of several UNIX tools available for Charles River Data Systems' UNOS operating system under Bell Laboratories license. Among the languages that were first implemented with Yacc are AWK, C++, eqn and Pic. Yacc was also used on Unix to implement the Portable C Compiler, as well as parsers for such programming languages as FORTRAN 77, Ratfor, APL, bc, m4, etc. Yacc has also been rewritten for other languages, including OCaml, Ratfor, ML, Ada, Pascal, Java, PHP, Python, Ruby, Go, Common Lisp and Erlang.

Berkeley Yacc: The Berkeley implementation of Yacc quickly became more popular than AT&T Yacc itself because of its performance and lack of reuse restrictions. LALR parser: The underlying parsing algorithm in Yacc-generated parsers. Bison: The GNU version of Yacc. Lex (and Flex lexical analyser), a token parser commonly used in conjunction with Yacc (and Bison). BNF is a metasyntax used to express context-free grammars: that is a formal way to describe context-free languages. PLY (Python Lex-Yacc) is an alternative implementation of Lex and Yacc in Python.

See also Compiler-compiler hoc (programming language)

References

External links Playground environment for learning and testing syntax

yacc – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group yacc(1) – Plan 9 Programmer's Manual, Volume 1 yacc(1) – Inferno General commands Manual yacc(1) – Linux General Commands Manual from ManKier.com

Worked examples

Example 1 — a first encounter with Yacc

Start with the simplest possible case. Write down what Yacc claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In biology, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Yacc before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Yacc ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Yacc

In research
Yacc appears in biology research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Yacc in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Yacc is common in secondary-school and first-year university syllabi. It links to neighbouring topics Compiling tools, Inferno (operating system) commands, Parser generators, so understanding it makes those chapters shorter.
In everyday life
Look for Yacc outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Yacc” →

How to study Yacc in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Yacc means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Yacc out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Yacc in simple terms?

Yacc (Yet Another Compiler-Compiler) is a computer program for the Unix operating system developed by Stephen C. Johnson.

Why does Yacc matter?

Because it connects several biology ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Yacc?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Yacc.

Tags

  • Compiling tools
  • Inferno (operating system) commands
  • Parser generators
  • Plan 9 commands
  • Unix SUS2008 utilities
  • Unix programming tools

Keep exploring