It’s been a bit, but I hope it’s worth it. StackLang, part 5: compiling to C!
StackLang, part 4: an interpreter. Here we go again!
This time, the goal is to actually get code running
StackLang, part 3: parsing. This is going to be the most complicated one thus far! Onward.
StackLang, part 2: lexing.
It’s quite often the simplest part of implementing a programming language (although parsers for s-expression based languages come close), but it’s still something that needs done. So here we go!
I enjoy writing programming languages. Example: Tiny. Let’s do that again.
This time, StackLang:
{
@[n fact]
1
{ n 1 - $fact fact n * }
N 1 <= if
} @fact
5 $fact fact writeln
Bit of gibberish there, I suppose, but the goal is to write everything in a postfix/stack based model. So n 1 - $fact fact n *
is equivalent to fact(fact, n - 1) * n
in a more traditional language.
Over the next few posts, I hope to write up where I am thus far and what’s next.
Given a list of stacks of syntax 1 and instructions in the form syntax 2, apply each instruction to pop
qty
items from the stacksrc
and put them ondst
one at a time.
Syntax 1: Stacks
[D]
[N] [C]
[Z] [M] [P]
1 2 3
Syntax 2: Instructions
move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2