cicada-nymph -- a forth-like language for to teach

the little nymph is for teaching purpose only.

it reuses the code and idea
of the early version of cicada-language,

to teach my friends
how to implement a interpreter
of a simple programming language.

I will use assembly language (FASM for x86-64)
to implement the interpreter.

the programming language to be implemented
is a threaded-code based (Forth-like) language.

the following shows how to define "if" & "else" & "then" by "define-macro"

: if
  << string[address, length] --
     address, string[address, length] >>
  *false?branch* save-into,jo-heap
  *current-free-address,jo-heap* xx|swap|x
  0 save-into,jo-heap
  end
; define-macro

: else
  << address, string[address, length] --
     address, string[address, length] >>
  *branch* save-into,jo-heap
  x|swap|xx
  *current-free-address,jo-heap* xxx|swap|x
  0 save-into,jo-heap
  << address, string[address, length], address >>
  *current-free-address,jo-heap*
  over sub *jo-size* div
  swap save
  end
; define-macro

: then
  << address, string[address, length] --
     string[address, length] >>
  x|swap|xx
  *current-free-address,jo-heap*
  over sub *jo-size* div
  swap save
  end
; define-macro

the following shows how to define factorial

: factorial
  << number -- number >>
  dup one? if
    end
  then
  dup sub1 factorial
  mul
  end
; define-function

for the code and more info ::

code on github
view the code in a fake emacs org-mode

the cicada nymph is for teaching purpose at first
thus many simplifications on features are made

and
the design of cicada language is influenced by scheme and forth and joy and smalltalk
I do not think, and will not say, which is "better" and "more powerful" than which
but some interesting features are to be designed for cicada language
I will post about them in the future ^-^

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Joy is a more powerful

abstract and interesting stack based language than forth, but it similarly lacks variables.

http://www.kevinalbrecht.com/code/joy-mirror/index.html

cicada-nymph is different from cicada-language

the cicada nymph is for teaching purpose at first
thus many simplifications on features are made

and
the design of cicada language is influenced by scheme and forth and joy and smalltalk
I do not think, and will not say, which is "better" and "more powerful" than which
but some interesting features are to be designed for cicada language
I will post about them in the future ^-^

the following shows one way of using named-global-variable in cicada nymph
more ways of using named-global-variable can be achieved, for example, by "define-macro"

you get the address of the variable *three*
by add "address" in front of it
"address" is just a macro defined by "define-macro"

233 : *three* ; define-variable
: add-three *three* add end ; define-function
1 add-three . << 234 >>

: fix-*three* 3 address *three* save end ; define-function
fix-*three*
1 add-three . << 4 >>

it is true that you can NOT use named-local-variable in cicada nymph
you can use unnamed-local-variable, and it is achieved by argument-stack