Pepelang!

2022 Jul 15 See all posts


Pepelang!

version coverage coolness

What is Pepelang?

Project

Pepelang was born out of two personal desires,

Concept

Pepelang is a programming language built and interpreted with/by Go.

It parses the source code in a Read-Eval-Print-Loop (REPL) environment and It has it's own token system, lexer, parser, AST and reuses the gargabe collection system from Go.

Pepelang's code looks like this:

var hola = fn() {
   retornar "hello world";
}

hola()

"hello world"

How to use?

Requirements:

Install

You'll need to install Go

git clone https://github.com/Danielratmiroff/pepelang.git
cd pepe
go install

Usage

Call pepe in your terminal

$ pepe

You can also call a pepe program:

$ pepe youProgram.pp

If you want, you can also add an alias for this with echo "alias pp=‘pepe'" >> ~/.zshrc (or whichever rc file you're using).

Please note: If you get an error claiming that pepe cannot be found or is not defined, you may need to add ~/go/bin to your $PATH (MacOS/Linux), or %HOME%(Windows). Not to be mistaken for C:(which is for Go's own binaries, not apps like pepe).

Features & Syntax

You can create and run your own pepe programs using the ".pp" file extension. (Yes, ".pp" extension is already a thing, but I found it very funny so I decided to keep it!)

Create a *.pp file in any folder. (e.g. hello.pp)

Run it with:

pp hello.pp # (if an alias was created) or ./pepe hello.pp

Pepelang supports the following functionality:

Variables:

Declared with the var keyword, can have either a string, number, boolean, array, dictionary or function value

var hola = "mundo"

Booleans:

verdad (true) or falso (false)

Arithmetics supported:

>> 4 + 2
6
>> !verdad
falso
>> var foo = 68
>> foo++
69

Arrays:

Indexes are treated as expressions, thus, all of the following are valid:

>> var lista = ["hola", 2, "mundo", 4]
>> lista[3]
"mundo"
>> var lista = [6 < 9 , 4 + 2]
>> lista[1]
6
>> var lista = [!verdad, !falso]
>> lista[0]
falso

Dictionaries:

Keys are literal values and values are parsed as expressions

>> var miDic = { "nombre": "daniel", "edad": 69};
>> miDic["nombre"];
daniel
>> miDic["edad"];
69

If/Else statements:

Declared using the si # (if) and sino # (else), can take any expression value and evaluate the code accordingly

>> si ( 1 < 2 ) {
retonar verdad
}

verdad
>> si ( 42 == 69 ) {
retonar verdad
} sino {
retornar falso
};

falso

Return statements:

Declared using the retonar keyword (as in previous example)

Function literals:

>> var suma = fn(a, b) { a + b; };
>> suma(2, 2)
4
var sumaTotal = fn(f, x) {
     retornar sumaDos(sumaDos(x));
};
var sumaDos = fn(x) {
    retornar x + 2;
};

sumaTotal(sumaDos, 2); // => 6

Built in functions:

>> tam("Hello world")
12
>> var lista = [1, 2, 3]
>> tam(lista)
2
>> pon("Imprime este mensaje!")
imprime este mensaje!
>> var lista = [1, 2, 3]
>> primero(lista)
1
>> ultimo(lista)
3
>> var lista = [1, 2, 3]
>> rest(lista)
[2, 3]
>> empuja(lista, "42")
[2, 3, "42"]


Enjoy!! 😄✨ (Spanish documentation coming soon!