884 views
0 votes
0 votes
If the grammar has only S-attributed  semantic definitions,  in a top down parser we will add the semantic action at the end of production and it will we executed when we reach there, In a bottom up parser we will perform semantic action when reduction occurs.

I understood the above part, But when we have L-Attributed semnatic rules how and when they will get executed?  please explain or provide a source to read.

2 Answers

0 votes
0 votes

@jaswanth431

S-attributed SDT If an SDT uses only synthesized attributes, it is called as S-attributed SDT.

These attributes are evaluated using S-attributed SDTs that have their semantic actions written after the production (right hand side)...

S-attributed SDT As depicted above, attributes in S-attributed SDTs are evaluated in bottom-up parsing, as the values of the parent nodes depend upon the values of the child nodes…

 

L-attributed SDT This form of SDT uses both synthesized and inherited attributes with restriction of not taking values from right siblings. In L-attributed SDTs, a non-terminal can get values from its parent, child, and sibling nodes….

As in the following production S → ABC S can take values from A, B, and C (synthesized).

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

No non-terminal can get values from the sibling to its right…

 

Attributes in L-attributed SDTs are evaluated by depth-first and left-to-right parsing manner. L-attributed SDT We may conclude that if a definition is S-attributed, then it is also L-attributed as L-attributed definition encloses S-attributed definitions...

 

1. https://cse.iitkgp.ac.in/~bivasm/notes/SDD.pdf 

 

2. https://nptel.ac.in/content/storage2/courses/106108113/module4/Lecture12.pdf 

 

3. https://www.cse.iitk.ac.in/users/swarnendu/courses/spring2020-cs335/Semantic%20Analysis.pdf 

 

4. https://www.csd.uwo.ca/~mmorenom/CS447/Lectures/Translation.html/node4.html 

 

5. https://gateoverflow.in/290789/Madeeasy-series-compiler-design-syntax-directed-translation 

 

6. https://gateoverflow.in/187007/L-and-s-attribute 

 

7. https://gateoverflow.in/169340/L-attributed-definition

 

 

 

0 votes
0 votes
Depth first evaluation is used in L attributes.

Related questions

0 votes
0 votes
1 answer
2
0 votes
0 votes
1 answer
3
atul_21 asked Nov 28, 2017
370 views