Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modern Programming Languages - Chapter 23 - Exercise 2 In this exercise you will define language four, an extension of language three. Here is a

Modern Programming Languages - Chapter 23 - Exercise 2

In this exercise you will define language four, an extension of language three. Here is a sample program in language four, showing all the new constructs:

let

val fact = fn x => if x<2 then x else x * fact (x-1)

in

fact 5

end

As you can see, language four extends language three with three new constructs: the < operator for comparison, the - operator for subtraction, and the conditional (if-then-else) expression. The sample program above defines a recursive factorial function and uses it to compute the factorial of 5.

A. Define the syntax of Language Four by extending the syntax of Language Three with the three additional constructs required. Show your new BNF. Make sure it is unambiguous.

B. Define the three new kinds of AST nodes you need to match your extended syntax. Extend the Prolog implementation of Language Three to handle them. (You will need to start with the dynamic-scoping implementation, since the static-scoping one cannot handle recursive definitions. For this reason, the sample program above is not legal in ML.) Verify that your implementation evaluates the sample program correctly _ the factorial of 5 is 120.

C. Give a natural semantics for Language Four.

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

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

List the benefits of strategic planning.

Answered: 1 week ago