Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[3 pts) You are given the task of bootstrapping a compiler for a new programming language L. Assume that you have already implemented a minimal

image text in transcribed

[3 pts) You are given the task of bootstrapping a compiler for a new programming language L. Assume that you have already implemented a minimal core of the language, Lo, which has the following features: Integer literals, variables, and arithmetic ops, e.g. 1, 25, x, y, +, Assignment of a single-operation expression to a variable, e.g. x = -5, y = x + 1 Unconditional jump to a label, e.g. goto L . Conditional jump with a single variable as condition, e.g. if x goto L (if x #0, jump to L) Print a single variable or integer, e.g. print x, print 4 Here is a factorial program written in Lo: n = 10 x = 1 L1: x - x *n n - n - 1 if n goto L1 print x The next level of the language, L1, has the following new features: General arithmetic expressions (parentheses allowed), e.g. x + (y - z) * 2 General assignment and print statement (arbitrary expr allowed): x = a + b * c, print(x + y) . General if statement (arbitrary expr allowed as cond): if (E) S1 else S2 General while statement: while (E) S (if E's value #0, execute S and continue, otherwise break) . Compound statement: (S1; 52; ...} These new features need to be implemented in Lo. As an exercise, show how the following Ly code fragments can be implemented in Lo by giving an equivalent code sequence in L, for each of them. (Hint: You may introduce additional variables if needed.) (a) print(x + y - z * 2) (b) if (x - y) z = 2 else z = 5; print (z * 3) (c) while (k) {x = x * k; k = k - 1}; print(x)

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

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago