Question: Please solve the question using c language Given the grammar defined by the following Extended BNF set of production rules : program body $ body

Please solve the question using c language

Given the grammar defined by the following Extended BNF set of production rules :

program body $

body lib-decl main () declarations block

lib-decl ( # include < name > ; )*

declarations const-decl var-decl

const-decl ( const data-type name = value ; )*

var-decl ( var data-type name-list ; )*

name-list name ( , name )*

data-type int | float

name user-defined-name

block { stmt-list }

stmt-list statement ( ; statement )*

statement ass-stmt | inout-stmt | if-stmt | while-stmt | block | l

ass-stmt name = exp

exp term ( add-oper term )*

term factor ( mul-oper factor )*

factor ( exp ) | name | value

value float-number | int-number

add-sign + | -

mul-sign * | / | %

inout-stmt input >> name | output << name-value

if-stmt if ( bool-exp ) statement else-part endif

else-part else statement | l

while-stmt while ( bool-exp ) { stmt-list }

bool-exp name-value relational-oper name-vaue

name-value name | value

relational-oper == | != | < | <= | > | >=

A sample program in this language:

#include;

#include;

main()

const float bi=3.14;

var int num,count,

var float x;

{ input>>num;

if (num !=0)

x=bi*2

else

x=x*3

endif;

output>>x;

} $

Note:

(1) The tokens in bold letters are reserved words.

(2) Other symbols as they appear in the production rules.

* Write a recursive descent parser for the above grammar .

* Your program will be tested with a random programs.

* Your program will be graded according to correctness, style, and documentation.

* No programs will be accepted after the due date.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!