20100921

20100921 - RHS of productions The algorithm is based on...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
============================ CS 441 Fall 2010 -- JWJ Pre-class notes - do not distribute Thursday, September 21, 2010 ============================ Scope: ------ Recursive Descent Parser and LL(1) context-free grammars FIRST and FOLLOW Sets Removing left recursion (reading assignment -- Section 3.13.1 in our textbook)) Outline: ------- Recursive Descent Parsing and its CF grammar requirements Problems with left recursion FIRST and FOLLOW sets and their role in parsing Elimination of left-recursion (this is a reading assignment): ----------------------------- A --> A alpha | beta is replaced with A --> beta A' A' -- alpha A' | epsilon For example: left-recursive after removing left recursion E --> E + T | T E --> T E' E' --> + T E' | epsilon T --> T * F | F T --> F T' T' --> * F T' | epsilon F --> (E) | id | num F --> (E) | id | num FIRST sets: ---------- Information about terminals that can be derived from nonterminals and
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: RHS of productions. The algorithm is based on computing nullable nonterminals and then setting systems of equations. FIRST sets can be calculated for all strings over a given alphabet. FIRST sets include terminals and epsilon. Input: a CFG G Output: FIRST sets for nonterminals (they can be used to compute FIRST for RHS) If X is a terminal, then FIRST(X) is X. If X derives the empty string then add epsilon to FIRST(X). If X is nonterminal and X --> Y_1Y_2 . .. Y_k is a production, then add FIRST(Y_1) . .. FIRST(Y_{i+1}) to FIRST(X) if FIRST(Y_1 . .. FIRST(Y_i) contain the empty string epsilon. If i = k then add the empty string epsilon to FIRST(X).-------An additional handout for the FIRST and FOLLOW sets has been distributed in class. Please request a copy if you do not have one. Pending assignments:- PA 1 (due this Friday) and hw3 (due 9/23) and hw4 (due 9/28)...
View Full Document

This document was uploaded on 12/14/2010.

Page1 / 2

20100921 - RHS of productions The algorithm is based on...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online