13.11.2014 Views

Introduction to Computational Linguistics

Introduction to Computational Linguistics

Introduction to Computational Linguistics

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

22. Shift–Reduce–Parsing 88<br />

the string, and <strong>to</strong> the right the last rule that we applied):<br />

(218)<br />

S<br />

−<br />

cCZ 1<br />

ccZ 10<br />

ccaBYZ 5<br />

ccabYZ 9<br />

ccabcYZ 7<br />

ccabccZ 8<br />

ccabccaBA 2<br />

ccabccabA 9<br />

ccabccaba 8<br />

The PDA is parsing the string as follows. (We show the successful run.) The<br />

stack is initialized <strong>to</strong> S (Line 1). It reads c and deletes S, but puts first Z and then<br />

C on it. The stack now is ZC (leftmost symbol is at the bot<strong>to</strong>m!). We are in Line<br />

2. Now it reads c and deletes C from stack (Line 3). Then it reads a and pops<br />

Z, but pushes first Z, then Y and then B (Line 4). Then it pops B on reading b,<br />

pushing nothing on <strong>to</strong>p (Line 5). It is clear that the strings <strong>to</strong> the left represent the<br />

following: the terminal string is that part of the input string that has been read,<br />

and the nonterminal string is the stack (in reverse order). As said, this is just one<br />

of the possible runs. There is an unsuccessful run which starts as follows. The<br />

stack is S. The machine reads c and decides <strong>to</strong> go with Rule 0: so it pops C but<br />

pushes only C. Then it reads c, and is forced <strong>to</strong> go with Rule 10, popping off C,<br />

but pushing nothing on<strong>to</strong> it. Now the stack is empty, and no further operation can<br />

take place. That run fails.<br />

Thus, we have shown that context free languages can be recognized by PDAs<br />

by empty stack. The converse is a little trickier, we will not spell it out here.<br />

22 Shift–Reduce–Parsing<br />

We have seen above that by changing the grammar <strong>to</strong> Greibach Normal Form we<br />

can easily implement a PDA that recognizes the strings using a pushdown of the<br />

nonterminals. It is not necessary <strong>to</strong> switch <strong>to</strong> Greibach Normal Form, though. We<br />

can translate directly the grammar in<strong>to</strong> a PDA. Alos, grammar and au<strong>to</strong>ma<strong>to</strong>n are<br />

not uniquely linked <strong>to</strong> each other. Given a particular grammar, we can define quite

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!