[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[epsilon-devel] Interpreter of an imperative language in epsilon

From: Luca Saiu
Subject: [epsilon-devel] Interpreter of an imperative language in epsilon
Date: Thu, 11 Dec 2003 03:34:41 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.3a) Gecko/20021212

As I promised I have written an interpreter for a very simple imperative language. The code should be clean and readable; you should
understand it before attempting to write a Logo system.
I know that this may seem difficult if it's the first time you seriously attempt understanding an interpreter. Don't be afraid, it's not *so* difficult. It's easier than the interpreters in SICP, because there is no eval/apply loop here (and this is because the language is really, really trivial :-)).
  If you have any doubts don't hesitate to ask me.

The main action is in main.epb; it contains some simple imperative programs that you can execute. The heart of the interpreter is in imperative.epi (for the abstract syntax) and especially in imperative.epb (for the semantics).

  Possible excercises for you:
* Understand how to write imperative programs in abstract syntax. You can use the sample programs in main.epb, and (especially) the concrete type definitions in imperative.epi. * Add this imperative program (it computes the factorial) to main.epb as program5 and test it (don't use tabs for indenting :-))):
                input_integer n;
                i := 1;
                fact := 1;
                while i < n + 1 do {
                  fact := fact * i;
                  i := i + 1;
                output fact;
* Read and understand all the code, with patience. This will take some time.
* Write more operators (string concatenation, less_or_equal, xor, and so on). Operators need not to be complex; the important matter is not what hey do, it's how easily you can add them to the language. Don't cut&paste here. * Modify operators.epb, making the 'equal' operator polymorphic (it means that it should work not only for pairs of integers, but also for pairs of booleans and for pairs of strings). Hint: use is_value_XXXX.
* Add a construct "repeat <command> until <expression>" to the language.
* Add a construct "for <var> from <e1> to <e2> do <c>" (this is more difficult).

  Good night,

Luca Saiu, maintainer of GNU epsilon

Attachment: imperative.tar.gz
Description: GNU Zip compressed data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]