Write a program that does the following: 1. Reads a grammar. 2. Finds all FIRST(X) sets, following algorithm on pg. 189 of text. 3. Finds all FOLLOW(A) sets following algorithm on pg. 190 of text. You may write the program in any language that is supported by the computers in the lab, but C++ is preferred. INPUT: A grammar G. OUTPUT: The list of all productions in G The FIRST(X) and FOLLOW(A) sets of G DELIVERABLES: Program source code, with internal documentation Test results for grammar G417 and at least one other grammar. NOTES: ===== Follow the textual conventions on pg.198 of text. (additionally follow algorithms described in First/Follow link on the Compilers web page or section 4.4.2 of text). A is a non-terminal. X is a grammar symbol (terminals or non-terminal). In addition we will use the following conventions: 1 – all terminals will be single characters. 2 – all non-terminals will be single letters. 3 – epsilon (the empty string) is: e 4 – the "produces" symbol in productions is: -> 5 – end of input / end of section symbol is: $ The format for a grammar is as follows: terminal terminal .. terminal $ production production production $ A first section with one terminal per line, ending in $, and a second section with one production per line, ending in $. The format of a production is: A->string where the string represents a single produciton with no whitespace or "or" symbols, and A is a single non-terminal. Sample grammar: ============== Example 4.27 from the book is in ~egomez/cs570/first/g417. The following modifications are made, to conform to the format above: epsilon is replaced with e. E' is replaced with D. T' is replaced with U. id is replaced with I. I-> x|y|z is added; x y and z are the only identifiers. You should modify the FIRST and FOLLOW sets for this grammar accordingly (see page 222). At least one more sample grammar will be placed in the same directory. Optional features: ================= You may choose to write your gramman interpreter so that it understands the "or" symbol: | You may choose to ignore whitespace for better readability. *** This assignment should be programmed in C++. and if you finish this I can give some assignments in series to you. ** What I attached is page 222. It will be helpful for this work. attachment pag222.png attachment page2222.png. Write a program that does the following:
1. Reads a grammar.
2. Finds all FIRST(X) sets, following algorithm on pg. 189 of text.
3. Finds all FOLLOW(A) sets following algorithm on pg. 190 of text.
You may write the program in any language that is supported by the
computers in the lab, but C++ is preferred.
INPUT:
A grammar G.
OUTPUT:
The list of all productions in G
The FIRST(X) and FOLLOW(A) sets of G
DELIVERABLES:
Program source code, with internal documentation
Test results for grammar G417 and at least one other
grammar.
NOTES:
=====
Follow the textual conventions on pg.198 of text.
(additionally follow algorithms described in First/Follow link
on the Compilers web page or section 4.4.2 of text).
A is a non-terminal.
X is a grammar symbol (terminals or non-terminal).
In addition we will use the following conventions:
1 – all terminals will be single characters.
2 – all non-terminals will be single letters.
3 – epsilon (the empty string) is: e
4 – the “produces” symbol in productions is: ->
5 – end of input / end of section symbol is: $
The format for a grammar is as follows:
terminal
terminal
..
terminal
$
production
production
production
$
A first section with one terminal per line, ending in $, and
a second section with one production per line, ending in $.
The format of a production is:
A->string
where the string represents a single produciton with no whitespace
or “or” symbols, and A is a single non-terminal.
Sample grammar:
==============
Example 4.27 from the book is in ~egomez/cs570/first/g417. The
following modifications are made, to conform to the format above:
epsilon is replaced with e.
E’ is replaced with D.
T’ is replaced with U.
id is replaced with I.
I-> x|y|z is added; x y and z are the only identifiers.
You should modify the FIRST and FOLLOW sets for this grammar accordingly
(see page 222).
At least one more sample grammar will be placed in the same directory.
Optional features:
=================
You may choose to write your gramman interpreter so that it
understands the “or” symbol: |
You may choose to ignore whitespace for better readability.
*** This assignment should be programmed in C++. and if you finish this I can give some assignments in series to you.
** What I attached is page 222. It will be helpful for this work.
attachment
pag222.png
attachment
page2222.png