You are on page 1of 13

Search This Website

Computer Revolution (www.comrevo.com) Search

Home General Compiler LEX & YACC GATE Cloud Computing CUDA MPI OpenCL Lisp OpenMP Web Designing Linux

Database Networking Data Structures Java Android Multi-Threading Blogging Tips YouTube Tips Vocabulary PICT PPL Contact

Guest Blogging Higher Studies Portal Job Portal Subscribe Youtube Channel Amazon Links

Number of Wednesday, 5 August 2015 Subscribe YouTube Channel


Posts on
Various Topics How to find FIRST and FOLLOW of a grammar with examples Comrevo

Abbreviations in YouTube 1K
Computer In this post, we will see how to
Science (1) find FIRST and FOLLOW of a grammar. I
Amazon Affiliate have also given some examples for better
Program (1) understanding.
Amazon Links Total Pageviews
Summary (2)
What is FIRST of a Non-Terminal of a
Android (19) Grammar: 436,916
Android App A Non-terminal can generate a
Development sequence of terminals(non-empty string) or
(13) Subscribe YouTube Channel
empty string. The collection of initial terminal
Applet (4) Comrevo
of all these strings is called a FIRST of a Non-
YouTube 1K
Blogging Tips terminal of a Grammar.
(32)

C Plus Plus
Programming
(17)

C Programming
(10)

Cloud Popular Posts


Computing (5)
LEX YACC program to evaluate arithmetic
Compiler (27) expression ( LEX and YACC programs for
arithmetic expression evaluation )

Cuda Programming

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Computer Watch following Video: CUDA program to add two matrices
Networks (4)
Java Swing Program To Add Two Numbers |
CUDA (16) How To Find First and Follow in Compiler Design … Java Swing program For Addition of Two
Watch later Share Numbers
Data Structures
(22) Interview Questions on CUDA Programming

Database (17) Cuda program for addition of two one


dimensional arrays
Dia Software (1)
Decomposition Techniques in Parallel
Fedora (2) Computing | Recursive, Data, Exploratory,
Speculative
GATE (6)
Cuda program for multiplication of two matrices
General (64)
How To Add Image in Java Swing JFrame
Google Forms using JLabel
(4)
OpenMP Program for Array Addition
Guest Blogging
(2) Watch on
High
Performance Watch on YouTube: https://www.youtube.com/watch?v=rnzGbQ3VjMU Like Facebook Page for Updates
Computing (62)

How To Write
Blog (15) (say, LHS stands for Left Hand Side of grammar production, RHS stands for Right Hand
Java (80) Side of grammar production and X is any Non-Terminal in grammar)
LEX & YACC (8)
How to find set FIRST(X):
Linux (8)
For all productions whose LHS is X,
Lisp (1) 1. If RHS starts with terminal, then add that terminal to the set FIRST(X).
Mathematics (1) ϵ ϵ
2. If RHS is , then add to the set FIRST(X).
MPI (3)
3. If RHS starts with Non-Terminal(say Y), then add FIRST(Y) to the set FIRST(X). If

MS Excel
ϵ
FIRST(Y) includes , then, also add FIRST(RHS except Y) to the set FIRST(X).
Formulas &
Functions (5)

Multithreading What is FOLLOW of a Non-Terminal of a Grammar:


(11)
In a derivation process, the collection of initial terminal(i.e. FIRST) of a string
My Vlogs (34) which follows Non-terminal, is called FOLLOW of that Non-terminal.
Mysql (7) For finding FOLLOW set of a Non-Terminal, check in RHS of all productions
which consist of that Non-Terminal.

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Nanded City
Pune (5)
How to find set FOLLOW(X):
Networking (10) 1. If X is "Start" symbol, then add $ to the set FOLLOW(X). (Reason: Each string
OPENCL (1) generated from grammar is assumed that it ends in $. For e.g. abc$ or a+b$. As that string
can be generated from the Start symbol, Start symbol is followed by $).
OPENMP (16)
2. If in any RHS, X is followed by terminal (say t), then add t to the set FOLLOW(X).
OpenMPI (3)
ϵ
3. If in any RHS, X is followed by Non-terminal (say Y), then add FIRST(Y) except to
Parallel
Computing (46)
ϵ
the set FOLLOW(X). If FIRST(Y) contains , then you have to also add FIRST of remaining
part of RHS after Y to the set FOLLOW(X). If remaining part of RHS after Y is empty, then
PPL (57) add FOLLOW(LHS) to the set FOLLOW(X).
SDL (2) 4. If X is the last symbol in any RHS (For e.g. Z->wX), then add FOLLOW(LHS) i.e.
Skill FOLLOW(Z) to the set FOLLOW(X). (Reason: RHS is derived from LHS. So whatever
Development follows RHS, also follows LHS. As X is last symbol in RHS, FOLLOW(X) includes
Lab (30)
FOLLOW(LHS)).
Socket
Programming (3)

SQL (4) Examples:


Swing (10)
1. Grammar:
Thread Pool (3)

Ubuntu (8)
S->xyz/aBC
Unboxing & B->c/cd
Review (1)
C->eg/df
Vedic
Mathematics (1)
FIRST(S)={x,a}
Vocabulary (1)
FIRST(B)={c}
Website FIRST(C)={e,d}
Designing (19)

Wine (2) FOLLOW(S)={$}


Youtube (16) FOLLOW(B)={e,d}
YouTube Tips FOLLOW(C)={$}
(16)
2. Grammar:

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
S->ABCDE
A->a/ ϵ
B->b/ ϵ
C->c
D->d/ ϵ
E->e/ ϵ
FIRST(S)={a,b,c}
FIRST(A)={a, } ϵ
FIRST(B)={b, } ϵ
FIRST(C)={c}
FIRST(D)={d, } ϵ
FIRST(E)={e, } ϵ
FOLLOW(S)={$}
FOLLOW(A)={b,c}
FOLLOW(B)={c}
FOLLOW(C)={d,e,$}
FOLLOW(D)={e,$}
FOLLOW(E)={$}

3. Grammar:

S->AB
A->ϵ
B->ϵ
ϵ
FIRST(S)={ }
ϵ
FIRST(A)={ }
ϵ
FIRST(B)={ }

FOLLOW(S)={$}
FOLLOW(A)={$}
FOLLOW(B)={$}

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
4. Grammar:

S->Bb/Cd
B->aB/ ϵ
C->cC/ ϵ
FIRST(S)={a,b,c,d}
FIRST(B)={a, }ϵ
FIRST(C)={c, }ϵ
FOLLOW(S)={$}
FOLLOW(B)={b}
FOLLOW(C)={d}

5. Grammar:

S->(S)/ ϵ
FIRST(S)={(, }ϵ
FOLLOW(S)={$,)}

6. Grammar:

S->AB/C
A->D/a/ ϵ
B->b
C->ϵ
D->d

FIRST(S)={d,a,b, } ϵ
FIRST(A)={d,a, } ϵ
FIRST(B)={b}

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
FIRST(C)={ }ϵ
FIRST(D)={d}

FOLLOW(S)={$}
FOLLOW(A)={b}
FOLLOW(B)={$}
FOLLOW(C)={$}
FOLLOW(D)={b}

7. Grammar:

S->ASB/d
A->a
B->AB/b/ϵ
FIRST(S)={a,d}
FIRST(A)={a}
FIRST(B)={a,b, } ϵ
FOLLOW(S)={$,a,b}
FOLLOW(A)={a,d,b,$}
FOLLOW(B)={$,a,b}

8. Grammar:

E->TE'
ϵ
E'->+TE'/
T->FT'
ϵ
T'->*FT'/
F->id/(E)

FIRST(E)={id,(}
FIRST(E')={+, } ϵ
FIRST(T)={id,(}

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
ϵ
FIRST(T')={*, }
FIRST(F)={id,(}

FOLLOW(E)={$,)}
FOLLOW(E')={$,)}
FOLLOW(T)={+,),$}
FOLLOW(T')={+,),$}
FOLLOW(F)={*,+,),$}

9. Grammar:

X->YZ
Y->m/n/ϵ
Z->m

FIRST(X)={m,n}
FIRST(Y)={m,n, } ϵ
FIRST(Z)={m}

FOLLOW(X)={$}
FOLLOW(Y)={m}
FOLLOW(Z)={$}

Watch following Video:

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
How To Find First and Follow in Compiler Design …
Watch later Share

Watch on

Watch on YouTube: https://www.youtube.com/watch?v=rnzGbQ3VjMU

Check Other Posts on Compiler

Next: Intermediate code generation for sample language using LEX and YACC

Previous: Concurrent YACC to Parse Input Text File


Related Posts:

How To Find Independent How to Create Side Effect of How C / C++


First and Follow compilation in Header File in C Aliasing with Compiler
in Compiler Java language / CPP or Example evaluates
Design Independent arithmetic
Examples | How expression /

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
To Find First compilation in Side Effect of
and Follow of a C language Global
Grammar Variables in C /
C++

Code
Optimization
Techniques in
Compiler
Design with
Examples

Labels: Compiler

16 comments:

tanzib 1 August 2016 at 01:34


nice :)

Reply

Replies

Parag Jambhulkar 21 January 2019 at 14:49

Thank You.

Reply

Ms 21 September 2016 at 05:23


I usually don't comment but i have my exam today and found this post really helpful. Thanks :)

Reply

Replies

Parag Jambhulkar 21 January 2019 at 14:49

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Thank You.

Reply

Unknown 26 September 2016 at 21:34

DO someone have finding follow code in C++ or in C?

Reply

Replies

Parag Jambhulkar 21 January 2019 at 15:00


Please check this link https://www.geeksforgeeks.org/program-calculate-first-follow-sets-given-grammar/

Reply

Security-Online 27 September 2016 at 18:54

Excellent examples!
Many thanks to the author of the note and clear position, that's cool
Reply

Replies

Parag Jambhulkar 21 January 2019 at 14:49

Thank You.

Reply

Unknown 5 April 2017 at 10:32

Just hilarious thanks a lot

Reply

Replies

Parag Jambhulkar 21 January 2019 at 14:57

Thank You.

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Reply

Unknown 2 October 2017 at 13:25

Very helpful..All the examples are excellent for clearing the concept. Thanks to the writer. :)

Reply

Replies

Parag Jambhulkar 21 January 2019 at 14:58


Thank You.

Reply

Unknown 9 November 2017 at 19:07

Very nice .thank you

Reply

Replies

Parag Jambhulkar 21 January 2019 at 14:58

Thank You.

Reply

Unknown 13 November 2017 at 02:30

This was very helpful, thank you!


Reply

Replies

Parag Jambhulkar 21 January 2019 at 14:58

Thank You.

Reply

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Enter your comment...

Comment as: Google Accoun

Publish Preview

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)

Google
Google Search

Domains List Contact Form

Buy Full Basket (www.buyfullbasket.com)


Name
Gents Special Amazon Links

Computer Revolution (www.comrevo.com)


Friend Class and Friend Function in C++ with Example | Friend Function in CPP with Example
Email *
Soniya Parag Recipes (www.soniyaparag.com)
Bahubali Thali at Nanded City Pune in JM Housefull Paratha | Mini Bahubali Thali

www.discoallnight.com
Buy Domain Name www.discoallnight.com on godaddy.com

www.incredibletelangana.com
Incredible Telangana Tourism

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
www.solvemyquery.com Message *
How to find ubuntu 32 or 64 bit?

Send

Best viewed in Google Chrome browser. Theme images by chuwy. Powered by Blogger.

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD

You might also like