0
$\begingroup$

I was going through the text Compilers: Principles, Techniques and Tools by Ullman et. al where I came across the following claim:

L-attributed definitions include all syntax-directed definitions based on LL(1) grammars.

What is the intuition or logic behind this statement?

In the later sections they show that L attributed grammars can be easily implemented by a DFS search algorithm of the parse tree (and hence easily by a predictive parser [recursive/non recursive]). $^\dagger$

Is it so that since LL(1) grammars can also be parsed by predictive parser and by the logic of $\dagger$, the authors make the claim?

$\endgroup$

1 Answer 1

1
$\begingroup$

L-attributed definitions are definition whose attributes can be evaluated in depth-first order (as they say in the first sentence).

The statement "L-attributed definitions include all syntax-directed definitions based on LL(1) grammars" is perhaps a bit subtle. It's not saying that the two sets of definitions are the same; rather, that syntax-directed definitions "based on LL(1) grammars" are a subset of L-attributed definitions.

That's true because the predictive parser based on the LL(1) grammar visits the parse tree in strictly depth-first order. This was already noted in Designing a Predictive Parser in Section 2.4 of the text book, which goes on to build a recursive-descent parser illustrating how this works.

$\endgroup$
1
  • $\begingroup$ Thanks for the help... $\endgroup$ Commented Mar 29, 2021 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.