An open API service indexing awesome lists of open source software.

https://github.com/l-applin/rept

Repeat langage Interpreter
https://github.com/l-applin/rept

backus-naur-form grammar-parser interpreter ply

Last synced: 3 months ago
JSON representation

Repeat langage Interpreter

Awesome Lists containing this project

README

          

# PYTHON Interpreter for "REPEAT" langage

Note : this is a personal project that I'm doing for fun and learning. Don't expect any commitement from my part or regular updates or anything of such. If you would like more information about the project, contact me personnaly.

## Description

*Repeat* is a pseudo-programing languge invented by [Alain Tapp][alain tapp] for our
[Introduction à l'informatique théorique][info theo] (Introduction to Theoretical computer science) at [University of Montreal][udem]. As a challenge I decided I would try to implement an interpreter of the langage using Python.

### The langage
*Repeat* is a very simple, very contrived and very limited "programming langage". I made some very slight modification to the syntax Mr Tapp used in his class but everything else is exactly the same. First, the langage has an infinite amount of registers that it can use to store an integer (the integer can be as large as it needs). Second, it has a few operations that can be made on those register :

1. Increment the value stored in a register : `inc r0`
2. Move the value from one register to another : `r1 <- r2`. It is also possible to directly put a value inside a register : `r0 <- 1024`
3. Repeat a block of commands by the amount of a register : `repeat r4 `
4. It also has the ability to define *non-recursive* macro to make the code more readable :
``` text
DEFINE-MACRO macro_id

end

r0 <- macro_id

```
That's it.

### Grammar
Here is the grammar I came up with for the *Repeat* langage

``` grammar
GRAMMAR ACTIONS & INFO
--------------------------------------------- ------------------------------------------------------
::= | A program is a list of expressions
::= | An expr is either a command or a macro definition
::= There are four different types of commands
|
|
|

::= INC REG reg[REG.val] = reg[REG.val] + 1
::= REG MOVE (REG | INT) reg[REG<1>.val] = reg[REG<2>.val]
::= REPEAT REG repeats all commands in body for REG.val times

::= END
::= |

::= REG MOVE ID execute all commands within matchin f macro definition
::= DEF ID define all actions to be done upon calling macro
::= REG | REG

```

### Parsing
For parsing the .repeat file, I choose to go with the pyhton library [PLY][ply]. This is a robust a classic library to work easily with BNF Grammar syntax. [Documentation][ply doc] for the library can be found by following the link.

### TODO:
Macros

[info theo]: https://sites.google.com/site/dirotappift2105/
[alain tapp]: http://diro.umontreal.ca/repertoire-departement/vue/tapp-alain/
[udem]: http://www.umontreal.ca/
[ply]: http://www.dabeaz.com/ply/
[ply doc]: http://www.dabeaz.com/ply/ply.html