Ocaml编程代写 | CSE-112 Program 2 Interpreter in Ocaml

本次澳洲代写是Ocaml编程相关的一个assignment

1. Overview

This project will repeat the Mini Basic interpreter,except this time the program will
be written in Ocaml but with Mini Basic programs untranslated from the original.
See the score directory for sample input files.Output should be the same as for the
Scheme version of the program, except for minor variations in output due to differ-
ences between the Scheme and Ocaml languages.Any results whichwould produce
acomplex value in Scheme should produce nan in this project.

2. Running ocaml interactively

Ocaml mayberun interactively from the command line or as a compiled program.
The compiled program version, created using make is required for all submitted pro-
grams.

To run ocaml interactively,add the following to your $HOME/.bash_profile :
export PATH=$PATH:/afs/cats.ucsc.edu/courses/cse112-wm/usr/ocaml/bin
When running ocaml interactively,use the command rlwrap to gain access to the
readline arrow keys so that you can recover earlier typed lines.Example :

-bash-$ rlwrap ocaml
OCaml version 4.02.1
# let f x y = x +. y;;
val f : float -> float -> float = <fun>
# f3.;;
-:float -> float = <fun>
# f3.4.;;
-:float = 7.
# ^D

To simplify typing,the following line might be added to your $HOME/.bash_profile :
alias wocaml=”rlwrap ocaml”

The suggestions above assume you are using bash as your login shell. If not, use the
syntax appropriate for whatever shell you are using.

Some files that are useful when running interactively are :

using
Aset of #use directives whichcan be used for interactive testing of the func-
tions.This file is not used in compilation. After starting Ocaml, type in the
following command to load your source code interactively :

#use “using”;;
.ocamlinit

As an alternative to the using file,create the file .ocamlinit containing the
same information. The file .ocamlinit in the current directory is automati-
cally sourced when ocaml starts.

As an alternative,start up ocaml with the line

rlwrap ocaml -init using

whichwill start up the init file when needed, but avoid the automatic startup when
you don’t want it. If you have a .ocamlinit and want to ocassionally suppress it,

you can use

rlwrap ocaml -init /dev/null

3. Source code

The following files and modules are provided in the code/ subdirectory :
etc.mli, etc.ml

Interface and implementation of the Etc module,whichcontains miscellaneous
functions not specifically tied to other purposes.
absyn.mli

Definition of the abstract syntax used by the interpreter.Noimplementation
file is needed.
tables.mli, tables.ml

Module for maintaining the five tables needed by the program. The interface
file is automatically generated from the implemenation, not entered manually.
The required tables and their types are :

unary_fn_table
The unary functions.
type unary_fn_table_t = (string, float -> float) Hashtbl.t

binary_fn_table
The binary functions.
type binary_fn_table_t = (string, float -> float -> float) Hashtbl.t
Because Ocaml is strongly typed, the unary and binary functions need to
be be in separate tables.

bool_fn_table
The binary functions returning boolean values.
type binary_fn_table_t = (string, float -> float -> float) Hashtbl.t
And the relational operators need to be kept in yet another function
table.

variable_table
The simple variables used by the program.
type variable_table_t = (string, float) Hashtbl.t

array_table
The arrays used by the program.
type array_table_t = (string, float array) Hashtbl.t

label_table
Labels with pointers to the list of program statements.
type label_table_t = (string, Absyn.program) Hashtbl.t

 


程序代写代做C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: itcsdx@outlook.com  微信:itcsdx


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

blank

发表评论