https://github.com/sampsyo/lang-start
skeleton for a language implementation in OCaml
https://github.com/sampsyo/lang-start
example interpreter ocaml
Last synced: 11 months ago
JSON representation
skeleton for a language implementation in OCaml
- Host: GitHub
- URL: https://github.com/sampsyo/lang-start
- Owner: sampsyo
- License: mit
- Created: 2018-05-20T15:51:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-08T18:23:26.000Z (over 6 years ago)
- Last Synced: 2025-02-26T19:07:20.387Z (12 months ago)
- Topics: example, interpreter, ocaml
- Language: OCaml
- Homepage:
- Size: 10.7 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Starting an Interpreter in OCaml
================================
This is a skeleton showing how to start writing a tiny interpreter in OCaml.
It just parses, pretty-prints, and evaluates a trivial arithmetic AST.
To build the project, you will need [Dune][] v1.10.0+.
You can install it using `opam install dune`.
There is one dependency: [Menhir][].
If you don't already have it, this will work to get it (or you can just do `opam install menhir`):
$ dune build @check # Generate the OPAM file.
$ opam install . --deps-only
You can build the project and run an example in one step:
$ echo '8*(3+2)+2' | dune exec calc
If you just need to compile, use `dune build`.
Or, to watch for changes and automatically rebuild, install [fswatch][] and then:
$ dune build --watch
Explore the implementation in a [utop][] REPL:
$ opam install utop
$ dune utop src
This repository contains:
* `src/`: The language implementation.
* `ast.ml`: An ADT for the language syntax.
* `parser.mly`: A [Menhir][] parser for expressions.
* `lexer.mll`: The [ocamllex][lexyacc] lexer for that parser.
* `ops.ml`: Functions to pretty-print and evaluate expressions.
* `bin/calc.ml`: A tool that reads a program from standard input.
* `dune-project`, `src/dune`, and `bin/dune`:
The build configuration for [Dune][].
[dune]: https://github.com/ocaml/dune
[menhir]: http://gallium.inria.fr/~fpottier/menhir/
[lexyacc]: https://caml.inria.fr/pub/docs/manual-ocaml/lexyacc.html
[utop]: https://github.com/diml/utop
[fswatch]: https://github.com/emcrisostomo/fswatch