The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 4 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Implement each of your SDD"s of Exercise 5.4.4 as a recursive-descent parser in the style of Section 5.5.1.
Exercise 5.4.4 : Write L-attributed SDD"s analogous to that of Example 5.19 for the following productions, each of which represents a familiar flow-of-control construct, as in the programming language C. You may need to generate a three-address statement to jump to a particular label L, in which case you should generate goto L.

Note that any statement in the list can have a jump from its middle to the next statement, so it is not sufficient simply to generate code for each statement in order.
5.5.1 Translation During Recursive-Descent Parsing
A recursive-descent parser has a function A for each nonterminal A, as discussed in Section 4.4.1. We can extend the parser into a translator as follows:
a) The arguments of function A are the inherited attributes of nonterminal A.
b) The return-value of function A is the collection of synthesized attributes of nonterminal A.
In the body of function A, we need to both parse and handle attributes:
1. Decide upon the production used to expand A.
2. Check that each terminal appears on the input when it is required. We shall assume that no backtracking is needed, but the extension to recursive- descent parsing with backtracking can be done by restoring the input
position upon failure, as discussed in Section 4.4.1.
3. Preserve, in local variables, the values of all attributes needed to compute inherited attributes for non-terminals in the body or synthesized attributes for the head nonterminal.
4. Call functions corresponding to non-terminals in the body of the selected production, providing them with the proper arguments. Since the underlying SDD is L-attributed, we have already computed these attributes and stored them in local variables.
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll