Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the compiler from Exercise 2.4 to write the lists of integers to a file. An F# list inss of integers may be output to

Modify the compiler from Exercise 2.4 to write the lists of integers to a file. An F# list inss of integers may be output to the file called fname using this function (found in Intcomp1.fs):

Then modify the stack machine interpreter in Machine.java to read the sequence of integers from a text file, and execute it as a stack machine program. The name of the text file may be given as a command-line parameter to the Java program. Reading numbers from the text file may be done using the StringTokenizer class or StreamTokenizer class; see e.g. Java Precisely [4, Example 145]. It is essential that the compiler (in F#) and the interpreter (in Java) agree on the intermediate language: what integer represents what instruction.

Exercise 2.4:

Write a bytecode assembler (in F#) that translates a list of bytecode instructions for the simple stack machine in Intcomp1.fs into a list of integers. The integers should be the corresponding bytecodes for the interpreter in Machine.java. Thus you should write a function assemble : sinstr list -> int list. Use this function together with scomp from Intcomp1.fs to make a compiler from the original expressions language expr to a list of bytecodes int list.

You may test the output of your compiler by typing in the numbers as an int array in the Machine.java interpreter. (Or you may solve Exercise 2.5 below to avoid this manual work).

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

27. Let . Show that if , then

Answered: 1 week ago