実験3での経験を活かせば,MiniML言語の構文解析器を実装することは難しくない.以上.

課題2(必須) フロントエンド
MiniMLの文法規則に従うMiniMLプログラムを入力とし,以下のsyntax.mlにより定義される抽象構文木を返す字句解析器・構文解析器を作成しなさい.配布コードのlexer.mllparser.mlyには,講義テキスト3.5節のML言語に相当する文法定義がすでに含まれている.

syntax.ml

exception Error of string
let err s = raise (Error s)

type id = string

type binOp = Plus | Mult | Lt

type exp =
    Var       of id
  | ILit      of int
  | BLit      of bool
  | BinOp     of binOp * exp * exp
  | IfExp     of exp * exp * exp
  | LetExp    of id * exp * exp
  | FunExp    of id * exp
  | AppExp    of exp * exp
  | LetRecExp of id * id * exp * exp
  | LoopExp   of id * exp * exp (* loop <id> = <exp> in <exp> *)
  | RecurExp  of exp            (* recur <exp> *)
  | TupleExp  of exp * exp      (* (<exp>, <exp>) *)
  | ProjExp   of exp * int      (* <exp> . <int> *)

この実験の主題からは逸脱するが,すぐにMiniMLプログラムを動かしてみたい場合には,以下の課題に取り組んでみるのも良い.

課題3(任意) インタプリタ・型推論
実験3で作成したML言語のインタプリタと型推論器を基に,MiniML言語のインタプリタと型推論器を作成しなさい.