Turing Complete DOM Programming Language

From Esolang
Jump to navigation Jump to search
Turing Complete DOM Programming Language
Designed by Andriy
Appeared in 2022
Type system dynamic
Dimensions one-dimensional
Computational class Turing-complete
Major implementations itch.io download link
Dialects None
Influenced by XML, Python
File extension(s) .xml

Turing Complete DOM Programming Language is an esoteric programming language created by User:Andriy where every code is also an xml file. You can download it here.

Architecture

Functions

The code is divided to functions. Each function has two attributes, a name and an id. Its possible to call a function using its id or using its name. The id is supposed to be unique but if it isn't calling by id will call the one that appears the latest. The name of the function is not meant to be unique. If you try to call a function using its name, and multiple functions exist with this name, the interpreter will choose a random one and run it. This can be used to create a primitive random number generator.

When the xml file is parsed and the code is loaded to memory, a dictionary is created that associates each function name with a list of ids. If two functions share the same id and name, only the last one will be called. However, if two functions have different names but the same id, calling the first one by name will cause the second one to be called.

When the code starts, it will call the main function using its name. If the programmer chooses to create multiple functions with the name main, the interpreter will choose a random one and run it.

Lines

Each function is divided to lines. Lines do not require any attributes. Their parameters are command and up to 4 arguments (arg1, arg2, arg3, arg4). Most functions will only require one or two arguments. When a function is called, it will run all the lines one by one in the order listed in the function. See #Commands for a list of commands and how many arguments each requires.

Hello World

Here is a code that prints hello world:

<?xml version="1.0" ?>
 
 <code>
 	<function name="main" id="1">
 		<line>
 			<command>PRINT</command>
 			<arg1>Hello, world!</arg1>
 		</line>
 	</function>
 </code>

Fibonacci numbers

<?xml version="1.0" ?>
 
 <code>
 	<function name="main" id="1">
 		<line>
 			<command>SET INT</command>
 			<arg1>x</arg1>
 			<arg2>0</arg2>
 		</line>
 		
 		<line>
 			<command>SET INT</command>
 			<arg1>y</arg1>
 			<arg2>1</arg2>
 		</line>
 		
 		<line>
 			<command>SET STRING</command>
 			<arg1>text</arg1>
 			<arg2>How many numbers from Fibonacci's sequence do you want to see? </arg2>
 		</line>
 		
 		<line>
 			<command>INPUT</command>
 			<arg1>n</arg1>
 			<arg2>text</arg2>
 		</line>
 		
 		<line>
 			<command>TO INT</command>
 			<arg1>n</arg1>
 			<arg2>n</arg2>
 		</line>
 		
 		<line>
 			<command>SET INT</command>
 			<arg1>m</arg1>
 			<arg2>0</arg2>
 		</line>
 		
 		<line>
 			<command>SET INT</command>
 			<arg1>1</arg1>
 			<arg2>1</arg2>
 		</line>
 		
 		<line>
 			<command>LESS</command>
 			<arg1>m</arg1>
 			<arg2>n</arg2>
 			<arg3>fibo</arg3>
 			<arg4>nothing</arg4>
 		</line>
 	</function>
 	
 	<function name="fibo" id="2">
 		<line>
 			<command>PRINT VAR</command>
 			<arg1>x</arg1>
 		</line>
 		
 		<line>
 			<command>ADD</command>
 			<arg1>t</arg1>
 			<arg2>x</arg2>
 			<arg3>y</arg3>
 		</line>
 		
 		<line>
 			<command>TO INT</command>
 			<arg1>x</arg1>
 			<arg2>y</arg2>
 		</line>
 		
 		<line>
 			<command>TO INT</command>
 			<arg1>y</arg1>
 			<arg2>t</arg2>
 		</line>
 		
 		<line>
 			<command>ADD</command>
 			<arg1>m</arg1>
 			<arg2>m</arg2>
 			<arg3>1</arg3>
 		</line>
 		
 		<line>
 			<command>LESS</command>
 			<arg1>m</arg1>
 			<arg2>n</arg2>
 			<arg3>fibo</arg3>
 			<arg4>nothing</arg4>
 		</line>
 	</function>
 
 	<function name="nothing" id="3"></function>
 </code>

Commands

This programming language has 23 commands:

Command Description
TYPE <arg1> Prints the value of <arg1> without a new line character at the end.
PRINT <arg1> Prints the value of <arg1> with a new line character at the end.
RUN FUNCTION BY NAME <arg1> Runs a function with the name <arg1>. If there are multiple with the same name, it will choose a random one.
RUN FUNCTION BY ID <arg1> Runs a function with the id <arg1>. If the are multiple functions with that id, it will run the last one. Please make sure all functions have different ids, or at the very least that functions with different names have different ids, otherwise when calling a function by name it might end up calling a function with a different name.
SLEEP <arg1> Sleeps <arg1> seconds.
EXIT Exits from the code
SET STRING <arg1> <arg2> Sets the value of variable <arg1> to the string value <arg2>. If the value does not exit, it gets created. Variables are dynamically-typed.
SET INT <arg1> <arg2> Sets the value of variable <arg1> to the int value <arg2>. If the value does not exit, it gets created. Variables are dynamically-typed.
SET FLOAT <arg1> <arg2> Sets the value of variable <arg1> to the float value <arg2>. If the value does not exit, it gets created. Variables are dynamically-typed.
TYPE VAR <arg1> Prints the value of variable <arg1> without a new line character at the end.
PRINT VAR <arg1> Prints the value of variable <arg1> with a new line character at the end.
ADD <arg1> <arg2> <arg3> All arguments must be variables. <arg2>+<arg3> => arg1. If you want arg2 or arg3 to be a number for example 5, define a variable called 5 with the value 5. If both arg1 and arg2 are string variables, it will concatenate them.
SUBTRACT <arg1> <arg2> <arg3> All arguments must be variables. <arg2>-<arg3> => arg1. If you want arg2 or arg3 to be a number for example 5, define a variable called 5 with the value 5.
MULTIPLY <arg1> <arg2> <arg3> All arguments must be variables. <arg2>*<arg3> => arg1. If you want arg2 or arg3 to be a number for example 5, define a variable called 5 with the value 5.
DIVIDE <arg1> <arg2> <arg3> All arguments must be variables. <arg2>/<arg3> => arg1. If you want arg2 or arg3 to be a number for example 5, define a variable called 5 with the value 5.
POWER <arg1> <arg2> <arg3> All arguments must be variables. <arg2>^<arg3> => arg1. If you want <arg2> or <arg3> to be a number for example 5, define a variable called 5 with the value 5.
TO INT <arg1> <arg2> Converts variable <arg2> to int and stores the result in <arg1>. Does not affect <arg2> unless <arg1> and <arg2> are the same variable.
TO FLOAT <arg1> <arg2> Converts variable <arg2> to float and stores the result in <arg1>. Does not affect <arg2> unless <arg1> and <arg2> are the same variable.
TO STRING <arg1> <arg2> Converts variable <arg2> to int and stores the result in <arg1>. Does not affect <arg2> unless <arg1> and <arg2> are the same variable.
EQUALS <arg1> <arg2> <arg3> <arg4> Checks if variables <arg1> and <arg2> are equal to each other. If they are runs function <arg3>, else runs function <arg4>. If you only want function <arg3> or function <arg4> you can create a function called nothing (or any other name you want) that do anything and put it as an argument. <function name="nothing" id="3"></function>
MORE <arg1> <arg2> <arg3> <arg4> Checks if variable <arg1> is more than variable <arg2>. If they are runs function <arg3>, else runs function <arg4>. If you only want function <arg3> or function <arg4> you can create a function called nothing (or any other name you want) that do anything and put it as an argument. <function name="nothing" id="3"></function>
LESS <arg1> <arg2> <arg3> <arg4> Checks if variable <arg1> is less than variable <arg2>. If they are runs function <arg3>, else runs function <arg4>. If you only want function <arg3> or function <arg4> you can create a function called nothing (or any other name you want) that do anything and put it as an argument. <function name="nothing" id="3"></function>
INPUT <arg1> <arg2> Types the message stored in <arg2> and waitts for the user to enter a value which is later stored in <arg1> as a string. If you want an integer or float value, you must explicity convert it in the next line.