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.
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:
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
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