Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The programming language Pascal has a construct repeatuntil for a logical post-test loop. The syntax is given by the following (somewhat simplified) grammar: | id

The programming language Pascal has a construct repeatuntil for a logical post-test loop. The syntax is given by the following (somewhat simplified) grammar:

| id = + | * | () | id | int-literal | ; repeat until (id relop id)

1. This problem deals with the operational semantics for this construct.

You may assume that the attribute grammar for the operational semantics of assignment statements and expressions are the same as those in the slides, and the operational semantics for statement lists is as follows:

{.code .code}

[2] ; {.code = [2].code || .code}

a. Write an attribute grammar for the intermediate code for repeat loops. You may assume, if needed, that there is a function negate(relop) that returns the opposite of the given relational operations lexeme (for example, negate(<) is >=).

b. Show the decorated parse tree and the intermediate code generated by your grammar for the following source code. a = 0; b = 10; c = 150; repeat a = a + 3; b = b*a until (b > c)

2. This problem deals with the denotational semantics for the same construct. You may assume that the denotational semantics for decimal numbers, expressions, assignment statements, and statement lists are as given in the textbook and slides.

a. Write the denotational-semantics definition for the function

Mr(,s), where s is the initial state before the loop begins execution.

(HINT: Unlike a logical pre-test loop, a logical post-test loop executes the statement list at least once. What is the effect of this on the state when the first logical test is performed?)

b. Use your denotational semantics to compute

Mr(repeat a = a+3; b = b*a until (b > c), {,,})

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_2

Step: 3

blur-text-image_3

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 Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

Have annual top executive meetings with our key suppliers?

Answered: 1 week ago