MOSIG M1 - PLSCD - Practical Work

The purpose of this work is to implement an interpreter for the While language (the one you studied in the 1st part of the PLSCD course). Your are free to choose the programming language you prefer to implement this interpreter. Some resources are provided in this page if you want to implement it in C, but Note that using a functionnal programming language (such Objective Caml, for instance, see the user manual ...) might be much easier.

Some practical constraints:

Some resources provided
(if you want to implement your interpreter in C)
The whole directory isd also available as a tarball WhileParser.tgz.

How to use the resources provided in this directory
./while ex1.w      parse the file ex1.w and pretty-print its AST.
./while                 parse the input stream read on stdin (terminated by ^D), and pretty-print its AST.

The while language

Concrete grammar

(terminal symbols are written in bold, an identifier is a sequence of letters or digits begining with a letter, an integer is a sequence of digits).
Note that this concrete syntax slightly differs from the one used during trhe course.

program ::= bloc 
bloc ::= declare declaration_list  begin instruction_list end
declaration_list ::= declaration | declaration_list ; declaration
declaration ::= var identifier | proc identifier () is bloc
instruction_list ::= instruction | instruction_list ; instruction
instruction ::= identifier := e | while b do instruction od| if b then instruction else instruction | call identifier ()
e ::= e + t | t
t ::= t * f | f
f::=  ( e )| identifier | integer
b ::=  b /\ bb | bb
bb ::= e < e | e =  e | ^ bb | (b)

Abstract Syntax Tree (AST)

The structure of the AST can be deduced from the print_tree() function of file tree.c
We assume that input programs are well-typed (no verification performed by the parser)