Attribute grammar

An attribute grammar is a formal way to supplement a formal grammar with semantic information processing. Semantic information is stored in attributes associated with terminal and nonterminal symbols of the grammar. The values of attributes are the result of attribute evaluation rules associated with productions of the grammar. Attributes allow the transfer of information from anywhere in the abstract syntax tree to anywhere else, in a controlled and formal way.[1]

Each semantic function deals with attributes of symbols occurring only in one production rule: both semantic function parameters and its result are attributes of symbols from one particular rule. When a semantic function defines the value of an attribute of the symbol on the left hand side of the rule, the attribute is called synthesized; otherwise it is called inherited.[2] Thus, synthesized attributes serve to pass semantic information up the parse tree, while inherited attributes allow values to be passed from the parent nodes down and across the syntax tree.

In simple applications, such as evaluation of arithmetic expressions, attribute grammar may be used to describe the entire task to be performed besides parsing in straightforward way; in complicated systems, for instance, when constructing a language translation tool, such as a compiler, it may be used to validate semantic checks associated with a grammar, representing the rules of a language not explicitly imparted by the syntax definition. It may be also used by parsers or compilers to translate the syntax tree directly into code for some specific machine, or into some intermediate language.

History

Attribute grammars were invented by Donald Knuth and Peter Wegner.[3] While Donald Knuth is credited for the overall concept, Peter Wegner invented inherited attributes during a conversation with Knuth. Some embryonic ideas trace back[3] to the work of Edgar T. "Ned" Irons,[4] the author of IMP.

Example

The following is a simple context-free grammar which can describe a language made up of multiplication and addition of integers.

 ExprExpr + Term
 ExprTerm
 TermTerm * Factor
 TermFactor
 Factor → "(" Expr ")"
 Factorinteger

The following attribute grammar can be used to calculate the result of an expression written in the grammar. Note that this grammar only uses synthesized values, and is therefore an S-attributed grammar.

 Expr1Expr2 + Term [ Expr1.value = Expr2.value + Term.value ]
 ExprTerm [ Expr.value = Term.value ]
 Term1Term2 * Factor [ Term1.value = Term2.value * Factor.value ]
 TermFactor [ Term.value = Factor.value ]
 Factor → "(" Expr ")" [ Factor.value =  Expr.value ]
 Factorinteger [ Factor.value = strToInt(integer.str) ]

Synthesized attributes

A synthesized attribute is computed from the values of attributes of the children. Since the values of the children must be computed first, this is an example of bottom-up propagation.[5] To formally define a synthesized attribute, let be a formal grammar, where

  • is the set of non terminal symbols
  • is the set of terminal symbols
  • is the set of productions
  • is the distinguished, or start, symbol

Then, given a string of nonterminal symbols and an attribute name , is a synthesized attribute if all three of these conditions are met:

  • (i.e. is one of the rules in the grammar)
  • (i.e. every symbol in the body of the rule is either nonterminal or terminal)
  • , where (i.e. the value of the attribute is a function applied to some values from the symbols in the body of the rule)

Inherited attributes

An inherited attribute at a node in parse tree is defined using the attribute values at the parent or siblings. Inherited attributes are convenient for expressing the dependence of a programming language construct on the context in which it appears. For example, we can use an inherited attribute to keep track of whether an identifier appears on the left or the right side of an assignment in order to decide whether the address or the value of the identifier is needed. In contrast to synthesized attributes, inherited attributes can take values from parent and/or siblings. As in the following production,

S → ABC

where A can get values from S, B, and C. B can take values from S, A, and C. Likewise, C can take values from S, A, and B.

Special types of attribute grammars

  • L-attributed grammar: inherited attributes can be evaluated in one left-to-right traversal of the abstract syntax tree
  • LR-attributed grammar: an L-attributed grammar whose inherited attributes can also be evaluated in bottom-up parsing.
  • ECLR-attributed grammar: a subset of LR-attributed grammars where equivalence classes can be used to optimize the evaluation of inherited attributes.
  • S-attributed grammar: a simple type of attribute grammar, using only synthesized attributes, but no inherited attributes

See also

References

  1. ^ Knuth 1968, p. 134.
  2. ^ Knuth 1968, p. 132.
  3. ^ a b D. E. Knuth: The genesis of attribute grammars. Proceedings of the international conference on Attribute grammars and their applications (1990), LNCS, vol. 461, 1–12.
  4. ^ "Main".
  5. ^ Knuth 1968, p. 130.

Read other articles:

ميثرا يقتل الثور الميثرائية، وتُعرف أيضًا بالأسرار الميثرائية، هي ديانة رومانية باطنية ترتكز على الإله ميثرا. تأثر هذا الدين بعبادة الإله الزراداشتي ميثرا، لكن الميثراس الإغريقي رُبط بتصور مميز جديد، ويُناقش مستوى الاستمرارية بين الممارسة الفارسية والغريكورومانية.[1&...

 

 

Indian political activist and writer (1883–1966) Savarkar and Veer Savarkar redirect here. For the 2001 Indian film, see Veer Savarkar (film). For the biography, see Savarkar (book). VeerVinayak Damodar SavarkarBorn(1883-05-28)28 May 1883Bhaghur,[1] Nasik district, Bombay Presidency, British India (present-day Maharashtra, India)Died26 February 1966(1966-02-26) (aged 82)Bombay, Maharashtra, IndiaNationalityBritish India (1883-1947) India (1947-1966)Other namesVeer Savarkar...

 

 

Untuk kota di Negros Occidental, lihat Bacolod City. BacolodMunisipalitasNegara FilipinaProvinsiLanao del Norte Koordinat: 8°11′20″N 124°03′00″E / 8.18889°N 124.05000°E / 8.18889; 124.05000 Bacolod adalah munisipalitas yang terletak di provinsi Lanao del Norte, Filipina. Pada tahun 2010, munisipalitas ini memiliki populasi sebesar 19.872 jiwa atau 4.212 rumah tangga. Pembagian wilayah Secara administratif Bacolod terbagi menjadi 16 barangay, yaitu: Alegria ...

ترانزستور ثنائي القطب ذو البوابة المعزولة   النوع ترانزستور ثنائي القطب  الرمز الإلكتروني   تعديل مصدري - تعديل   ترانزستور ثنائي القطبية ذو بوابة معزولة (بالإنجليزية: Insulated-gate bipolar transistor)‏ و يرمز له أيضا ب(IGBT) هو مكون يعتمد أشباه الموصلات يستخدم في الكهرباء ذات الطا

 

 

1982 single by Thin Lizzy Angel of DeathSingle by Thin Lizzyfrom the album Renegade Released1982GenreHard rock, heavy metalLength6:18LabelWarner Bros. Records (USA)Songwriter(s)Phil Lynott, Darren Wharton Angel of Death is a song by rock band Thin Lizzy featured on their Renegade album,[1] released as a single in the United States. The tune peaked at No. 38 on the Mainstream Rock chart.[2] The song was a collaboration between band leader Phil Lynott and Darren Wharton, who had...

 

 

Kirche der Assemblies of God in Dili (Osttimor) Assemblies of God (World Assemblies of God Fellowship) ist eine pfingstliche Denomination mit Sitz in Springfield (Missouri). Eigenen Angaben zufolge verfügte die Organisation im Jahre 2020 über 55,5 Millionen Anhänger.[1] Inhaltsverzeichnis 1 Geschichte 2 Theologie 3 Einfluss auf die Politik 4 Einzelnachweise 5 Weblinks Geschichte Die Vereinigung Assemblies of God bildete sich im April 1914 während eines internationalen Treffens pfi...

روبرت ساكر معلومات شخصية الميلاد 6 يونيو 1989 (العمر 34 سنة)باتون روج الطول 7 قدم 0 بوصة (2.1 م) مركز اللعب وسط الجنسية  كندا الوزن 113 كيلوغرام  الحياة العملية الدوري الرابطة الوطنية لكرة السلة الرقم 50 بلد الرياضة الولايات المتحدة كندا  المسيرة الاحترافية الفرق الآن

 

 

High rise building in Adelaide, South Australia Not to be confused with Grenfell Tower in London. Grenfell CentreAlternative namesOracle House,JLW Building,Black Stump (nickname)General informationArchitectural styleInternationalLocation25 Grenfell Street, Adelaide, South AustraliaConstruction started1973Completed1975Renovated1979HeightTip114 metres (374 ft)Top floor26Technical detailsFloor count27Lifts/elevators8Design and constructionArchitect(s)Cheesman Doley Neighbour & Raffen Ha...

 

 

Arçelik A.Ş.JenisAnonim ŞirketKode emitenTemplat:IMKBIndustriElektronik konsumen, Peralatan rumah tanggaGenreElektronikDidirikan1955; 68 tahun lalu (1955)PendiriVehbi KoçKantorpusatGolden Horn, Sütlüce, Beyoğlu, IstanbulWilayah operasiWorldwideTokohkunciRahmi Koç (Ketua) Hakan Bulgurlu (Direktur Utama)[1]ProdukMonitor komputer, televisis, pemutar DVD, pemutar Blu-ray, sistem Home Cinemaproyektor film, laptop, drive optik, lemari es, mesin cuci, penyedot debu, pendingin ud...

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: Parasuramalingeswarar Temple – news · newspapers · books · scholar · JSTOR (August 2018) (Learn how and when to remove this template message) Hindu temple in Tamil Nadu, India Parasuramalingeswarar TempleShri Parasuramalingeswarar Temple @ AyanavaramReligionAff...

 

 

2004 Spanish drama film The Sea InsideTheatrical poster by Toni Galingo.Directed byAlejandro AmenábarWritten byAlejandro AmenábarMateo GilProduced byAlejandro AmenábarFernando BovairaStarringJavier BardemBelén RuedaLola DueñasMabel RiveraCelso BugalloCinematographyJavier AguirresarobeEdited byAlejandro AmenábarMusic byAlejandro AmenábarProductioncompaniesSogepaqUGC ImagesEyescreenDistributed byWarner Sogefilms (Spain)[1]UGC Fox Distribution (France)[1]Lucky Red (Italy)&...

 

 

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: The Immortals 1995 film – news · newspapers · books · scholar · JSTOR (June 2019) (Learn how and when to remove this template message) 1995 American filmThe ImmortalsPosterDirected byBrian GrantWritten byKevin Bernhardt Elie SamahaProduced byElie SamahaSta...

Former American esports organization This article may contain excessive or inappropriate references to self-published sources. Please help improve it by removing references to unreliable sources where they are used inappropriately. (April 2019) (Learn how and when to remove this template message) Team CoastDivisionsLeague of LegendsDota 2SmiteHearthstoneFoundedJanuary 4, 2013 (2013-01-04)FoldedOctober 14, 2016 (2016-10-14)Team historyGood Game University (2013)Te...

 

 

List of events ← 1591 1590 1589 1592 in India → 1593 1594 1595 Centuries: 15th 16th 17th 18th Decades: 1570s 1580s 1590s 1600s 1610s See also:List of years in IndiaTimeline of Indian history Events from the year 1592 in India. Years in India: 1589 1590 1591 1592 1593 1594 1595 Centuries: 15th century · 16th century · 17th century Decades: 1560s 1570s 1580s 1590s 1600s 1610s 1620s Years: 1589&...

 

 

British rugby league season Super League XLeagueSuper LeagueDuration28 RoundsTeams12Highest attendance25,004 Wigan Warriors vs St. Helens (25 March) Lowest attendance2,682 Salford City Reds vs Huddersfield Giants (2 July)Attendance1,492,464 (average 8,884)Broadcast partnersSky Sports2005 SeasonChampionsBradford Bulls4th Super League title6th British titleLeague LeadersSt. HelensMan of Steel Jamie LyonTop point-scorer(s) Paul Deacon (322)Top try-scorer(s) Mark Calderwood (27)New franchiseAward...

1981 film For the 1994 short film, see Eisha Marjara. The Incredible Shrinking WomanTheatrical release posterDirected byJoel SchumacherWritten byJane WagnerBased onThe Shrinking Manby Richard MathesonProduced byHank MoonjeanStarring Lily Tomlin Charles Grodin Ned Beatty CinematographyBruce LoganEdited byJeff GoursonMusic bySuzanne CianiDistributed byUniversal PicturesRelease date January 30, 1981 (1981-01-30) (United States) Running time88 minutesCountryUnited States Langua...

 

 

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: Imjingang Station – news · newspapers · books · scholar · JSTOR (June 2019) (Learn how and when to remove this template message) K337 임진강Imjingang Korean nameHangul임진강역Hanja臨津江驛Revised RomanizationImjingangnyeokMcCune–ReischauerRimjin'ga...

 

 

Canadian television game show 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: Deal or No Deal Canada – news · newspapers · books · scholar · JSTOR (October...

Hereditary Countess Palatine of Neuburg Anne Catherine Constance VasaHereditary Countess Palatine of NeuburgPortrait by Johannes Spilberg, ca. 1648.Born(1619-08-07)7 August 1619WarsawDied8 October 1651(1651-10-08) (aged 32)CologneBurialChurch of the Jesuits, DüsseldorfSpouse Philip William, Hereditary Count Palatine of Neuburg ​ ​(m. 1642)​HouseVasaFatherSigismund III VasaMotherConstance of Austria Anna Catherine Constance Vasa (Polish: Anna Katarzyna ...

 

 

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 relies largely or entirely on a single source. Relevant discussion may be found on the talk page. Please help improve this article by introducing citations to additional sources.Find sources: Felix Galimir – news · newspapers · books · scholar · JSTOR (April 2022) You can help expand this...

 

 

Strategi Solo vs Squad di Free Fire: Cara Menang Mudah!