Question: 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

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!