dedepython - OCaml types for a subset of python


In class we looked at depython, some types for representing python abstract syntax trees.

In python you can introspect code using the ast module.

import ast


The result is


A more complicated example:

ast.dump(ast.parse("2 + 3"))

Results in

Module(body=[Expr(value=BinOp(left=Num(n=2), op=Add(), right=Num(n=3)))])


We can define OCaml types similar to the above representations of python ast

type binop = Add | Sub | Mult | Div

type exp =
    | Num of int
    | BinOp of exp * binop * exp

type stm =
    | Expr of exp

type prog =
    | Module of stm list

I have made a github repository with the data types, some build instructions, and the beginning of a test suite.


Implement an interpreter for the prog type, following the skeleton in the example code. See the file for more details. Be careful to not change the types of the funcion or data. My test suite should build against your dedepython file.