It's official. Keg is now a transpiled language, as interpreting it was just too hard. Here is a guide of how everything now works
graph TB
First[Preprocessor] --> Second
Second[Uncompressor] --> Third
Third[Parser] --> Fourth
Fourth[Translator] --> Fifth
Fifth[Execution] --> Output
Characters in the range of a-z
and A-Z
will be pushed as so:
letter()
As such, the program ABC
would be transpiled as:
A(); B(); C()
And Hello World
would become:
H(); e(); l(); l(); o(); space(); W(); o(); r(); l(); d()
This allows for letters to be redefined as macros if that makes sense. (More on that later)
Numbers in the range of 0-9
would follow as such:
0: zero()
1: one()
2: two()
3: three()
4: four()
5: five()
6: six()
7: seven()
8: eight()
9: nine()
Thenceforth, 89
would become:
eight(); nine()
Quite simple really:
+: add(stack.pop(), stack.pop())
-: minus(stack.pop(), stack.pop())
*: times(stack.pop(), stack.pop())
/: divide(stack.pop(), stack.pop())
%: modulo(stack.pop(), stack.pop())
I'mma start using a new way of writing these. All functions assume the parameters stack.pop(), stack.pop()
=: eq()
≠: nq()
>: gt()
<: lt()
≥: ge()
≤: le()
≬: g0()
!: length()
$: swap()
^: reverse()
:: duplicate()
": r_shift()
': l_shift()
,: nice()
.: raw()
?: _input()
~: random()
_: stack.pop()
Unlike all prior sections, this section shan't be so brief. Why? Because the humble [...|...]
isn't just a function you see.
The general form will become:
if bool(stack.pop):
...
else:
...
But what if there is only one section? (i.e. [...]
)
if bool(stack.pop()):
...
But what if there is an empty ifTrue
section but a filled ifFalse
section? (i.e. [|...]
)
if bool(stack.pop()):
pass
else:
...
Although maybe this is more appropriate:
if not bool(stack.pop()):
...
I mean, really, the only person bothering with this is those making transpilers.
These are a bit harder, as, well, Keg loops are a little different. Given the normal counted loop (no vars, integer as condition):
for _ in _loop_eval(stack.pop())
...
It is important to note that _loop_eval()
is defined as such:
def _loop_eval(expr):
if type(expr) in [int, chr]:
return range(expr)
else:
return expr
But what if there are three parts? (i.e. (count|var|code)
)
for var in _loop_eval(count):
code
But what if there isn't a loop condition?
length()
for _ in _loop_eval(stack.pop()):
...
Written with StackEdit.