This is a compiler frontend ie an interpreter written in OCAML language.
You will need to install:
- opam: the package manage for OCaml. Follow instructions here: https://opam.ocaml.org/doc/Install.html
- ocaml: the language we use as host for implementing our interpreters. Follow the instructions here: https://ocaml.org/docs/install.html
- menhir: the lexer and parser generator. Just type
opam install menhir
- ounit: the unit testting library. Just type
opam install ounit2
- dune: the standard build system for OCaml. Just type
opam install dune
- Steps to execute
- clone the repo
- move into folder
cd Dysfunctionally_Functional
- open command-line and execute
interp <your expressions in quote>
for language extension:
Syntax
- Concrete Syntax: rules you have to follow to filter out incorrect code
- Abstract Syntax:
Semantics → is how we run code
- Specification
- Results
- Evaluation Judgements
- Evaluation rules
- Implementation
using parse in utop you can convert from conceret to abstract syntax
Grammar Notation
<Expression>::= <Number>
<Expression>::= <Expression> − <Expression>
<Expression>::= <Expression>/<Expression>
<Expression>::= (<Expression>)
The infix operator (>>=) is called bind and is left associative.
Consider the expression c >>= f
; its behavior may be described as follows:
- evaluate the argument
c
to produce a result (i.e. a non-error value or an error value); ifc
returns an error, propagate it and conclude. - otherwise, if
c
returnsOk v
, for some expressed valuev
, then passv
on tof
by evaluatingf v
.
<Expression>::= <Number>
<Expression>::= <Identifier>
<Expression>::= <Expression><BOp><Expression>
<Expression>::= zero?(<Expression>)
<Expression>::= if<Expression> then <Expression> else <Expression>
<Expression>::= let <Identifer> = <Expression> in <Expression>
<Expression>::= (<Expression>)
<BOp>::= + | - | * | /
〈Expression〉 ::= 〈Number〉
〈Expression〉 ::= 〈Identifier〉
〈Expression〉 ::= 〈Expression〉〈BOp〉〈Expression〉
〈Expression〉 ::= zero?(〈Expression〉)
〈Expression〉 ::= if 〈Expression〉then 〈Expression〉else 〈Expression〉
〈Expression〉 ::= let 〈Identifier〉= 〈Expression〉in 〈Expression〉
〈Expression〉 ::= (〈Expression〉)
〈Expression〉 ::= proc(〈Identifier〉){〈Expression〉}
〈Expression〉 ::= (〈Expression〉〈Expression〉)
〈BOp〉 ::= + |- |* |/
〈Expression〉 ::= 〈Number〉
〈Expression〉 ::= 〈Identifier〉
〈Expression〉 ::= 〈Expression〉〈BOp〉〈Expression〉
〈Expression〉 ::= zero?(〈Expression〉)
〈Expression〉 ::= if 〈Expression〉then 〈Expression〉else 〈Expression〉
〈Expression〉 ::= let 〈Identifier〉= 〈Expression〉in 〈Expression〉
〈Expression〉 ::= (〈Expression〉)
〈Expression〉 ::= proc(〈Identifier〉){〈Expression〉}
〈Expression〉 ::= (〈Expression〉〈Expression〉)
〈Expression〉 ::= letrec 〈Identifier〉(〈Identifier〉) = 〈Expression〉in 〈Expression〉
〈BOp〉 ::= + |- |* |