RosettaCodeData/Task/Quine/NetRexx/quine.netrexx

115 lines
2.5 KiB
Plaintext

/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
Q = "'"
S = "\\"
N = "\n"
A = "&"
code = [ -
'/* NetRexx */', -
'options replace format comments java crossref savelog symbols nobinary', -
'', -
'Q = "&QS"', -
'S = "&ESC"', -
'N = "&NL"', -
'A = "&AMP"', -
'code = [ -', -
'&REP', -
' ]', -
'', -
'pgm = ""', -
'txt = ""', -
'loop t_ = 0 for code.length', -
' txt = txt || " " || Q || code[t_] || Q || ", -" || N', -
' end t_', -
'txt = txt.strip("T", N)', -
'txt = txt.delstr(txt.lastpos(","), 1)', -
'', -
'K = ""', -
'K[0] = 5', -
'K[1] = A"NL"', -
'K[2] = A"AMP"', -
'K[3] = A"ESC"', -
'K[4] = A"QS"', -
'K[5] = A"REP"', -
'loop c_ = 0 for code.length', -
' loop v_ = 1 to K[0]', -
' T = K[v_]', -
' if code[c_].pos(T) <> 0 then do', -
' parse code[c_] pre(T)post', -
' select case T', -
' when K[1] then do', -
' code[c_] = pre || S || "n" || post', -
' end', -
' when K[2] then do', -
' code[c_] = pre || A || post', -
' end', -
' when K[3] then do', -
' code[c_] = pre || S || S || post', -
' end', -
' when K[4] then do', -
' code[c_] = pre || Q || post', -
' end', -
' when K[5] then do', -
' code[c_] = txt', -
' end', -
' otherwise nop', -
' end', -
' end', -
' end v_', -
' pgm = pgm || code[c_].strip("T") || N', -
' end c_', -
'pgm = pgm.strip("T", N) || N', -
'say pgm', -
'', -
'return', -
'' -
]
pgm = ""
txt = ""
loop t_ = 0 for code.length
txt = txt || " " || Q || code[t_] || Q || ", -" || N
end t_
txt = txt.strip("T", N)
txt = txt.delstr(txt.lastpos(","), 1)
K = ""
K[0] = 5
K[1] = A"NL"
K[2] = A"AMP"
K[3] = A"ESC"
K[4] = A"QS"
K[5] = A"REP"
loop c_ = 0 for code.length
loop v_ = 1 to K[0]
T = K[v_]
if code[c_].pos(T) <> 0 then do
parse code[c_] pre(T)post
select case T
when K[1] then do
code[c_] = pre || S || "n" || post
end
when K[2] then do
code[c_] = pre || A || post
end
when K[3] then do
code[c_] = pre || S || S || post
end
when K[4] then do
code[c_] = pre || Q || post
end
when K[5] then do
code[c_] = txt
end
otherwise nop
end
end
end v_
pgm = pgm || code[c_].strip("T") || N
end c_
pgm = pgm.strip("T", N) || N
say pgm
return