8
1
Your task is "simple" should you choose to accept it.
Write an HQ9+ compiler in a language of your choice.
HQ9+ has four commands (as you may be able to tell) H prints "Hello, World!" Q prints out the source code (this can either be the compiled source or HQ9+ source for the purpose of this challenge),9 prints out the lyrics to 99 bottles of beer on the wall, and + is essentially a noop.
Your submission should be written in some language X, and should take input of HQ9+ source and output a program in X.
Wait, I know what you're thinking. This is not a duplicate of Creating a HQ9+ interpreter as it should not run HQ9+ code, but rather compile it. It should output a fully functional program.
Rules
- Language X should satisfy the traditional definition of a language
- Standard loopholes disallowed
- This is code golf (shortest program in bytes wins)
- Your solution must be testable
- X cannot be HQ9+ or an extension of HQ9+
Clarifications
There has been some confusion as to what the q command should do. I had originally thought that it would output the compiled code (i.e code in langauge X), but my reference implementation outputs the hq9+ code. I would like to see either one depending on your golfing preferences.
What would
HH
produce? – Leaky Nun – 2016-07-01T00:07:28.933Hello, World!Hello, World!@LeakyNun – Rohan Jhunjhunwala – 2016-07-01T00:10:28.127
@LeakyNun Presumably
Hello, World!\nHello, World!\n
– Mego – 2016-07-01T00:10:39.310can the output language be HQ9+? – Maltysen – 2016-07-01T00:12:03.487
No, adding that to the specs – Rohan Jhunjhunwala – 2016-07-01T00:15:28.653
4This would be a perhaps better challenge for languages X and Y to be the same. – Conor O'Brien – 2016-07-01T00:22:33.443
Perhaps but its too late now – Rohan Jhunjhunwala – 2016-07-01T00:23:24.877
It's not too late. There's only one valid answer currently (mine), and it wouldn't be invalidated by that rule change. Additionally, banning extensions of HQ9+ (like those found in the "See Also" section of this page) is probably a good idea.
– Mego – 2016-07-01T00:26:35.367Ok altering the challenge – Rohan Jhunjhunwala – 2016-07-01T00:35:25.840
Dr Green Eggs. It is not I talked about how it is not an interpeter it is different because it is a compiler. – Rohan Jhunjhunwala – 2016-07-01T00:48:14.793
@RohanJhunjhunwala Yes I know, but I think the difference is pretty small. I could write
print "print"
at the beginning of the python answer and copy the rest. Although FWIW, it'll take 3 other users to agree with me, so the question might stay open anyway. – James – 2016-07-01T01:00:16.877IT is fairly similar of a challenge I guess, but I would say that it does open itself to some interesting variations, and it does actually fit HQ9+'s spec of ingnore extraneous characters. – Rohan Jhunjhunwala – 2016-07-01T01:03:33.493
4Should
Q
output the source of the input program, or the compiled program? – Conor O'Brien – 2016-07-01T01:05:54.240@CᴏɴᴏʀO'Bʀɪᴇɴ I would think the compiled program - otherwise it wouldn't really be a quine. – Mego – 2016-07-01T02:58:30.413
@Mego I don't know... a C quine doesn't output its compiled binary either. – Martin Ender – 2016-07-01T05:51:05.770
6The post would benefit from the inclusion of HQ9+ specs. – Fatalize – 2016-07-01T06:16:43.880
@MartinEnder A C Quine outputs its own source code. C doesn't have to be compiled (though the interpreters admittedly don't work well). – Mego – 2016-07-01T06:33:04.510
@Mego But a C quine still outputs its C source code even if it is compiled. HQ9+ doesn't need to be compiled either. I really don't see why you want to treat one differently from the other. – Martin Ender – 2016-07-01T06:58:50.037
@MartinEnder Fair enough. I guess clarification from the OP would be helpful. I interpreted it as "write a program that outputs an equivalent program to the HQ9+ input program in your language", meaning a quine should output the compiled program and not the input program. – Mego – 2016-07-01T07:14:49.743
My reference implementation has q print out the hq9+ source as opposed to the compiled source, but it would be interesting to make it be the compiled source – Rohan Jhunjhunwala – 2016-07-01T13:16:52.083
The accepted answer is the one that wins the challenge. Though you are not obligated to accept an answer, if you do, the consensus on meta is that you should accept the answer with the best score - for code golf, that's the shortest answer in bytes. – Mego – 2016-07-01T21:14:54.583
@Mego ok I guess I can accept the smallest program. – Rohan Jhunjhunwala – 2016-07-01T21:23:20.577
2This should stay closed. If you can interpret HQ9, then all you have to do is stringify the commands used in your code and output them at the correct moments. – Rɪᴋᴇʀ – 2017-04-11T03:27:12.987