Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the grammar defined by the following set ofproduction rules in the EBNF mo

ID: 3874588 • Letter: G

Question

Given the grammar defined by the following set ofproduction rules in the EBNF module-declaration module "." module module-heading declarations compound-stmt module-heading module "name" ";" declarations const-decl var-decl task-decl const-decl const (const-item ";" )+ 1 const-item "name" "integer-value" var-decl var (var-item ".") var-item name-list ":" i name-list "name" ("," "name") task-decl à task-heading declarations nteger task-heading-> task "name" ";" compund-stmt begin stmt-list end stmt-list ( statement "." ) statement ass-stmt l inout-stmt | stmt l while- ass-stint "name" ":-'' arith-exp arith-exp term (add-sign term) term factor (mul-sign factor ) factor"(" arith-exp")" I name-value name-value "name" "integer-value" add-sign "+" "-" mul-sign "*" | 7" inout-stmt input "(" "name" ")" 1 out "(" name-value if-stmt if bool-exp then statement else-part fi else-part else statement | while-stmt while bool bool-exp name-value relational-oper name-value stmt | compound-stmt | ")" -exp do statement Notes: (1) The tokens in bold letters are reserved words. (2) The words between “ " are terminals (terminal tokens). Write a recursive descent parser for the above grammar using C programming language, By using CodeBlock

Explanation / Answer

In your questions example, evaluating FOLLOW(A') results in only two possibilities where A' is on the RHS and can have a following symbol. Below are the two productions that can result

A->bA'
A'->aA'

Unfortunately, out of the two one is FOLLOW(A') = FOLLOW(A') (as per the rule I have mentioned in last line of the answer)

Hence we can only consider the other follow which is

FOLLOW(A') = FOLLOW(A)

i.e.

FOLLOW(A) = FIRST(B)

In a practical sense, if we have
S->ABC and
A-> bA'
A'->aA'|E

Then whenever we have an A production, it will further lead to either

A -> baA' or A->b (if we take A'->E)

In both cases the only thing that can follow A' is whatever is the first of B.

In a similar manner we can compute the same for FOLLOW(B') and FOLLOW(C').

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote