Description
I have provided a lexer and parser for dedepython+ on github.
Your task is to modify my lexer and parser to recognize a small language described in Lecture 3.
‹expr›:
NUMBER
add1 ( ‹expr› )
sub1 ( ‹expr› )
Your parser should produce an abstract syntax as shown in Lecture 3 as well:
type expr =
| Num of int64
| Add1 of expr
| Sub1 of expr
Example code
There's sample code in github. To run it you will need menhir and dune installed. I used opam to install mine.
You can parse a sample depython program using:
$ dune build
$ dune exec ./main.exe tests/112.dp
Module [
Expr Num 112
]
After modifying the lexer and parser you should be able to parse a program like the examples in lecture 3.
add1(42)
add1(sub1((add1(42))))
Deliverables
You should turn in your modified lexer.mll
, parser.mly
, pretty.ml
and
syntax.ml
. You shouldn't need to make changes to other files.