Question
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)
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) 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started