Mirco Bochicchio
  • Projects
  • About
  • Experience
Email me

© 2026 Mirco Bochicchio. Built by me, for me: I was the customer again.

Privacy and credits
  • GitHub profile
  • LinkedIn profile

Murphy· Open-source project

A small language, built from scratch.

Write a program in Murphy and run it. The scanner, the parser and the interpreter are all in one OCaml file.

View codeEmail me
A Murphy program that applies the square function three times to 2, and the terminal printing 256

An interpreter feels like magic until you write one.

Every language you use has a scanner, a parser and an interpreter behind it. Murphy is a small one, built to see all three parts at work with nothing doing the hard parts for me.

Customer: me. I wanted to understand what happens between typing code and seeing it run, so I wrote the whole chain.

How it works

  1. Scan the text

    The source is cut into tokens: numbers, names, symbols and the capitalised keywords FUNC, TEST, SUCCESS, FAIL, DEF and IN.

    square(2)IDEsquareLB(NUM2RB)
    Source text in, a list of tokens out.
  2. Parse it into a tree

    Tokens are arranged by the grammar into a syntax tree, so that 2 + 3 * 4 multiplies before it adds.

    Plus
    ├ Num 2
    └ Mul
       ├ Num 3
       └ Num 4
    14
    The tree for 2 + 3 * 4. The multiplication sits lower, so it runs first.
  3. Evaluate the tree

    The interpreter walks the tree with an environment of variables and functions. Functions are values, so one can be passed to another.

    2416256
    apply_fun_v_ntimes(square, 2, 3): square is passed in as a value and applied three times.

Small, on purpose

No dependencies

Plain OCaml. Compile it with ocamlc and run it.

Functions are values

A function can be passed as an argument and called inside another function.

Maths that does not crash

Dividing by zero gives PLUS_INFINITY, MINUS_INFINITY or NAN instead of an error.

Runs from the terminal

Write your program in a text file and pass it to the interpreter.

Built with

  • OCaml

One OCaml file, about 760 lines. It works with integers only.

All projectsNext: Revenue Leakage Defender