OCaml Code: Write an interpreter for OCaml that pushes integers to the stack, pushes string to the stack, pushes names to the stack, has booleans, errors and units, uses pop method, add method, subtraction method, multiplication method, division method, remainder method, negation of an integer, swap method, toString method, println method, and quit method. Give me the correct interpreter code that compiles for OCaml. The name of the file must be interpreter.ml that contains a function, interpreter, with the following type signature: val interpreter : string * string -> unit. Use the input.txt cases with their output.txt cases below to test the code to make sure the code works. Don't give me an explanation. I need the code on how to write an interpreter for OCaml. Make sure that the code compiles correctly and provide the code with the screenshot of the output.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

OCaml Code: Write an interpreter for OCaml that pushes integers to the stack, pushes string to the stack, pushes names to the stack, has booleans, errors and units, uses pop method, add method, subtraction method, multiplication method, division method, remainder method, negation of an integer, swap method, toString method, println method, and quit method. Give me the correct interpreter code that compiles for OCaml. The name of the file must be interpreter.ml that contains a function, interpreter, with the following type signature: val interpreter : string * string -> unit. Use the input.txt cases with their output.txt cases below to test the code to make sure the code works. Don't give me an explanation. I need the code on how to write an interpreter for OCaml. Make sure that the code compiles correctly and provide the code with the screenshot of the output.

 

input1.txt:                              

push 1
toString
println
quit
 

 

input2.txt: 

push 5
push :true:
push :false:
push "str1"
push str1
push :error:
push :unit:
toString
println
toString
println
toString
println
toString
println
toString
println
toString
println
toString
println
quit

 

 

input3.txt:

push 10
push 2
push 8
pop
add
toString
println
quit

 

input4.txt:

push 6
push 2
push 3
sub
add
toString
println
quit
 

input5.txt:

push :true:
push 7
push 8
push :false:
pop
mul
toString
println
toString
println
quit

 

 

 

output1.txt:

1

 

 

output2.txt:

:unit:
:error:
str1
str1
:false:
:true:
5

 

 

 

output3.txt:

12

 

 

output4.txt:

5

 

 

output5.txt:

56
:true:

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Where is the input and output test files I gave being run? I ran the code and got errors. Please provide the correct code with the screenshot of the output. I need to see the input and output test files being run in order for me to know the code works

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY