Share to: share facebook share twitter share wa share telegram print page

Yacc

Yacc
Original author(s)Stephen C. Johnson
Repository
Written inC
Operating systemUnix, Unix-like, Plan 9, Inferno
PlatformCross-platform
TypeCommand
LicensePlan 9: MIT License

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).[1] Yacc is supplied as a standard utility on BSD and AT&T Unix.[2] GNU-based Linux distributions include Bison, a forward-compatible Yacc replacement.[3]

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[4] (developed using McIlroy's TMG compiler-compiler[5]), 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.[4] Yacc was influenced by[6] and received its name in reference to TMG compiler-compiler.[7]

Yacc was originally written in the B programming language, but was soon rewritten in C by Alan Snyder.[5] It appeared as part of Version 3 Unix,[8] and a full description of Yacc was published in 1975.[6]

Johnson used Yacc to create the Portable C Compiler.[8] Bjarne Stroustrup also attempted to use Yacc to create a formal specification of C++, but "was defeated by C's syntax".[9] 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++.[10]

In a 2008 interview, Johnson reflected that "the contribution Yacc made to the spread of Unix and C is what I'm proudest of".[11]

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.[6]

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.[6] 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.[12]

Some versions of AT&T Yacc have become open source. For example, source code is available with the standard distributions of Plan 9.[13]

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.[14]

Yacc was also one of several UNIX tools available for Charles River Data Systems' UNOS operating system under Bell Laboratories license.[15]

Among the languages that were first implemented with Yacc are AWK, C++,[10] eqn and Pic.[16] 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.[8][17]

Yacc has also been rewritten for other languages, including OCaml,[18] Ratfor, ML, Ada, Pascal, Java, PHP, Python, Ruby, Go,[19] Common Lisp[20] and Erlang.[21]

  • 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.[22]
  • 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

References

  1. ^ "The A-Z of Programming Languages: YACC". Computerworld. Archived from the original on 31 January 2013. Retrieved 30 November 2012.
  2. ^ Levine, John (1992). Lex & yacc. Sebastopol, CA: O'Reilly & Associates. p. xx. ISBN 1-56592-000-7.
  3. ^ Levine, John (2009). Flex & bison. Sebastopol, Calif: O'Reilly Media. p. xv. ISBN 978-0-596-15597-1.
  4. ^ a b Morris, Richard (1 October 2009). "Stephen Curtis Johnson: Geek of the Week". Red Gate Software. Retrieved 19 January 2018.
  5. ^ a b Ritchie, Dennis M. (April 1993). "The Development of the C Language". History of programming languages---II. Association for Computing Machinery, Inc. (published 1996-01-01). doi:10.1145/234286.1057834. ISBN 0-201-89502-1. pp. 675, 684: After the TMG version of B was working, Thompson rewrote B in itself(a bootstrapping step).…When Johnson returned to Bell Labs in 1973, he was disconcerted to find that the language whose seeds he had brought to Canada had evolved back home; even his own yacc program had been rewritten in C, by Alan Snyder.
  6. ^ a b c d Johnson, Stephen C. (1975). Yacc: Yet Another Compiler-Compiler (Technical report). Murray Hill, New Jersey: AT&T Bell Laboratories. 32. Retrieved 31 January 2020.
  7. ^ "Early Translator Writing Systems". Atlas Computer Laboratory.
  8. ^ a b c McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. 139.
  9. ^ Stroustrup, Bjarne. "A History of C++: 1979−1991" (PDF).
  10. ^ a b Stroustrup, Bjarne. "Cfront source code".
  11. ^ Hamilton, Naomi (2008-07-09). "Yacc, Unix, and advice from Bell Labs alumni Stephen Johnson". www.computerworld.com. Archived from the original on 2020-08-22. Retrieved 2020-11-10.
  12. ^ lex – Shell and Utilities Reference, The Single UNIX Specification, Version 4 from The Open Group, yacc – Shell and Utilities Reference, The Single UNIX Specification, Version 4 from The Open Group.
  13. ^ "plan9: UC Berkeley release of Plan 9 under the GPLv2". GitHub. 26 December 2017. Retrieved 2 January 2018.
  14. ^ Bison Manual: History
  15. ^ The Insider's Guide To The Universe (PDF). Charles River Data Systems, Inc. 1983. p. 13.
  16. ^ "UNIX Special: Profs Kernighan & Brailsford". Computerphile. September 30, 2015. Archived from the original on 2021-12-11.
  17. ^ Kernighan, Brian W.; Pike, Rob (1984). The Unix Programming Environment. Prentice Hall. ISBN 0-13-937681-X.
  18. ^ "OCaml User's Manual: Chapter 12 Lexer and parser generators (ocamllex, ocamlyacc)". Retrieved 25 Nov 2013.
  19. ^ "Yacc.go: A version of Yacc for the Go Programming Language". Retrieved 15 July 2017.
  20. ^ "CL-Yacc: A Common Lisp version of Yacc".
  21. ^ "yecc: An Erlang implementation of Yacc".
  22. ^ John Levine (August 2009), flex & bison, O'Reilly Media
  • Playground environment for learning and testing syntax

Read other articles:

Cél articllo est ècrit en arpetan supradialèctâl / ORB lârge. Fevriér 1ér 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 (30) Tôs los jorns Lo 14 de fevriér est lo 45émo jorn de l’an du calendriér grègorien. Manuscrit de los Juraments d’Estrâbôrg Maria Louise de Savouè. Politica et èvènements 0842 : Juraments d’Estrâbôrg, a Estrâbôrg – Lo texto est la première trace écrite du francês. 1349 : Pogrom d’Estrâborg, contre l...

حيران الثاني معلومات شخصية تاريخ الميلاد القرن 3  مواطنة تدمر  الأب أذينة  الأم زنوبيا  إخوة وأخوات وهب اللات،  وحيران الأول  تعديل مصدري - تعديل   كان حيران الثاني أميرًا تدمريًا وهو ابن الملك أذينة ربما من زوجته الثانية زنوبيا. ختم RTP 736 تم تأسيس وجود حيران م

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Dance of the Wicked – news · newspapers · books · scholar · JSTOR (August 2010) (Learn how and when to remove this template message) 2003 studio album by Sister SinDance Of The WickedStudio album by Sister SinReleasedSeptember 1, 2003, 2013Recorded2003G...

This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: AGM-124 Wasp – news · newspapers · books · scholar · JSTOR (April 2022) (Learn how and when to remove this ...

Опис файлу Опис Фундаменти церкви пророка Іллі в Галичі за Каргером Джерело Ю, Диба Ротонда св. пророка Іллі у Галичі//Українські храми-ротонди Х - першої половини XIV століть. - Львів: Видавництво Національного університету Львівська політехніка, 2005. - 108 с.: іл. Час створення...

  لمعانٍ أخرى، طالع مالون (توضيح). مالون   الإحداثيات 44°51′13″N 74°19′44″W / 44.853611111111°N 74.328888888889°W / 44.853611111111; -74.328888888889  [1] تاريخ التأسيس 1805  تقسيم إداري  البلد الولايات المتحدة[2][3]  التقسيم الأعلى مقاطعة فرانكلن، نيويورك  خصائص جغرافي...

Академія медичних наук СРСР Основні дані Засновано 1944 Країна  СРСРТип академія наук і організаціяМатеринськаорганізація Академія наук СРСР Акаде́мія меди́чних нау́к СРСР — вища наукова медична установа в СРСР. Створена в 1944 році. ЇЇ приємниками є Російська А...

A arte rupestre do extremo sul da península Ibérica, conhecida localmente como arte sureño (arte sulista), refere-se a um conjunto de arte rupestre existente primariamente nas províncias de Cádis, bem como na de Málaga, na Andaluzia (Espanha). Trata-se de mais de 180 cavernas e abrigos com representações pré-históricas em forma de pinturas e gravuras. As figuras mais antigas do conjunto datam do Paleolítico Superior. Um exemplo desta época são as gravuras de cavalos da Caverna do...

Konventionstaler von 1766 mit Heinrich XXIV. (1747–1779) Residenz Schloss Ebersdorf, Parkseite Residenz Schloss Ebersdorf, Straßenseite Die Grafschaft Reuß-Ebersdorf entstand nach mehreren Teilungen der jüngeren Linie Reuß ebenso wie die Grafschaft Reuß-Hirschberg 1678 aus einer Teilung der Grafschaft Reuß-Lobenstein und existierte bis 1848. Inhaltsverzeichnis 1 Geschichte 2 Übersicht der Regenten 2.1 Grafen Reuß zu Ebersdorf 2.2 Fürsten Reuß zu Ebersdorf 3 Siehe auch 4 Einzelnach...

American 2015 television series Show Me a HeroGenreDramaBased onShow Me a Heroby Lisa BelkinWritten by David Simon William F. Zorzi Directed byPaul HaggisStarring Oscar Isaac Bob Balaban Jim Belushi Jon Bernthal Dominique Fishback Ilfenesh Hadera LaTanya Richardson Jackson Catherine Keener Terry Kinney Alfred Molina Natalie Paul Peter Riegert Carla Quevedo Winona Ryder Ending themeWhen the People Find Out by Steve EarleComposerNathan LarsonCountry of originUnited StatesOriginal languageEnglis...

Aespa in 2023 South Korean girl group Aespa has recorded 33 songs, of which 29 are in Korean, three are in English, and one in Japanese. Songs Key † Indicates a single release # Indicates a promotional single release ‡ Indicates a soundtrack single release Songs recorded by Aespa Title Year Lyricist Composer Arranger Album Ref. Aenergy 2021 Yoo Young-jin Kill DavePat MorrisseyJess CorazzaYoo Young-jin Kill DavePat MorrisseyYoo Young-jin Savage [1] Beautiful Christmas(with Red Velv...

Not to be confused with Meyhane. Music of Azerbaijan General topics Musical instruments Khananda Mugham triads Art of playing the tar Dances Ballet Genres Jazz Religious [az] Military Hip hop Classical Opera Pop Rock Folk music Specific forms Traditional music Ashiq music Meykhana Mugham Tasnif Subgenres Jazz mugham Mugham opera Symphonic mugham [az] Media and performance Music awards People's Artiste of Azerbaijan Honored Art Worker Humay Award Music festivals ...

Athletic teams of McMaster University in Hamilton, Ontario, Canada McMaster MaraudersUniversityMcMaster UniversityAssociationU SportsConferenceOntario University AthleticsAthletic directorShawn BurtLocationHamilton, OntarioFootball stadiumRon Joyce StadiumArenaBurridge Gymnasium in Ivor Wynne CentreFieldBack Tens FieldMascotMac the Marauder[1]NicknameMaraudersFight songShout for McMaster!ColoursMaroon and Grey   Websitewww.marauders.ca The McMaster Marauders a...

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Object Manager Windows – news · newspapers · books · scholar · JSTOR (March 2019) (Learn how and when to remove this template message) Object Manager in Windows, categorized hierarchically using namespaces Object Manager (internally called Ob) is a subsyst...

The Eagle & Phenix Dam on the Chattahoochee River prior to its demolition in 2012. This is a list of dams in Alabama that have been removed as physical impediments to free-flowing rivers or streams. Completed removals Dam[1] Height Year removed Location Watercourse Watershed Notes Unnamed dam 2007 Hanceville34°03′20″N 86°45′21″W / 34.0555°N 86.7558°W / 34.0555; -86.7558 Mud Creek Black Warrior River Dam was illegally constructed by Hanceville Wa...

Role and influence of socialism in Bangladesh This article is part of a series on thePolitics of the People's Republic of Bangladesh Constitution Amendments Law of Bangladesh Human rights Article 70 Judicial review Government President: Mohammed Shahabuddin Prime Minister: Sheikh Hasina Cabinet: Hasina IV Taxation Agencies Civil Service Local governments Parliament Speaker: Shirin Sharmin Chaudhury Leader of the House: Sheikh Hasina Leader of the Opposition: Rowshan Ershad Judiciary Supreme C...

Motor vehicle Saipa Atlas2023 Saipa AtlasOverviewManufacturerSAIPAProduction2023–present (1402–present)AssemblyIran: TehranBody and chassisClassSubcompact crossover SUVBody style5-door hatchbackLayoutFront-engine, front-wheel-drivePlatformX200Relatedfa:سایپا سهندPowertrainEngine1.5 L M15I I4 (petrol)Transmission5-speed manual6-speed automaticDimensionsWheelbase2,410 mm (94.9 in)Length4,020 mm (158.3 in)Width1,685 mm (66.3 in)Height1,540 mm ...

Domestic airport in Long Beach, California Long Beach AirportIATA: LGBICAO: KLGBFAA LID: LGBWMO: 72297SummaryAirport typePublicOwnerCity of Long BeachServesGreater Los AngelesLocationLong Beach, CaliforniaElevation AMSL60 ft / 18 mCoordinates33°49′04″N 118°09′06″W / 33.81778°N 118.15167°W / 33.81778; -118.15167Websitelgb.orgMapsFAA airport diagramLGBShow map of Long Beach, CaliforniaLGBShow map of the Los Angeles metropolitan areaLGBShow map ...

Anglo-Irish soldier and statesman (1564–1631) This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Henry Docwra, 1st Baron Docwra of Culmore – news · newspapers · books · scholar · JSTOR (December 2022) (Learn how and when to remove this template message) Detail of a stained glass window in the Guildhall in Der...

Australian magazine The Lone HandCover of the July 1907 editionFormer editorsJ. F. ArchibaldFrank FoxA. H. AdamsBertram StevensWalter JagoCategoriesLiterature and poetryFrequencyMonthlyFounderJ. F. ArchibaldFrank FoxFounded1907First issueMay 1907; 116 years ago (1907-05)Final issueFebruary 1928 (1928-02)CountryAustraliaBased inSydney The Lone Hand was a monthly Australian magazine of literature and poetry published between 1907 and 1928. The magazine was based...

Kembali kehalaman sebelumnya