Misplaced Pages

Yacc

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

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.

#479520

23-408: 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

46-404: A preprocessor for Fortran designed to give it C -like capabilities. Fortran was widely used for scientific programming but had very basic control-flow primitives ("do" and " goto ") and no " macro " facility which limited its expressiveness. The name of the language is a pun ( Ratfor (RATional FORtran) -> "Rat Four" -> "Rat Five" -> RatFiv ). Ratfiv was developed by Bill Wood at

69-623: A Silicon Valley startup and developed a "long-distance consulting relationship" with him in the 1990s. As of 2018 Johnson currently lived in Morgan Hill, California busy working on energy-efficient computers for machine learning at Wave Computing. Ratfor Ratfor (short for Rational Fortran ) is a programming language implemented as a preprocessor for Fortran 66 . It provides modern control structures , unavailable in Fortran 66, to replace GOTOs and statement numbers. Ratfor provides

92-473: 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". The input to Yacc is a grammar with snippets of C code (called "actions") attached to its rules. Its output

115-454: A useless intermediate Fortran code (.f) ( gcc foo.r ), this functionality was lost in version 4 during the move in 2005 from f77 to GNU Fortran . The original source was available in . deb and . rpm forms at its original site, mirror.corbina.net/mandriva/, and its archive, www.dgate.org/ratfor/ are gone as of April, 2024. Ratfiv is an enhanced version of the Ratfor programming language ,

138-474: Is a computer scientist who worked at Bell Labs and AT&T for nearly 20 years. He is best known for Yacc , Lint , spell , and the Portable C Compiler , which contributed to the spread of Unix and C . He has also contributed to fields as diverse as computer music , psychometrics and VLSI design . Johnson's passion for computing started at age five, when his grandfather took him along to his work at

161-478: 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 recognizes summation expressions and constructs nodes for them. The special identifiers $ $ , $ 1 and $ 3 refer to items on

184-463: Is available, it can be ported to any Fortran system. Ratfor source code file names end in .r or .rat. Ratfor was designed and implemented by Brian Kernighan at Bell Telephone Laboratories in 1974, and described in Software—;Practice & Experience in 1975. It was used in the book "Software Tools" ( Kernighan and Plauger , 1976). In 1977, at Purdue University , an improved version of

207-551: The Bureau of Standards . The computer he saw ("the size of a small house") made a strong impression on him, and he decided he "wanted to work with computers, and never looked back after". There were no computer science classes in college, so he studied mathematics, in which he eventually earned a PhD. Johnson joined Bell Labs and AT&T in the 1960s and worked on Unix tools for nearly 20 years, alongside computer scientists like Jeffrey Ullman , Dennis Ritchie and Alfred Aho . He

230-465: The Institute for Cancer Research , Philadelphia , PA in the early 1980s and released on several DECUS (Digital Equipment Users Group) SIG (Special Interest Group) tapes. It is based on the original Ratfor by B. Kernighan and P. J. Plauger , with rewrites and enhancements by David Hanson and friends (U. of Arizona), Joe Sventek and Debbie Scherrer ( Lawrence Berkeley National Laboratory ). Ratfiv V2.1

253-637: The USENIX board for ten years, including four years as president in the early 1990s. He now serves as the USENIX representative to the Computing Research Association . In 2002, he moved to Boston to work at MathWorks , where he helped maintain the front end of the MATLAB programming language, for which he also built a lint product called M-Lint. He had met MathWorks founder Cleve Moler while working at

SECTION 10

#1732898680480

276-463: The Ratfor preprocessor was written. It was called Mouse4, as it was smaller and faster than Ratfor. A published document by Dr. Douglas Comer , professor at Purdue, concluded "contrary to the evidence exhibited by the designer of Ratfor, sequential search is often inadequate for production software. Furthermore, in the case of lexical analysis, well-known techniques do seem to offer efficiency while retaining

299-470: The availability of Fortran 77 , a successor named Ratfiv (Ratfor=rat4 => rat5=Ratfiv) could, with an option /f77, output a more readable Fortran 77 code: Initial Ratfor source code was ported to C in 1985 and improved to produce Fortran 77 code too. A git tree has been set in 2010 in order to revive ratfor . Although the GNU C compiler had the ability to directly compile a Ratfor file (.r) without keeping

322-421: 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

345-412: The early '70s because he wanted to insert an exclusive or operator into Ritchie's B language compiler. Bell Labs colleague Alfred Aho suggested he look at Donald Knuth 's work on LR parsing , which served as the basis for Yacc. In a 2008 interview, Johnson reflected that "the contribution Yacc made to the spread of Unix and C is what I'm proudest of". Lint was developed in 1978 while Johnson

368-524: The following kinds of flow-control statements, described by Kernighan and Plauger as "shamelessly stolen from the language C , developed for the UNIX operating system by D.M. Ritchie " ("Software Tools", p. 318): For example, the following code might be translated as The version of Ratfor in Software Tools is written in Ratfor, as are the sample programs, and inasmuch as its own translation to Fortran

391-542: 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 . 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

414-460: 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

437-457: 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

460-409: The simplicity, ease of coding and modularity of ad hoc methods." (CSD-TR236). In comparison to the Ratfor preprocessor on a program of 3000 source lines running on a CDC 6500 system took 185.470 CPU seconds. That was cut by 50% when binary search was used in the Ratfor code. Rewriting the ad hoc lexical scanner using a standard method based on finite automata reduced run time to 12.723 seconds. With

483-402: 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 . Stephen C. Johnson Stephen Curtis Johnson (born 1944)

SECTION 20

#1732898680480

506-496: Was best known for writing Yacc , Lint , and the Portable C Compiler . In the mid-1970s, Johnson and Bell colleague Dennis Ritchie co-authored the first AT&T Unix port. They also "demonstrated that Unix was portable ", which Ritchie considers the spark that led to Unix becoming widespread. In the mid-1980s, he served as the head of the UNIX Languages Department ( UNIX System V ). Johnson developed Yacc in

529-567: Was debugging the Yacc grammar he was writing for C and struggling with portability issues stemming from porting Unix to a 32-bit machine. In 1986, Johnson moved to Silicon Valley , where he joined several startups , where he worked mostly on compilers , but also 2D and 3D graphics, massively parallel computing and embedded systems . The startups included Dana Computer, Inc. , Melismatic Software, and Transmeta , which made low-power, Intel -compatible microprocessors . Johnson served on

#479520