Drton is a mini-compiler for a programming language written in Darija. This mini-compiler includes its own lexical, syntactic and semantic analyzer, it is based mostly on Python, which is also used as an intermediate language to generate the machine language.
# drton
**drton** is a mini-compiler for a programming language written in *Darija*.
This mini-compiler has its own lexical, syntactic and semantic analyzer. It is based on mostly on Python, which is also used as an intermediate language to generate the machine language by using python ply.
## Requirements:
* Python (v3.7+)
* Python ply `pip install ply`
## Use:
You can start using it by using the following commands:
* `python parser.py` for interpreted mode
* `python parser.py file.dr` to compile a file
## Keywords (and equivalent in python):
Keyword | Python
------------ | -------------
`kteb` | `print`
`qra` | `input`
`ila ` | `if`
`wla ` | `else`
`dir ` | `do`
`ma7ed ` | `while`
`lkola ` | `for`
`khrej ` | `break`
`kmel ` | `continue`
`wa ` | `and`
`aw ` | `or`
`khate2 ` | `false`
`s7i7 ` | `true`
`mojod ` | `global`
`walo ` | `None`
`l3akss ` | `not`
`ta3rif ` | `def`
`red ` | `return`
`jereb ` | `try`
`masd9ch ` | `except`
`akhiran ` | `finally`
`tol ` | `len`
`zid ` | `append`
`kber ` | `extend`
`n9s ` | `pop`
`dkhel ` | `insert`
`khwi ` | `clear`
## Features:
* Variables
* Comments
* Control flow statements:
- loops (while,do-while,for)
- conditional statements
- function calls
- exceptions
* Operators:
- arithmetic : `+ - * / % ^`
- comparison : `> >= y)
# Output: khate2
kteb(x =y)
# Output: khate2
kteb(x = 0){
kteb('The number is positive')
}
wla{
kteb('The number is negative')
}
```
- We can have a `ila..wla` statement inside another `ila..wla` statement. This is called nesting in computer programming.
```Python
num = qra("Enter a number: ")
ila (num >= 0){
ila (num == 0){
kteb("Zero")
}
wla{
kteb("Positive number")
}
}
wla{
kteb("Negative number")
}
```
* **lkola** (*for loop*):\
The `lkola` loop is used to iterate over a sequence.
```Python
lkola(i=0;i = 0){
red(num)
}
wla{
red(-num)
}
}
kteb(absolute_value(2)) # Output: 2
kteb(absolute_value(-4)) # Output: 4
```
> You'll find more examples in the examples folder!
* **jereb..masd9ch..akhiran* …