# Interpreted Interpreter [duplicate]

Duplicate? I knew somebody must've done this before.

Programming a programming language in itself is something that has interested me since I knew what a programming language was. So I thought I'd create a Code Golf challenge for you.

## Challenge

Create an interpreter for a given programming language, programmed entirely in itself. The interpreter should be able to run any valid program in that language, including itself.

### Inputs:

The program can take it's input as a file passed as a parameter (e.g. python myfile.py) or as lines from stdin (cat myfile.py | python).

### Outputs:

Whatever an interpreter would normally output, on the correct streams (stdout, stderr etc.)

## Specifications

• The code needs to be written in an interpretable language, and serve as an interpreter for its own language.
• It can't use an eval() function to interpret code.
• It must run any valid program in that language. If the language allows external modules (or includes), it must be able to read those modules.
• This task is code golf. The submission with the least characters that is correct wins. In case of a tie, the solution that was submitted first wins.

### Loophole remover:

• Yes, if you can interpret Java, Bytecode or HQ9++ in themselves, go ahead!
• In JavaScript / ES, using HTML tags such as <script> is not allowed.
• Our default scoring method is bytes, not characters, because scoring in character will likely get you answers like this. You are free to choose characters over bytes if you really want to, but I thought I'd let you know about the consequences. ;) – Martin Ender Aug 29 '15 at 14:19
• Seems like this might be a better popularity contest than code golf- there are many extremely degenerate non-general esolangs which have simple solutions to this problem and more interesting languages have no chance of competing. – JohnE Aug 29 '15 at 14:34
• Oh well, this contest is over. Loopholes should be closed not opened. – Dennis Aug 29 '15 at 14:40
• @MartinBüttner I meant bytes! But there's no point editing now, even though the duplicate refers to an old and inactive challenge. – wizzwizz4 Aug 30 '15 at 7:30
• is tcl interp create valid? – sergiol Jul 6 '17 at 20:46

# Nothing, 0 chars

The source code is an empty file. It does nothing, like any Nothing program, therefore it is the correct execution of every such program.

• Nothing doesn't satisfy our definition of programming language. – Dennis Aug 29 '15 at 14:36
• @Dennis the OP seems to explicitly accept such languages (e.g. HQ9++) – aditsu Aug 29 '15 at 14:37
• In that case, nothing beats Nothing. – Dennis Aug 29 '15 at 14:38
• @aditsu That was a joke, as there is no way to create an interpreter of HQ9++ in itself. But this is accepted. – wizzwizz4 Aug 29 '15 at 16:32

# JavaScript ES6, 44 bytes/chars

s=>document.write(<${t='script>'}${s}</+t)


Defines a function, taking the code string as a parameter.

How it works:

This function simply takes the code, wraps it in <script> tags, and writes it into the page. It doesn't use the eval function at all - the browser simply runs the code when the new <script> element is inserted into the page.

Tested in the FireFox console on the about:blank page as follows:

(s=>document.write(<${t='script>'}${s}</+t))("alert('hi')")


Yes, this is probably a loophole and as such I don't really expect to win. (It's impossible to beat the Nothing answer, anyway...)

If anything, hopefully it shows how it is possible to evaluate code in javascript without the use of the eval function.

• This is a loophole. I'll add it to the Loophole remover. – wizzwizz4 Aug 29 '15 at 16:33