The tool menhir and the graphics library are requirements for this lab. If you haven't already, install them with the command opam install menhir graphics.
The basic structure is provided (a tarball with OCaml files and a Makefile) : mini-turtle.tar.gz. Once uncompressed (for instance with tar zxvf mini-turtle.tar.gz, you get a directory mini-turtle/ with the following files:
turtle.ml(i) | the graphical turtle (complete) |
ast.ml | the abstract syntax mini-Turtle (complete) |
lexer.mll | lexical analyzer (to be completed) |
parser.mly | syntax analyzer (to be completed) |
interp.ml | the interpreter (complete) |
miniturtle.ml | main file (complete) |
Makefile/dune | to automate the build (complete) |
The code compiles (run make, which runs dune build) but is incomplete. Places to be filled are marked * À COMPLÉTER */. The program takes a file to be interpreted on the command line, with suffix .logo. When running make, the program is run on file test.logo.
if else def repeat penup pendown forward turnleft turnright color black white red green blueAn identifier ident contains letters, digits, and underscores and starts with a letter. An integer literal integer is a sequence of digits.
file ::= def* stmt* def ::= def ident ( ident*Priorities of arithmetic operations are usual, and unary negation has the strongest priority., ) stmt stmt ::= penup | pendown | forward expr | turnleft expr | turnright expr | color color | ident ( expr*, ) | if expr stmt | if expr stmt else stmt | repeat expr stmt | { stmt* } expr ::= integer | ident | expr + expr | expr - expr | expr * expr | expr / expr | - expr | ( expr ) color ::= black | white | red | green | blue
If needed, do make explain to display the conflicts detected by menhir.
forward 100should be accepted and a window should open with an horizontal line (100 pixels long). Check the priorities of arithmetic operations, for instance with
forward 100 + 1 * 0If the priorities are wrong, you will get a point instead of a line.
Test with programs such as
forward 100 turnleft 90 color red forward 100
Test with programs such as
repeat 4 { forward 100 turnleft 90 }
You can test using the files provided in subdirectory tests, namely :
The command make tests runs the program on each of these files. You should get the following images (pressing a key in between): ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |