Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. The CFG shown in Figure 2.1 defines the syntax of ac programs. Explain how this grammar enables you to answer the following questions. (a)

image text in transcribed1. The CFG shown in Figure 2.1 defines the syntax of ac programs. Explain how this grammar enables you to answer the following questions.

(a) Can an ac program contain only declarations (and no statements)?

(b) Can a print statement precede all assignment statements?

2. Sometimes it is necessary to modify the syntax of a programming lan- guage. This is done by changing the CFG that the language uses. What changes would have to be made to acs CFG (Figure 2.1) to implement the following changes?

(a) All ac programs must contain at least one statement. (b) All integer declarations must precede all float declarations.

(c) The first statement in any ac program must be an assignment state- ment.

Formal Definition of ac 1 Prog Dols Stmts $ 2 Dcls DclDols 4 Dcl floatdcl id 6 Stmts Stmt Stmts 8 Stmt id assign Val Expr I intdcl id | print id 10 Expr plus Val Expr | minus Val Expr 12 13 Val id | inum | fnum 14 15 Figure 2.1: Context-free grammar for ac

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

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

Answered: 1 week ago

Answered: 1 week ago

Question

2. Show the trainees how to do it without saying anything.

Answered: 1 week ago