Preview

Attribute grammar

Good Essays
Open Document
Open Document
591 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Attribute grammar
What is the difference between a synthesized attribute and an inherited attribute? Define each of those terms.

A synthesized attribute is defined for a node v in terms of the attributes of the children of v. Any attribute that is not synthesized is called inherited.

Sometimes it is desirable to use only synthesized attributes in your parser. Is it always possible to do that, even if your semantics requires inherited attributes? If so, how can you deal with complex semantics while only using synthesized attributes in the parser. If not, what prevents you from using only synthesized attributes?

You can use only synthesized attributes in the parser by building syntax trees there, and passing those syntax trees to semantic processing routines. The semantic processing is free to make many passes over the syntax trees, even though the parser makes only one bottom-to-top traversal of the parse tree.

Exercise 6.6 of the text contains a grammar that describes binary trees where each node of the tree has an integer label. It discusses an ordering requirement that is the same one required by binary search trees. Solve that exercise.

Solved in class using synthesized attributes. Think about what you need to remember about each subtree. It suffices to remember the smallest value and largest value in the subtree, and whether the subtree obeys the ordering requirements. Attribute equations then follow easily.

You are given the following (ambiguous) grammar for expressions.

expr -> expr + expr expr -> expr * expr expr -> NUM expr -> VAR where NUM and VAR are tokens. The lexer provides an attribute NUM.val that is the (integer) value of a NUM token. It also provides an attribute VAR.name that is the name of a variable. You would like to translate these expressions into instructions for a stack machine. The stack machine has the following instructions. Push the value of the variable at offset k onto the stack
PUSH_INT k Push

You May Also Find These Documents Helpful

  • Satisfactory Essays

    13 T | A transient dependency is where an attribute depends on another attribute for its meaning and not on the key.…

    • 313 Words
    • 1 Page
    Satisfactory Essays
  • Good Essays

    79) The ________ property appears in parentheses so it will appear at the top of the alphabetical Property list.…

    • 3668 Words
    • 15 Pages
    Good Essays
  • Satisfactory Essays

    Attribute-Based Programming: Attributes assist you to add declarative information in your programs. This information can then be queried at runtime using reflection.…

    • 485 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    poop

    • 796 Words
    • 4 Pages

    2. An attribute is a property that applies to a given entity. There can be many attributes for an entity.…

    • 796 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Ap Psychology Quiz

    • 564 Words
    • 3 Pages

    |5. |What is the term for a characteristic or attribute that can assume different values? |…

    • 564 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Each new class obtained through inheritance is known as derived class, and classes from which it derives are called base classes. In addition, each derived class can be used as a base class for a new derived class. And each derived class can be one or more base classes. In the latter case are referred to bypass manifold.…

    • 290 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Bloom's Taxonomy

    • 374 Words
    • 2 Pages

    Synthesize in the context of the Bloom’s Taxonomy and Granello’s article refers to the evaluation of information in a way that makes the information new to the writer (Darcy, 2001). However, the information gathered is given merit as fact. It is not fully developed into the writer’s own arguments, but is presented as truth. Synthesize is on the higher level of Bloom’s Taxonomy but it lack the use of fully developed arguments that use sources as support to the writers own ideas.…

    • 374 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Copro 2 Reviewer 2014

    • 557 Words
    • 3 Pages

    Object Oriented Programming is a programming paradigm the breaks down a programming task into series of interactions among different entities or object.…

    • 557 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    5. Synthesis: arrange, assemble, collect, compose, construct, create, design, develop, formulate, manage, organize, plan, prepare, propose, set up, write.…

    • 440 Words
    • 2 Pages
    Powerful Essays
  • Powerful Essays

    Constructor:- Constructor is like a method which may contain some certain set of statement, But constructor does not have any Return Type and it will have the same name as the Class Name.…

    • 550 Words
    • 3 Pages
    Powerful Essays
  • Powerful Essays

    Bibliography: Crystal, D. (2003). A Dictionary of Linguistics and Phonetics. Blackwell Publishing ltd. Lobner, S. (2002). Understanding Semantics. Arnold, London. Lyons, J. (1977) Semantics. Cambridge University Press. Palmer, F.R. (1981) Semantics. Cambridge U P. Quirk, R., Greenbaum, S., and Svartvik (1985). A Comprehensive Grammar of the English Language. . Longman group ltd. Oxford Advanced learners Dictionary. (1989). Oxford University Press.…

    • 3586 Words
    • 15 Pages
    Powerful Essays
  • Good Essays

    Macro

    • 5801 Words
    • 24 Pages

    References: [1] [2] R. Ierusalimschy, L. H. de Figueiredo, W. Celes, “Lua-An Extensible Extension Language”, Software: Practice & Experience 26 pp 635-652 #6 (1996). L. H. de Figueiredo, R. Ierusalimschy, W. Celes, “The Design and Implementation of a Language for extending applications”, Proceedings of XXI Brazilian Seminar on Software and Hardware, pp 273-283 (1994). R. Ierusalimschy, L. H. de Figueiredo, W. Celes, “The Evolution of an Extension Language: A History Of Lua”, Proceedings of V Brazilian Symposium on Programming Languages B-14--B-28 (2001). L. H. de Figueiredo, R. Ierusalimschy, W. Celes, “Lua: An Extensible Embedded Language a Few Metamechanisms Replace a Host of Features”, Dr. Dobb 's Journal 21 #12 pp 26-33. [DDJ] (Dec 1996) J. Gracia-Martin, M. Sutil-Martin, “The Extreme Compiling Pattern Language” Associative Array at Wikipedia, “http://en.wikipedia.org/wiki/Associative_array” R. Ierusalimschy, L. H. de Figueiredo, W. Celes, “Lua 5.0 Reference Manual”, Technical Report MCC-14/03, PUC-Rio, 2003 L. H. de Figueiredo, R. Ierusalimschy, W. Celes, “The Design And Implementation Of A Language For Extending Applications”, Proceedings of XXI Brazilian Seminar on Software and Hardware pp 273-283 (1994). Len Bass, Paul Clements, and Rick Kazman; “Software Architecture in Practice”, second edition, Apr 9, 2003, Addison-Wesley Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, and Michael Stahl; “Pattern-Oriented Software Architecture: A System of Patterns” 1996, Wiley & Sons Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides; “Design Patterns” 1994, Addison-Wesley “The Kepler Project” at http://www.keplerproject.org, 2004, Fábrica Digital and PUC-Rio “tolua” at http://www.tecgraf.puc-rio.br/~celes/tolua/ , 2004, Tecgraf/PUC-Rio “IUP” http://www.tecgraf.org/iup, 2004, Tecgraf/PUC-Rio “LuaSocket” at http://www.tecgraf.org/luasocket, 2004, Fábrica Digital and PUCRio 17…

    • 5801 Words
    • 24 Pages
    Good Essays
  • Powerful Essays

    Finite Automata

    • 26011 Words
    • 105 Pages

    The finite-state machine (FSM) and the pushdown automaton (PDA) enjoy a special place in computer science. The FSM has proven to be a very useful model for many practical tasks and deserves to be among the tools of every practicing computer scientist. Many simple tasks, such as interpreting the commands typed into a keyboard or running a calculator, can be modeled by finite-state machines. The PDA is a model to which one appeals when writing compilers because it captures the essential architectural features needed to parse context-free languages, languages whose structure most closely resembles that of many programming languages. In this chapter we examine the language recognition capability of FSMs and PDAs. We show that FSMs recognize exactly the regular languages, languages defined by regular expressions and generated by regular grammars. We also provide an algorithm to find a FSM that is equivalent to a given FSM but has the fewest states. We examine language recognition by PDAs and show that PDAs recognize exactly the context-free languages, languages whose grammars satisfy less stringent requirements than regular grammars. Both regular and context-free grammar types are special cases of the phrasestructure grammars that are shown in Chapter 5 to be the languages accepted by Turing machines. It is desirable not only to classify languages by the architecture of machines that recognize them but also to have tests to show that a language is not of a particular type. For this reason we establish so-called pumping lemmas whose purpose is to show how strings in one language can be elongated or “pumped up.” Pumping up may reveal that a language does not fall into a presumed language category. We also develop other properties of languages that provide mechanisms for distinguishing among language types. Because of the importance of context-free languages, we examine how they are parsed, a key step in…

    • 26011 Words
    • 105 Pages
    Powerful Essays
  • Satisfactory Essays

    Comounding and Acronym

    • 773 Words
    • 4 Pages

    Compounding is the morphological operation that-in general-puts together two free forms and gives rise to a new word. The importance of compounding stems from the fact that there are probably no languages without compounding, and in some languages (e.g. Bahasa Melayu) it is the major source of new word formation. Compounds are particularly interesting linguistic constructions for a number of reasons. First, they constitute an anomaly among grammatical constructions because they are “words,” but at the same time exhibit a type of “internal syntax.” Compounds, furthermore, represent a contact point between several crucial linguistic and non-linguistic notions such as syntagmatic and paradigmatic relationships, syntax and morphology, and linguistic knowledge and pragmatic knowledge. As for the relationship between syntax and morphology, it has often been observed that compounds are the morphological constructions that are closest to syntactic constructions, to the extent that there is no general agreement on which component of the grammar is responsible for their formation.…

    • 773 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Bloomfield

    • 852 Words
    • 3 Pages

    Transformational- Generative Grammar • The innateness hypothesis • What Is a generative grammar • The Classical Theory • The Standard theory • The Extended Standard Theory • Main features of TG Grammar • Later theories…

    • 852 Words
    • 3 Pages
    Good Essays

Related Topics