-
Notifications
You must be signed in to change notification settings - Fork 2
Introduction
· I/O »
Learning Pepe isn't hard. Understanding Pepe is pretty easy — writing appropriate control flow can be hard.
A program is a line of commands and nothing else. There are no block structures like ifs, whiles or fors.
Every command has common structure: An R
or r
followed by a various amount of E
s and e
s. It is a bit similar to object object oriented languages: object.method()
, here the letter R is the object and letters E are the method.
A full list of commands is available here.
Each character not in REre
is a comment. Also, every character following a #
until the end of line will also be considered a comment.
Pepe has two stacks, represented by characters R
and r
mentioned above. Each command runs on one of them, for example, REEE
will run on stack R
.
Each stack has a pointer, starting at the beginning of each stack.
Each stack is initially empty, but if a get
operation is performed, a 0
will automatically be pushed and returned.
As previously said, there are no block structures like if
, while
or for
. None. Pepe allows you to create labels, but these are quite different than those in other languages. You don't define a constant name in the source code — they're dynamic.
The command REE
will create a label with name of the active value in the stack.
For example, we will start the stack R
with a 1 in it: REEEEE
(increment) and then define a label REE
. It will use the active value on the stack R
(which at the moment is 1), defining a label 1
in the position of the label. This makes it impossible to refer to a label before it has been created.
There are two goto commands: ReE
is goto [R] if [R] == [r]
— it will go to the label named the active value in stack R
, but only if active values in both stacks are equal (do nothing otherwise). For example, it will goto label 2
if stacks are [>2,1]
and [1,>2]
, where >
is a pointed value. The second command, Ree
is the reverse: goto [R] if [R] != [r]
— will goto if the values aren't equal.
With one of Pepe updates, command flags has been added, making control flow a lot easier and saving few bytes on moving the pointer and duplicating things.
A flag is created using "wrong syntax", for example ...RREEE...
— there are two R
, but there is no command without E
; another example can be EREE...
— there is one E
used before any R
.
The point of flags is to change behavior of a command or entire program. Most flags are used for improved stack management, for example the command RE
(push 0) has 2 flags: rRE
will insert the value at the next position instead, RRE
will prepend the value to the stack.
There is one exceptional flag that is used for greatly improved control flow — it is available for the commands REE
(create label), ReE
and Ree
(goto labels). REE
will skip all commands until a REe
(return). ReE
and Ree
, if true, will skip all commands until a REe
. The commands previously could only simulate a do...while
loop, but the addition of flags made it possible to simulate any kind of loop.
Examples of implementations (X is either E
or e
depending on the condition, Y is the swapcase of X):
-
do...while:
REE ... ReX
-
if...end:
rREE ... REe ReX
(also called a function) -
while...end:
rEE rreY ... reX reY rEe
More details about Pepe syntax: Syntax
A lot of Pepe functionality can be found in the list of commands. It was made in such a way that it should be possible to learn Pepe using it, once you learned how the syntax works.
If you feel like if this wiki can be improved, you can edit it or add a new page on any subject related to Pepe. This can be a page with various tips, examples, anything you'd like.
· I/O »