Page namespace (page_namespace) | 0 |
Page title (without namespace) (page_title) | 'QX' |
Full page title (page_prefixedtitle) | 'QX' |
Old content model (old_content_model) | 'wikitext' |
New content model (new_content_model) | 'wikitext' |
Old page wikitext, before the edit (old_wikitext) | ''''QX''' is a minimal language made by [[User:↑]].
[[File:QX logo.png|thumb|alt=QX logo|Logo.]]
== Commands ==
{| class="wikitable"
|-
! Command !! What it does
|-
| Q [a] || Increments the current value at pointer by a. Can decrement if a is negative
|-
| X [a] [b] || If a <= previous item at pointer then go to previous item at pointer and jump to line b else go to next item at pointer.
|}
== Computational class ==
QX is [[Turing-complete]] by translation from unbounded [[brainfuck]].
{| class="wikitable"
! Command
! Translation
|-
| <code>+</code>
| <code>Q 1</code>
|-
| <code>-</code>
| <code>Q -1</code>
|-
| <code>></code>
| <code>X ∞ 0</code>
|-
| <code><</code>
| <code>X -∞ n</code>, where <code>n</code> is the next command
|-
| <code>[</code> and <code>]</code>
| <code>X ∞ 0 X 1 s X -∞ e1 X -∞ e2</code>, where <code>s</code> is after the corresponding <code>[</code>, <code>e1</code> is <code>X -∞ e2</code>, and <code>e2</code> is after the corresponding <code>]</code>
|}
Note that this assumes infinity is a valid constant. A translation from bounded brainfuck will avoid infinity:
{| class="wikitable"
! Command
! Translation
|-
| <code>+</code>
| <code>Q 1 X 257 0 X 256 d X 0 n1 X 0 n2 Q -256</code>, where <code>d</code> is <code>Q -256</code>, <code>n1</code> is <code>X 0 n2</code>, and <code>n2</code> is the next command
|-
| <code>-</code>
| <code>Q -1 X 255 0 X 0 n X -1 d1 X -1 d2 Q 256</code>, where <code>n</code> is the next command, <code>d1</code> is <code>X -1 d2</code> and <code>d2</code> is <code>Q 256</code>.
|-
| <code>></code>
| <code>X 256 0</code>
|-
| <code><</code>
| <code>X 0 n</code>, where <code>n</code> is the next command
|-
| <code>[</code> and <code>]</code>
| <code>X 256 0 X 1 s X 0 e1 X 0 e2</code>, where <code>s</code> is after the corresponding <code>[</code>, <code>e1</code> is <code>X 0 e2</code>, and <code>e2</code> is after the corresponding <code>]</code>
|}
There is also a translation from [[Brainpocalypse]]:
{| class="wikitable"
|-
! Brainpocalypse !! QX
|-
| {{cd|<}} || {{cd|X 0 n}} where n is next line
|-
| {{cd|>}} || {{cd|X ∞ 0}} where lim is the absolute limit of the numbers
|-
| {{cd|+}} || {{cd|Q 1}}
|-
| {{cd|-}} || {{cd|X ∞ 0 X 1 d X -1 s X -1 1 Q -1}}, where line <code>d</code> is <code>Q -1</code> and line <code>s</code> is <code>X -1 1</code>
|}
== Examples ==
=== [[Infinite loop]] ===
X 0 1
=== [[A+B Problem]] ===
Q ?
Q ?
If A and B must start separate:
Q ?
X 1 0
Q ?
X 1 6
X 0 12
Q -1
X 1 0
Q 1
X ∞ 0
X 0 4
[[Category:Languages]] [[Category:2025]]
== Lua interpreter ==
Made by [[User:Aadenboy]]
<pre>
assert(arg[1], "Argument 1 must be a file to interpret")
local file = io.open(arg[1], "r")
assert(file, "File not found")
local code = file:read("*a")
file:close()
local range = {1, 1}
local mem = {0}
local pointer = 1
local commands = {}
code = code:gsub("∞", "i")
for pos, qx, a, b in code:gmatch("()([QX])%s*([%d%-%?%.i]*)%s*([%d%-%?%.i]*)") do
a = a == "?" and "?" or (a == "i" and math.huge or (a == "-i" and -math.huge or tonumber(a)))
b = b == "?" and "?" or (b == "i" and math.huge or (a == "-i" and -math.huge or tonumber(b)))
local line = ({code:sub(0, pos):gsub("\n", "")})[2] + 1
local char = #code:sub(0, pos):match("\n?([^\n]+)$")
assert(a, line..":"..char..": "..qx.." expects at least one integer")
assert(qx == "Q" or b, line..":"..char..": X expects two integers")
table.insert(commands, {qx = qx, a = a, b = qx == "X" and b})
end
local i = 1
local steps = 0
repeat
steps = steps + 1
local c = commands[i]
local a = c.a == "?" and (tonumber(io.read()) or 0) or c.a
local b = c.b == "?" and (tonumber(io.read()) or 0) or c.b
if c.qx == "Q" then
i = i + 1
mem[pointer] = mem[pointer] + a
else
local pre = mem[pointer-1] or 0
pointer = pointer + (a <= pre and -1 or 1)
mem[pointer] = mem[pointer] or 0
i = a <= pre and b or i + 1
end
range = {math.min(range[1], pointer), math.max(range[2], pointer)}
until i < 1 or i > #commands or steps >= (tonumber(arg[2]) or math.huge)
print(steps.." steps\nPointer at "..pointer.."\nMemory:")
for i=range[1], range[2] do
print("\t["..i.."]: "..mem[i])
end
</pre>
[[Category:Implemented]][[Category:Turing tarpits]][[Category:Turing complete]]' |
New page wikitext, after the edit (new_wikitext) | ''''QX''' is a minimal language made by [[User:↑]].[[User:↑|why is there a filter rule]]
[[File:QX logo.png|thumb|alt=QX logo|Logo.]]
== Commands ==
{| class="wikitable"
|-
! Command !! What it does
|-
| Q [a] || Increments the current value at pointer by a. Can decrement if a is negative
|-
| X [a] [b] || If a <= previous item at pointer then go to previous item at pointer and jump to line b else go to next item at pointer.
|}
== Computational class ==
QX is [[Turing-complete]] by translation from unbounded [[brainfuck]].
{| class="wikitable"
! Command
! Translation
|-
| <code>+</code>
| <code>Q 1</code>
|-
| <code>-</code>
| <code>Q -1</code>
|-
| <code>></code>
| <code>X ∞ 0</code>
|-
| <code><</code>
| <code>X -∞ n</code>, where <code>n</code> is the next command
|-
| <code>[</code> and <code>]</code>
| <code>X ∞ 0 X 1 s X -∞ e1 X -∞ e2</code>, where <code>s</code> is after the corresponding <code>[</code>, <code>e1</code> is <code>X -∞ e2</code>, and <code>e2</code> is after the corresponding <code>]</code>
|}
Note that this assumes infinity is a valid constant. A translation from bounded brainfuck will avoid infinity:
{| class="wikitable"
! Command
! Translation
|-
| <code>+</code>
| <code>Q 1 X 257 0 X 256 d X 0 n1 X 0 n2 Q -256</code>, where <code>d</code> is <code>Q -256</code>, <code>n1</code> is <code>X 0 n2</code>, and <code>n2</code> is the next command
|-
| <code>-</code>
| <code>Q -1 X 255 0 X 0 n X -1 d1 X -1 d2 Q 256</code>, where <code>n</code> is the next command, <code>d1</code> is <code>X -1 d2</code> and <code>d2</code> is <code>Q 256</code>.
|-
| <code>></code>
| <code>X 256 0</code>
|-
| <code><</code>
| <code>X 0 n</code>, where <code>n</code> is the next command
|-
| <code>[</code> and <code>]</code>
| <code>X 256 0 X 1 s X 0 e1 X 0 e2</code>, where <code>s</code> is after the corresponding <code>[</code>, <code>e1</code> is <code>X 0 e2</code>, and <code>e2</code> is after the corresponding <code>]</code>
|}
There is also a translation from [[Brainpocalypse]]:
{| class="wikitable"
|-
! Brainpocalypse !! QX
|-
| {{cd|<}} || {{cd|X 0 n}} where n is next line
|-
| {{cd|>}} || {{cd|X ∞ 0}} where lim is the absolute limit of the numbers
|-
| {{cd|+}} || {{cd|Q 1}}
|-
| {{cd|-}} || {{cd|X ∞ 0 X 1 d X -1 s X -1 1 Q -1}}, where line <code>d</code> is <code>Q -1</code> and line <code>s</code> is <code>X -1 1</code>
|}
== Examples ==
=== [[Infinite loop]] ===
X 0 1
=== [[A+B Problem]] ===
Q ?
Q ?
If A and B must start separate:
Q ?
X 1 0
Q ?
X 1 6
X 0 12
Q -1
X 1 0
Q 1
X ∞ 0
X 0 4
[[Category:Languages]] [[Category:2025]]
== Lua interpreter ==
Made by [[User:Aadenboy]]
<pre>
assert(arg[1], "Argument 1 must be a file to interpret")
local file = io.open(arg[1], "r")
assert(file, "File not found")
local code = file:read("*a")
file:close()
local range = {1, 1}
local mem = {0}
local pointer = 1
local commands = {}
code = code:gsub("∞", "i")
for pos, qx, a, b in code:gmatch("()([QX])%s*([%d%-%?%.i]*)%s*([%d%-%?%.i]*)") do
a = a == "?" and "?" or (a == "i" and math.huge or (a == "-i" and -math.huge or tonumber(a)))
b = b == "?" and "?" or (b == "i" and math.huge or (a == "-i" and -math.huge or tonumber(b)))
local line = ({code:sub(0, pos):gsub("\n", "")})[2] + 1
local char = #code:sub(0, pos):match("\n?([^\n]+)$")
assert(a, line..":"..char..": "..qx.." expects at least one integer")
assert(qx == "Q" or b, line..":"..char..": X expects two integers")
table.insert(commands, {qx = qx, a = a, b = qx == "X" and b})
end
local i = 1
local steps = 0
repeat
steps = steps + 1
local c = commands[i]
local a = c.a == "?" and (tonumber(io.read()) or 0) or c.a
local b = c.b == "?" and (tonumber(io.read()) or 0) or c.b
if c.qx == "Q" then
i = i + 1
mem[pointer] = mem[pointer] + a
else
local pre = mem[pointer-1] or 0
pointer = pointer + (a <= pre and -1 or 1)
mem[pointer] = mem[pointer] or 0
i = a <= pre and b or i + 1
end
range = {math.min(range[1], pointer), math.max(range[2], pointer)}
until i < 1 or i > #commands or steps >= (tonumber(arg[2]) or math.huge)
print(steps.." steps\nPointer at "..pointer.."\nMemory:")
for i=range[1], range[2] do
print("\t["..i.."]: "..mem[i])
end
</pre>
[[Category:Implemented]][[Category:Turing tarpits]][[Category:Turing complete]]' |