Skip to content

Instantly share code, notes, and snippets.

@eraserhd
Created June 19, 2012 01:36
Show Gist options
  • Save eraserhd/2951827 to your computer and use it in GitHub Desktop.
Save eraserhd/2951827 to your computer and use it in GitHub Desktop.
Proposed syntax of compiled stack-based language
% A comment starts with '%'
123 -42 0 0xffff 0xDEAD 0b111101 % Numeric literals
"Hello, World!\r\n\t" % String literals
true false % Boolean literals
[ 2 3 4 ] % List of integers
printf + * / - on? % Names
-> % Naming operator
<- % Non-executing value-of operator
42 -> meaning-of-life % Name the value '42' 'meaning-of-life'
meaning-of-life % Dereference 'meaning-of-life' (executes it if a function)
<- meaning-of-life % Dereference 'meaning-of-life' (does not execute it if a function)
{ ... } % Function literal
{ 1 + } -> +1 % Create a function which takes one argument and adds 1, name
% it +1
2 +1 . % Push 2 on stack, call +1 (leaving 3 on the stack), call '.'
{ % Make a new function
->a ->b % Pop and name 'a' and 'b'
a b + % Compute and push a+b
} ->f % Name the function f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment