Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Comp 439 Given the grammar defined by the following Extended BNF set of production rules : program body $ body lib-decl main () declarations block

Comp 439

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

What is quality of work life ?

Answered: 1 week ago

Question

What is meant by Career Planning and development ?

Answered: 1 week ago

Question

What are Fringe Benefits ? List out some.

Answered: 1 week ago