Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maxm33/minicaml-interpreter
An interpreter written in Java that understands a subset of OCaml instructions.
https://github.com/maxm33/minicaml-interpreter
interpreter ocaml
Last synced: 3 months ago
JSON representation
An interpreter written in Java that understands a subset of OCaml instructions.
- Host: GitHub
- URL: https://github.com/maxm33/minicaml-interpreter
- Owner: maxm33
- License: mit
- Created: 2024-03-11T16:35:48.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-08-24T23:47:48.000Z (5 months ago)
- Last Synced: 2024-09-29T06:41:06.110Z (3 months ago)
- Topics: interpreter, ocaml
- Language: Java
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# MiniCaml Interpreter
This is an interpreter that understands a simplified version of OCaml (**MiniCaml**).
Since it is implemented in Java, every construct, type or structure (**every expression**, better said) in MiniCaml is modeled as an object.
OCaml offers constructs for OOP and imperative programming, which is not _(yet)_ the case in MiniCaml.
However, MiniCaml offers constructs for control-flow, declaration of variables, functions and recursive functions.
## Grammar
Every program must start with an expression `e ;;` from which can derive as follows:
- **e** := **val** | **ide** | **ListOp** | (**e**) | (**e** **bop** **e**) | **uop** **e** | **e** ;; **e** | (**ide** **e1 ... e16**) | if **e** then **e** else **e** | let _rec_ **ide** _**ide1 ... ide16**_ = **e** _in **e**_ | function **ide1 ... ide16** -> **e**
- **ListOp** := List.hd **e** | List.tl **e** | List.rev **e** | List.isEmpty **e** | List.length **e** | List.cons **e** **e** | List.append **e** **e** | List.map **e** **e** | List.filter **e** **e** | List.exists **e** **e** | List.forAll **e** **e** | List.fold **e** **e** **e**
- **val** := Int | Bool | Closure | RecursiveClosure | [**e0 ... en-1**]
- **uop** := !
- **bop** := **+** | **-** | \* | **/** | **&** | **|** | **>** | < | **>=** | <= | **%** | **^** | **==** | **!=**
- **ide** := Identifiers
> [!TIP]
> You can refer to OCaml documentation for any doubt, since it should be almost equivalent to this lexic, syntax and semantics.
As in OCaml, functions in MiniCaml are treated as values, so they can be passed as arguments to or returned from other functions, or stored in variables/lists.
> [!NOTE]
>
> - '( )' can surround any expression (just one), but they are also necessary to define operations and functional applications, so use them wisely.
> - 'in', 'rec' and 'ide1 ... ide16' are optional in 'let' declaration, thus they are formatted in _italic_. This was done to reduce several rules to just one, lightening the grammar representation.
## Usage
- Compile
```
javac Main.java
```- Run
```
java Main
```
> [!TIP]
> Some test programs are available in `test` folder.