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, 3 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
The following grammar represents selection statements in C. It is not parable by recursive descent (or equivalently, by a table-driven parser), because with look ahead if, we cannot tell which of the first two productions to use. Left-factor the grammar to make it parable by the algorithms of this section and Section 11.6. Hint: When you left factor, you get a new syntactic category with two productions. One has body o; the other has a body that begins with else. Evidently, when else is a look ahead, the second production can be the choice. For no other look ahead can it be the choice. But, if we examine on what look heads it might make sense to expand by the production with body o, we discover that these look ahead symbols include else. However, we may arbitrarily decide never to expand to o when the look ahead is else. That choice corresponds to the rule that “an else matches the previous unmatched then.” It is thus the “correct” choice. You might wish to find an example of an input where expanding to o with look ahead else allows the parser to complete the parse. You will discover that in any such parse, the constructed parse tree matches an else with the “wrong” then.

Hel-----------lo -----------Sir-----------/Ma-----------dam----------- -----------Th-----------ank----------- Yo-----------u f-----------or -----------usi-----------ng -----------our----------- we-----------bsi-----------te -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill-----------