~otheb/stf

2d77b09d88c1cd3549c85d33b6019676e05b4930 — Olie Ayre 3 years ago 512814b
Write first design draft
1 files changed, 57 insertions(+), 0 deletions(-)

A design
A design => design +57 -0
@@ 0,0 1,57 @@
\ DESIGN

\ tokens
-?[0-9]+u?l? \ integer
-?[0-9]*\.[0-9]+d? \ float
".*" \ string
(true|false) \ bool

\ line comment
( block comment ( that nests ) )

\ if
<condition> if <iftrue> [else <iffalse>] end
\ while/until
<condition> while|until <body> end
\ iota
<n> repeat <body> end
<start> <end> loop <body> end
<start> <end> <step> sloop <body> end

\ variable
var <name>
= <name>
(
	All variables are stack pointers.
	Assigning to a variable just changes the address to the top of the stack.
	Reading a variable pushes the pointer value, but any action on the pointer
	acts on the addressed value.
)

\ function
fn [{ <types> }] <name> [{ <returns> }] <body> end
\ anonymous function (for loops etc.)
{ <body> }

\ block
do <body> end

\ types
type <name> <members> end
	\ member
	<name> : <type>


\ macro system ( possibly )
\ example declaring variables `a` to `e`
%[ 0 5 loop var i "var" "abcde" [i] end ]%
(
	Section between %[ ]% is executed and the remaining stack is converted to
	code (all stack items converted to strings, each treated as a word, then
	parsed as normal).
)
\ resulting stack from example being evaluated
"var" "a" "var" "b" "var" "c" "var" "d" "var" "e"
\ converted to code
var a var b var c var d var e
\ then evaluated