Questions tagged [attribute-grammars]

22 questions
7
votes
1 answer

Can abstract syntax trees be unparsed in subexponential time?

Abstract problem description The way I see it, unparsing means to create a token stream from an AST, which when parsed again produces an equal AST, i.e. parse(unparse(AST)) = AST should hold. This is the equal to finding a valid parse tree which…
Stefan K.
  • 171
  • 2
5
votes
2 answers

Bottom-Up Evaluation of Inherited Attributes

I came across $2$ translation schemes of Syntax Directed Translation (SDT) in compilers which are as follows : Using a top-down translation scheme, we can implement any $L$-attributed definition based on a $LL(1)$ grammar. Using a bottom-up…
Garrick
  • 492
  • 1
  • 7
  • 24
3
votes
0 answers

Generating valid sentence with respect to attribute grammar

Given a context free grammar, both the algorithm for determining whether a given string is grammatical and the algorithm for producing a grammatical string in that language are well understood. To produce a grammatical string, just keep replacing…
2
votes
0 answers

Intuition on what an attribute grammar can achieve

I have seen attribute grammars for a small handful of tasks: Parsing simple arithmetical expressions Type checking Checking that a variable is initialized anbncn (seems to be a favorite toy example)... and that's about it. What are some…
2
votes
1 answer

Full circularity vs strong circularity for attribute grammars

Attributes of an attribute grammar can have a circular dependency. In my compiler construction course I learned, that there are two types of circularity for attribute grammars: full circularity can be checked in exponential time strong circularity…
2
votes
1 answer

Calculating attributes' values in the semantic analysis stage

I'm reading through the book : "Compiler Construction: Principles and Practice". In chapter 6 : semantic analysis, an example about attribute grammars is given. The example is of a simple integer arithmetic expressions (I posted a picture because…
2
votes
2 answers

Ambiguity vs. context-sensitivity

It is said that attributes supply some semantic information to the grammar. Meantime, the same attributes let you to resolve ambiguities. Text books agree that it is worth haveing a CF grammar which admits ambiguities because the ambiguities will go…
2
votes
0 answers

Flaw with Knuth original attribute grammar paper

Knuth's original attribute grammar paper (title: Semantics of Context-Free Languages) apparently had a flaw where circularity is always detected but some noncircular AGs may be reported to be circular. Knuth later constructed an exact algorithm…
Node.JS
  • 151
  • 1
  • 12
1
vote
1 answer

Writing a Context-Free-Grammar using Backus Naur Form for a for-loop?

I'm pretty new to CFG, and I've tried out some samples as well. As of now I'm trying this for-loop to write it in CFG using BNF: Start{ int z = 20; for(int b = 0; b < 5; b++) { //some statement } } Attempted BNF:
1
vote
0 answers

What is difference between LAG (Left Atrributed Grammar) and LATG (Left Attributed Translation Grammar)?

I am reading Compilers and am unable to understand difference between these two terms. I could not find any text which has clearly mentioned how they differ but these two separate terms are being used. Can someone please explain me?
Abhishek Kumar
  • 271
  • 2
  • 3
1
vote
3 answers

Attribute grammars: How are attributes implemented?

I've read about attribute grammars, but I haven't found out, how are the attributes often implemented? To me they scream objects (of classes), but they could be also variables. But are there any general rules as to how the attributes should be…
mavavilj
  • 579
  • 7
  • 23
1
vote
2 answers

How can this grammar parse such an input?

I've an example which I simply don't get at all. Implement an attributed grammar that checks that either the word ends in $b$ or each prefix of the word contains at least as many $b$s as $a$s E.g. the word $bbbbaabaabaa$ is allowed but…
1
vote
0 answers

How do bottom up parser evaluate things that need an inherited attribute?

I learned that Bottom up parsers use only synthesized attributes to evaluate semantics. Which makes sense considering that it would be very hard to evaluate an inherited attribute in bottom up parsing. So, can bottom up parser evaluate pretty much…
1
vote
1 answer

In syntax-directed definition, terminals are assumed to have synthesized attributes only, definition doesn't provide any semantic rules for terminals?

I was going through the text Compilers: Principles,Techniques and Tools by Ullman et. al. where I came across the claim in the question by authors. Below is the definition and following it is the claim by the authors. Form of a Syntax-Directed…
Abhishek Ghosh
  • 1,184
  • 9
  • 24
1
vote
2 answers

How to evaluate a Kleene's Closure through CFG and attribute grammars

For a CFG with the production rules that can represent a regular expression. How can one calculate all the set of strings that regular expression would produce. For T = {a, b,*,(,)} and an arbitrary production rule I created to represent a simple…
1
2