Pepelang!
2022 Jul 15
See all posts
Pepelang!
What is Pepelang?
- Pepelang is an open source programming language supported by me
- Easy to learn and get started with (if you know spanish)
- Built-in sequential execution (get your concurrency out of here! who needs speed anyways?)
- Open for PRs and improvements!
Project
Pepelang was born out of two personal desires,
- Learning how to build my own programming language
- More programming content available for the spanish speaking community
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
Booleans:
verdad (true) or falso (false)
Arithmetics supported:
- addition (+)
- substraction (-)
- multiplication (*)
- division (/)
- not operator (!)
- single operands (++) (–)
>> 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:
- Declared using the fn keyword
- Treated as high order functions (supports recursion and callback functions)
- Can take any number of parameters and such are treated as expressions.
- Support closure
>> 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: Returns the length on a given value. Supported by strings, integers and arrays
>> var lista = [1, 2, 3]
>> tam(lista)
2
- Pon: Prints a value into the console
>> pon("Imprime este mensaje!")
imprime este mensaje!
>> var lista = [1, 2, 3]
>> primero(lista)
1
>> ultimo(lista)
3
- Rest: Removes the first element of a given array
>> var lista = [1, 2, 3]
>> rest(lista)
[2, 3]
- Empuja: Inserts an element at the end of the array
>> empuja(lista, "42")
[2, 3, "42"]
Enjoy!! 😄✨ (Spanish documentation coming soon!
Pepelang!
2022 Jul 15 See all postsWhat 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:
"hello world"
How to use?
Requirements:
Install
You'll need to install Go
Usage
Call pepe in your terminal
You can also call a pepe program:
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 valueBooleans:
Arithmetics supported:
Arrays:
Indexes are treated as expressions, thus, all of the following are valid:
Dictionaries:
Keys are literal values and values are parsed as expressions
If/Else statements:
Declared using the
si # (if)
andsino # (else)
, can take any expression value and evaluate the code accordinglyReturn statements:
Declared using the
retonar
keyword (as in previous example)Function literals:
Built in functions:
Primero: Gets the first element of a given array
Ultimo: Gets the last element of a given array
Enjoy!! 😄✨ (Spanish documentation coming soon!
Daniel Ratmiroff © - site made with: blogmaker - credit to Vitalik Buterin