Metat

From Esolang
Jump to navigation Jump to search

Metat is an interpretered meta programming language. It's main goal is to act as an interpreter or parser itself.

Syntax

The Metat program is a parser in itself, so it has to load a source file. It will run through the source file character by character. The program is segmented into the initialization segment, and the rule segment. In the initialization segment you will declare states, registers and allocate memory.


state myState declares a state that the parser can be in.

register n type defined a numbered register n with the specified type type. There can be a total of 16 registers, ranging from 0 - 15.

Valid types are: char string uint8 uint16 uint32 int8 int16 int32 int uint

alloc amount regx allocates the specified amount of bytes and binds them to the register regx


Registers are referenced as regx where x is the number of the register.


Examples

A Brainfuck interpreter.

::A Brainfuck interpreter written in metat.
state top
state fast
state re
register 0 uint8
register 1 uint16
register 2 uint8
register 3 int16
start
	alloc 65535 reg0
case top
	on +
		take reg0 reg1 reg2
		add reg2 1
		put reg2 reg0 reg1
	on -
		take reg0 reg1 reg2
		sub reg2 1
		put reg2 reg0 reg1
	on <
		sub reg1 1
	on >
		add reg1 1
	on [
		take reg0 reg1 reg2
		eql 0
		if
			then fast
	on ]
		take reg0 reg1 reg2
		eql 0
		if
			then re
	on .
		take reg0 reg1 reg2
		print char reg2
	on ,
		get char reg2
		put reg2 reg0 reg1
case fast
	start
		set reg3 0
	on [
		add reg3 1
	on ]
		sub reg3 1
		eql reg3 0 reg2
		if
			then top
		less reg3 0 reg2
		if
			error Unbalanced brackets
	eof
		error Unbalanced brackets
case re
	start
		set reg3 0
	on [
		add reg3 1
		rewind 2
	on ]
		sub reg3 1
		eql reg3 0 req2
		if
			then top
		less reg3 0 reg2
		if
			error Unbalanced brackets
		rewind 2
	eof
		error Unbalanced brackets