Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I compile/run this sample program in OCaml? I am very new to OCaml and having trouble getting started. I have installed ocaml and

How do I compile/run this sample program in OCaml? I am very new to OCaml and having trouble getting started. I have installed ocaml and can compile this program with ocamlopt, but I don't know how to provide the input.

image text in transcribed

(* binop ('a -> a> 'a) 'a list >a list *) let binop opfunction I>failwith "invalid expression" (* interpfloat list -string -stringfloat list *) let interp s functiorn binop+.) s I "-" -> "subt r " , binop ( -. ) s I "**-> "mult", binop (*. ) s | "/" -> "divide", binop /.) s I "A" -"exp", binop *s | str ->"push", (float of string str) ::s (* interp_and_show:float list -> string let interp_and_show s inp - float list ) let op,s'interp s inp in Printf.print f "%s\t%s\t" np op; List. (iter (Printf.printf "F ") (rev s)) print_newline ); (*rpn_eval:string -> float list ) let rpn-eval str = Printf.printf "Token tAction tstack " let ssStr.(split (regexp string "") str) in List.fold_left interp_and_show [ ss Evaluation of the test expression # rpn, eval "3 4 2 * Token Action Stack 15-23^^/+". push 3 push 3. 4 push 3. 4. 2. mult 3. 8 push 3. 8. 1. push 3. 8. 1. 5 subtr 3. 8. -4. push 3. 8. -4. 2. push 3. 8. -4. 2. 3. exp exp divide 3. 0.0001220703125 add 4 2 2 3. 8. 65536 3.00012207031 float list = [3.0001220703125] (* binop ('a -> a> 'a) 'a list >a list *) let binop opfunction I>failwith "invalid expression" (* interpfloat list -string -stringfloat list *) let interp s functiorn binop+.) s I "-" -> "subt r " , binop ( -. ) s I "**-> "mult", binop (*. ) s | "/" -> "divide", binop /.) s I "A" -"exp", binop *s | str ->"push", (float of string str) ::s (* interp_and_show:float list -> string let interp_and_show s inp - float list ) let op,s'interp s inp in Printf.print f "%s\t%s\t" np op; List. (iter (Printf.printf "F ") (rev s)) print_newline ); (*rpn_eval:string -> float list ) let rpn-eval str = Printf.printf "Token tAction tstack " let ssStr.(split (regexp string "") str) in List.fold_left interp_and_show [ ss Evaluation of the test expression # rpn, eval "3 4 2 * Token Action Stack 15-23^^/+". push 3 push 3. 4 push 3. 4. 2. mult 3. 8 push 3. 8. 1. push 3. 8. 1. 5 subtr 3. 8. -4. push 3. 8. -4. 2. push 3. 8. -4. 2. 3. exp exp divide 3. 0.0001220703125 add 4 2 2 3. 8. 65536 3.00012207031 float list = [3.0001220703125]

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

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

Did the team members feel that their work mattered

Answered: 1 week ago

Question

2. What process will you put in place to address conflicts?

Answered: 1 week ago