next up previous
Next: Exercise. Up: No Title Previous: No Title

Computer Science 456/656 Spring 1999. Parsing.

Consider the unambiguous context-free grammar G, whose productions are given as follows:

0. tex2html_wrap_inline384

1. tex2html_wrap_inline386

2. tex2html_wrap_inline388

Let L=L(G). The problem is to design a shift-reduce parser for G. Note that G is unambiguous.

Although the textbook does not mention it, we would like the parser to output the derivation of any input string in L. In this case, the derivation will be the so-called ``reverse rightmost'' derivation of the string. For example, if the input string is tex2html_wrap_inline398 , then the output of the parser should be 11211220.

Here is the table of the transitions that we want our parser to make. Note that we do not concern ourselves with states at this time, and we allow the popping of any number of symbols in one step. Nor do we concern ourselves with lookahead, because we have not yet figured out how to use lookahead as a guide. We call this machine, which always knows what to do without having any memory or lookahead, tex2html_wrap_inline402 .

tex2html_wrap_inline404

We now look at the sequence of configurations that occurs when tex2html_wrap_inline402 parses tex2html_wrap_inline398 .

tex2html_wrap_inline410

We now design a deterministic lookahead parser tex2html_wrap_inline412 that emulates the action of tex2html_wrap_inline402 . tex2html_wrap_inline412 can look ahead (``peek'') without reading.

tex2html_wrap_inline412 has 8 states. We write just numbers for the states, for example, 4 symbolizes state tex2html_wrap_inline420 . It helps to write an explanation for each state in words.

tabular237

If the entry in the ``peek'' column is empty, that means that tex2html_wrap_inline412 does not need to look ahead to perform that transition. We allow tex2html_wrap_inline412 to pop any number (zero or more) of symbols. tex2html_wrap_inline412 is deterministic, but is not yet a DPDA according to the formal rules, because those rules require that exactly one symbol be popped at every step.

tex2html_wrap_inline442



next up previous
Next: Exercise. Up: No Title Previous: No Title

Lawrence L Larmore
Mon Mar 15 14:23:25 PST 1999