Tarflex

Original Code:
Code at Runtime:



Output:


Errors:


Input:


Sample nr 1 (adding 2 numnbers):
read a
read b

:l1
dec a
inc r
if a > z goto l1

:l2
dec b
inc r
if b > z goto l2

outv r

Sample nr 2 (printing "Hello World" 5 times with reflection):
inc a
inc a
inc a
inc a
inc a
:l2
push l1
outs Hello
push l1
outs World
push l1
outnl
dec a
if a > z goto l2
:l1
!selfprint

Sample nr 3 (reversing instructions with reflection):
:orig
outs message 1
outs message 2
outs message 3
:int
if isempty orig goto prev
unshift rev head orig
shift orig
if z == z goto int
:prev
outnl
:rev
!selfprint


Tarflex Language Specification:

General rules:
  1. There are basic instructions for incrementing, decrementing, copying, jumping, storing into an indexed memory and retrieving data from it, reading from input and writing to the output.
  2. The language is reflective - the program may alter its program code at runtime using specific instructions. Because of its minimalistic nature, the program can be viewed as a list of labels and every label can be viewed as a list of instructions. There are instructions for adding or removing other instructions or labels.
  3. To output the program code at any moment use the !selfprint instruction.
  4. Every variable is initialized with 0. There are no numeric literals.
  5. Comments start with a "/" and must be on their own line.
  6. Empty lines are ignored.
Basic instructions:
inc varincrements var by 1
dec vardecrements var by 1
mov dest_var source_varcopies source_var to dest_var
if var1 < var2 goto dest_labelperforms a jump to dest_label if the condition is met - other supported relations are: <=, ==, >=, >, !=

Memory instructions:
store adress_var source_varstores source_var in memory at adress adress_var
load dest_var adress_varretrieves the value stored in memory at adress adress_var and copies it in dest_var

IO instructions:
read dest_varreads a value from the input buffer and stores it in dest_var
outv varoutputs the value stored in var
outs any_string...outputs all that follows on the same line
outnloutputs a new line

Program alteration instructions:
if isempty label goto dest_label jumps to dest_label if label contains no instructions
push dest_label adds the next instruction at the end of the list defined by dest_label
push dest_label head/last source_label adds the first/last instruction from the list defined by source_label at the end of the list defined by dest_label
pop label removes the last instruction from the list defined by label
unshift dest_label adds the next instruction at the beginning of the list defined by dest_label
unshift dest_label head/last source_label adds the first/last instruction from the list defined by source_label at the beginning of the list defined by dest_label
shift label removes the first instruction from the list defined by label
pushlab dest_label new_label adds new_label after dest_label
unshiftlab dest_label new_label adds new_label before dest_label
dellab label removes label; the instructions of label are left unchanged and thus merged with the list of instructions defined by the previous label
delwholelab label erases label and its contents
!selfprint outputs the program code

No comments:

Post a Comment