Thursday, June 10, 2010

FIRST AND FOLLOW FUNCTIONS

FIRST FUNCTION - SIMPLIFIED

Definition : FIRST(a) is the set of terminals that begins with the strings derived from a.

ALGORITHM (PROCEDURE) :

To compute FIRST(X) , the following are the rules

1 . If X is a terminal then FIRST(X) = {X}
Example: F -> (E) | id
We can write it as FIRST(F) -> { ( , id }
2. If X is a non terminal like E -> T then to get
FIRST(E) substitute T with other productions until you get a terminal as the first symbol.

3. If X -> ε then add ε to FIRST(X).