100
\$\begingroup\$

Your challenge: write a "program", for a language of your choice, that causes the compiler/interpreter/runtime to produce error output when compiling/running your program which is identical to your program's source code.

Rules:

  • Your program may be specific to a particular version or implementation of your language's compiler/interpreter/runtime environment. If so, please specify the particulars.
  • Only standard compiler/interpreter/runtime options are permitted. You cannot pass some weird flag to your compiler to get a specific result.
  • The program does not need to be syntactically or semantically valid, but I may give a bounty to the best syntactically valid submission.
  • The program must not produce any output of its own (e.g. by calling a print or output function). All output generated upon attempting to compile/run the program must originate from the compiler/interpreter/runtime.
  • The complete output of the compiler/interpreter/runtime must be exactly identical to your program source code.
  • The compiler/interpreter/runtime must generate at least one error message when invoked with your program.

This is a popularity contest. Most creative answer, as determined by upvotes, wins. If you can give a good case for using a standard loophole, you may do so.

\$\endgroup\$
  • 7
    \$\begingroup\$ What is "error output"? And what does it mean to "generate an error message"? More specifically: 1) Does the output have to be to stderr? 2) If the runtime logs an error to syslog and doesn't write anything to stderr, what should be compared to the source of the program? 3) If the runtime throws an exception internally when given an empty program, but requires a flag to actually print the exception and so ends up exiting with a non-zero exit code but no output, has an error message been generated? \$\endgroup\$ – Peter Taylor Aug 16 '14 at 9:24
  • 1
    \$\begingroup\$ I tried doing this in java and got a p3 oscilator. This was the shortest phase: (Compile from q.java): Error: Could not find or load main class Q \$\endgroup\$ – SuperJedi224 Jun 1 '15 at 12:57
  • 2
    \$\begingroup\$ Ha, because of a syntactic ambiguity in the first sentence, I thought the challenge here was to produce a program which normally produces no output, but if you pass its own code to it as input, it produces an error. \$\endgroup\$ – Steve Bennett Apr 10 '17 at 6:32
  • 2
    \$\begingroup\$ When reporting an error, APL always prints a customizable error name, optionally an error message, the name of the program that caused the error, the (bracketed) line number where the error occurred, the line of code that caused the error, and a line with a caret indicating where parsing stopped. Any hope for participation here? \$\endgroup\$ – Adám May 7 '17 at 21:50
  • 1
    \$\begingroup\$ @SteveBennett Why haven't you made that challenge yet? \$\endgroup\$ – CalculatorFeline May 28 '17 at 1:53

95 Answers 95

107
\$\begingroup\$

Ed (1 byte)

All the other solutions thus far are long and ugly. I suppose that is because of the nature of most error messages. But a good error message is elegant in its simplicity. For that, look no further than ed.

?

Save this to a file called edscript and run with ed < edscript, or run ed<<<?. The result:

?

The question mark is written to stderr and ed returns 1, so this actually is an error message. I wonder why ed isn't very popular?

False (0 bytes)

Run with false filename. It writes the program's source code (i.e. nothing) to stderr and returns 1. Of course, calling false a programming language is questionable, and the zero byte quine is unoriginal, but I thought I might as well add it. There is probably some interpreter for a language that prints no error messages, and could replace false.

Now I wish this was code golf.

\$\endgroup\$
  • 12
    \$\begingroup\$ I was looking through the (long) list of esolangs to find a language like this. This is the weakness of this challenge. It's not about writing a clever program, it's about cleverly choosing the language. :/ \$\endgroup\$ – Ingo Bürk Aug 16 '14 at 16:24
  • 22
    \$\begingroup\$ @IngoBürk Fortunately this is a popularity contest, not a golf. \$\endgroup\$ – fluffy Aug 16 '14 at 20:11
  • \$\begingroup\$ The 0-byte False is also the same code that at one time won the "Worst Abuse of the Rules" award by the IOCCC for making the theoretically shortest quinine. It had plenty of compiler errors, though, and it was written in K&R C, not ISO C (which is stricter). \$\endgroup\$ – Isiah Meadows Aug 17 '14 at 8:28
  • 6
    \$\begingroup\$ @IngoBürk Many real-life problems are about cleverly choosing the language, too. :P \$\endgroup\$ – Sarge Borsch Aug 18 '14 at 14:32
  • 2
    \$\begingroup\$ @Mendeleev *Quine (Until somewhat recently, I've constantly misread "quine" as "quinine" for some reason...) \$\endgroup\$ – Isiah Meadows Jun 20 '17 at 12:47
111
\$\begingroup\$

Windows Command Prompt

& was unexpected at this time.

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Note that this works with | also. \$\endgroup\$ – MD XF May 7 '17 at 21:01
  • 2
    \$\begingroup\$ & was unexpected at this time. +1 \$\endgroup\$ – workoverflow Dec 11 '17 at 10:44
77
+100
\$\begingroup\$

CoffeeScript, syntactically valid

As tested on their website using Chrome or Firefox.

ReferenceError: defined is not defined

You can replace defined with anything that's not a built-in variable, but I thought this version was fun. Unfortunately, undefined is not defined in particular doesn't work as a quine.

In CoffeeScript this isn't even a syntax error, because it compiles. This is technically a runtime error in JavaScript, albeit a boring one. CoffeeScript is a likely candidate to produce some more interesting runtime error quines because a lot of funny sentences are valid code. E.g. the above example compiles to

({
  ReferenceError: defined === !defined
});
\$\endgroup\$
  • 1
    \$\begingroup\$ defined is by definedition defined. Wha...how...? \$\endgroup\$ – CalculatorFeline Feb 24 '17 at 3:18
  • 2
    \$\begingroup\$ Undefined is not defined (with a capital U) seems to work lol \$\endgroup\$ – Shieru Asakoto Oct 11 '18 at 1:49
46
\$\begingroup\$

Python

Spyder

Well, a rather trivial solution for the Spyder IDE is to raise a SyntaxError.

Code and identical output:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
    execfile(filename, namespace)
  File "/Users/falko/golf.py", line 1
    Traceback (most recent call last):
                         ^
SyntaxError: invalid syntax

(Python 2.7.8 with Spyder 2.2.5)


Terminal

An alternative solution for Python started from command line struggles with an unexpected indent.

Command:

python golf.py

Code and identical output:

  File "golf.py", line 1
    File "golf.py", line 1
    ^
IndentationError: unexpected indent

ideone.com

On ideone.com a solution might be as follows. (Try it!)

Code and identical output:

Traceback (most recent call last):

  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/py_compile.py", line 117, in compile
    raise py_exc
py_compile.PyCompileError: SyntaxError: ('invalid syntax', ('prog.py', 1, 22, 'Traceback (most recent call last):\n'))

(This is for Python 2. An example for Python 3 is trivial but with 15 lines of "code" rather lengthy.)


General approach:

How to create your own solution in 2 minutes?

  1. Open a new file in an IDE of your choice.
  2. Bang your head onto the keyboard in front of you.
  3. Compile.
  4. Replace the code with the compiler error message.
  5. Repeat steps 3 and 4 until the code converges.

I bet such a procedure terminates pretty quickly in most cases!

\$\endgroup\$
  • 6
    \$\begingroup\$ As you can probably tell, I'm using that general approach. It doesn't work when the copied code progressively increases the amount of compiler errors. :-) \$\endgroup\$ – rink.attendant.6 Aug 16 '14 at 9:30
  • 9
    \$\begingroup\$ @rink.attendant.6: That's when our much-valued expert knowledge about software engineering is required. ;) \$\endgroup\$ – Falko Aug 16 '14 at 9:33
  • \$\begingroup\$ @rink.attendant.6 Or when you are sent off running in circles. Try it in the Excel-VBA immediate window. \$\endgroup\$ – Dennis Jaheruddin Aug 18 '14 at 13:14
  • 42
    \$\begingroup\$ I did step 1, 2, and 3, but I couldn't do step 4, the perl code was perfectly valid! \$\endgroup\$ – rodolphito Nov 20 '14 at 4:48
  • \$\begingroup\$ Hey how about this in the python stock IDE, SyntaxError: invalid syntax produces the same thing too :) \$\endgroup\$ – Gurupad Mamadapur Oct 11 '16 at 7:37
38
\$\begingroup\$

><> - 25 Bytes

something smells fishy...

In Fish, any bad instruction outputs the error: "something smells fishy...". Since s is not a valid command, it errors immediately.

\$\endgroup\$
  • 10
    \$\begingroup\$ Please note that the language name is ><>, which is usually pronounced "fish". \$\endgroup\$ – Aaron Aug 31 '15 at 12:54
  • 1
    \$\begingroup\$ And it's really "Something smells fishy..." \$\endgroup\$ – Conor O'Brien Oct 15 '15 at 2:31
  • 3
    \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ On the python interpreter, it is indeed something smells fishy..., but it is Something smells fishy... on the online interpreter. It's dependent on the interpreter. \$\endgroup\$ – Addison Crump Oct 17 '15 at 21:47
  • 1
    \$\begingroup\$ @VTCAKAVSMoACE Ah, thanks. \$\endgroup\$ – Conor O'Brien Oct 18 '15 at 1:31
  • \$\begingroup\$ Cuz 'fish' is the name of the shell program/language for the 90s! \$\endgroup\$ – Nick T Oct 11 '16 at 19:01
36
\$\begingroup\$

Whitespace

First I thought this is clearly impossible. But actually it is trivial as well. -.-

Fail: Input.hs:108: Non-exhaustive patterns in function parseNum'

Try it.

Yeah, my first whitespace program! ;)

\$\endgroup\$
  • 1
    \$\begingroup\$ Can we even call this a whitespace program? \$\endgroup\$ – V. Courtois Jul 26 '18 at 6:42
36
\$\begingroup\$

Windows .EXE, 248 bytes

The version of this file is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need an x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.

No, really. Save as quine.txt, then rename to quine.exe (or download it here):

\$\endgroup\$
32
\$\begingroup\$

Chicken

Error on line 1: expected 'chicken'
\$\endgroup\$
  • 7
    \$\begingroup\$ What a peculiar language \$\endgroup\$ – Albert Renshaw Apr 13 '17 at 8:36
27
\$\begingroup\$

Commodore 64 Basic

?SYNTAX  ERROR

When run on the emulator of your choice (or an actual Commodore 64), produces

?SYNTAX  ERROR

This is, in fact, a syntactically-valid one-line program. The question mark is a shortcut for PRINT, and SYNTAX and ERROR are valid variable names. The error occurs because the parser gets confused by the substring OR in ERROR.

\$\endgroup\$
  • 4
    \$\begingroup\$ If the parser gets confused and throws a syntax error, doesn't that make it not syntactically valid? \$\endgroup\$ – Martin Ender Aug 16 '14 at 10:16
  • 3
    \$\begingroup\$ @MartinBüttner, that really depends on which you consider the authority for "valid syntax": the language description, or the language implementation. \$\endgroup\$ – Mark Aug 16 '14 at 10:18
  • 14
    \$\begingroup\$ I see, so technically is syntactically valid but it's tripping up the parser due to a bug of a particular implementation? \$\endgroup\$ – Martin Ender Aug 16 '14 at 10:22
  • 6
    \$\begingroup\$ More or less, confounded by the fact that there is only one implementation. \$\endgroup\$ – Mark Aug 18 '14 at 19:16
  • \$\begingroup\$ Nitpick: CBM BASIC actually prints two spaces, not one, between "SYNTAX" and "ERROR". Unfortunately I can't edit this answer to correct it, as Stack Exchange imposes a silly 6-character minimum for edits. \$\endgroup\$ – Psychonaut Oct 16 '15 at 14:53
27
\$\begingroup\$

Microsoft Excel

Formula: #DIV/0!

Error Message: #DIV/0!

In order to enter a formula without using an equals sign, go into Excel Options/Advanced/Lotus Compatibility Settings and enable Transition Formula Entry.

\$\endgroup\$
25
\$\begingroup\$

JavaScript

Since different browsers use different JavaScript compilers, they produce different messages. These are, however, rather trivial solutions.

V8 (Chrome 36 / Node.js)

SyntaxError: Unexpected identifier

enter image description here

SpiderMonkey (Firefox 31)

SyntaxError: missing ; before statement

enter image description here

Chakra (Internet Explorer 11)

Expected ';'

enter image description here

\$\endgroup\$
  • \$\begingroup\$ In jsc: Exception: SyntaxError: Unexpected identifier 'identifier' :D \$\endgroup\$ – clap Nov 2 '15 at 6:59
  • 2
    \$\begingroup\$ @ConfusedMr_C That's a wierd token to choke on. \$\endgroup\$ – SuperJedi224 Nov 2 '15 at 13:59
  • \$\begingroup\$ @SuperJedi224 Yes. At least it works :P \$\endgroup\$ – clap Nov 2 '15 at 15:24
21
\$\begingroup\$

Java

Why I have to break a rule

Because of the way java exceptions are generated and printed, this rule has to be broken in order to create an exception quine that will actually compile:

The program must not produce any output of its own (e.g. by calling a print or output function). All output generated upon attempting to compile/run the program must originate from the compiler/interpreter/runtime.

This is because the default uncaught exception handling behavior in java prints out stuff that is not valid java source code. Here is what happens when an uncaught exception occurs in java (from the class ThreadGroup):

public void uncaughtException(Thread t, Throwable e) {
    if (parent != null) {
        parent.uncaughtException(t, e);
    } else {
        Thread.UncaughtExceptionHandler ueh = Thread.getDefaultUncaughtExceptionHandler();
        if (ueh != null) {
            ueh.uncaughtException(t, e);
        } else if (!(e instanceof ThreadDeath)) {
            System.err.print("Exception in thread \"" + t.getName() + "\" ");
            e.printStackTrace(System.err);
        }
    }
}

Notice that the words "Exception in thread..." will always be printed at the beginning of the exception output. Because no valid java program exists starting with this phrase, there is no way in java to create a syntactically valid quine which generates an error, and follows all the rules. Thus, I have come up with two ways which allow a syntactically valid program to solve this problem.

1. Use print statements to encapsulate extraneous java exception output with comments

I apologize in advance for the lengthy, cryptic, and super escaped string literals. This is the first quine I've ever attempted, and as such, I didn't read any theory or look at any other quines (except for the ones in this thread). I merely tried to come up with one. It's been a multi-hour journey. I also made no attempt to code golf this. However, it is sufficiently short to be understood.

// Exception in thread "main" 
public class Main {
    public static void main(String[] args) {
        System.err.print("// ");

        new Thread() {
            public void run() {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {}
                System.err.print("*/");
            }
        }.start();

        throw new RuntimeException() {
            public String toString() {
                String open = "\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tSystem.err.print(\"// \");\n\t\t\n\t\tnew Thread() {\n\t\t\tpublic void run() {\n\t\t\t\ttry {\n\t\t\t\t\tThread.sleep(10);\n\t\t\t\t} catch (InterruptedException e) {}\n\t\t\t\tSystem.err.print(\"*/\");\n\t\t\t}\n\t\t}.start();\n\t\t\n\t\tthrow new RuntimeException() {\n\t\t\tpublic String toString() {\n";
                String close = "return open + \"\\t\\t\\t\\tString open = \\\"\" + open.replace(\"\\t\", \"\\\\t\").replace(\"\\n\", \"\\\\n\").replace(\"\\\"\", \"\\\\\\\"\") + \"\\\";\\n\\t\\t\\t\\tString close = \\\"\" + close.replace(\"\\\\\",\"\\\\\\\\\").replace(\"\\t\", \"\\\\t\").replace(\"\\n\", \"\\\\n\").replace(\"\\\"\", \"\\\\\\\"\") + \"\\\";\\n\\n\\t\\t\\t\\t\" + close;\n\t\t\t}\n\t\t};\n\t}\n};\n/*";

                return open + "\t\t\t\tString open = \"" + open.replace("\t", "\\t").replace("\n", "\\n").replace("\"", "\\\"") + "\";\n\t\t\t\tString close = \"" + close.replace("\\","\\\\").replace("\t", "\\t").replace("\n", "\\n").replace("\"", "\\\"") + "\";\n\n\t\t\t\t" + close;
            }
        };
    }
};
/*
    at Main.main(Main.java:15)
*/

You can see how a comment is inserted at the beginning of the output in order to remove the "Exception in thread..." phrase. Furthermore, a time-delayed thread is used in order to close off a block comment containing the (one line) stack trace.

2. Take advantage of the UncaughtLocalExceptionListener

Method 1 is a blatant violation of the rules. So, I have come up with an arguably less (or more) violating version that works by removing the "Exception in thread..." phrase and the stack trace altogether.

import java.lang.Thread.UncaughtExceptionHandler;
public class Main2 {
    public static void main(String[] args) {
        Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread t, Throwable e) {
                System.err.print(e);
            }
        });
        throw new RuntimeException() {
            public String toString() {
                String open = "import java.lang.Thread.UncaughtExceptionHandler;\npublic class Main2 {\n\tpublic static void main(String[] args) {\n\t\tThread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {\n\t\t\t@Override\n\t\t\tpublic void uncaughtException(Thread t, Throwable e) {\n\t\t\t\tSystem.err.print(e);\n\t\t\t}\n\t\t});\n\t\tthrow new RuntimeException() {\n\t\t\tpublic String toString() {\n";
                String close = "return open + \"\\t\\t\\t\\tString open = \\\"\" + open.replace(\"\\t\", \"\\\\t\").replace(\"\\n\", \"\\\\n\") + \"\\\";\\n\\t\\t\\t\\tString close = \\\"\" + close.replace(\"\\\\\",\"\\\\\\\\\").replace(\"\\t\", \"\\\\t\").replace(\"\\n\", \"\\\\n\").replace(\"\\\"\", \"\\\\\\\"\") + \"\\\";\\n\\n\\t\\t\\t\\t\" + close;\n\t\t\t}\n\t\t};\n\t}\n};";

                return open + "\t\t\t\tString open = \"" + open.replace("\t", "\\t").replace("\n", "\\n") + "\";\n\t\t\t\tString close = \"" + close.replace("\\","\\\\").replace("\t", "\\t").replace("\n", "\\n").replace("\"", "\\\"") + "\";\n\n\t\t\t\t" + close;
            }
        };
    }
};

Here you can see the custom UncaughtExceptionHandler is really just a stripped down version of the uncaughtException method above. So, while it still breaks the rules, it's as close as you can get.

I would love to see if anyone could find a way to break the rules even less in Java and also to see more exception-quines which are syntactically valid programs!

\$\endgroup\$
  • 1
    \$\begingroup\$ You could have also broken the no weird flags rule and used the -Xmaxerrs flag with the "general approach", but your answer was interesting nonetheless :-) \$\endgroup\$ – rink.attendant.6 Aug 17 '14 at 7:00
  • \$\begingroup\$ Who sad that the program source has to be valid? \$\endgroup\$ – NightElfik Aug 18 '14 at 18:54
  • 9
    \$\begingroup\$ No one, however, invalid syntax errors have been thoroughly explored in this thread, so I wanted to try something different. \$\endgroup\$ – xleviator Aug 18 '14 at 19:22
19
\$\begingroup\$

Bash (32)

Save as file named x:

x: line 1: x:: command not found

When run:

>> bash x
x: line 1: x:: command not found
\$\endgroup\$
16
\$\begingroup\$

Java 8 compilation error quine (12203 bytes)

Generated on windows + mingw with java 1.8.0_11 jdk, using this command:

echo a > Q.java; while true; do javac Q.java 2> Q.err; if [ $(diff Q.err Q.java | wc -c) -eq 0 ]; then break; fi; cat Q.err > Q.java; done

May not be the shortest one, may not be the longest one either, more a proof of concept. Works because error output shows at most 100 errors.

Q.java:1: error: class, interface, or enum expected
Q.java:1: error: class, interface, or enum expected
^
Q.java:1: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
                      ^
Q.java:1: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
                                 ^
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
Q.java:1: error: class, interface, or enum expected
                                      ^
  (use -source 1.4 or lower to use 'enum' as an identifier)
Q.java:1: error: = expected
Q.java:1: error: class, interface, or enum expected
                                           ^
Q.java:2: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
      ^
Q.java:2: error: ';' expected
Q.java:1: error: class, interface, or enum expected
       ^
Q.java:2: error: illegal start of type
Q.java:1: error: class, interface, or enum expected
        ^
Q.java:2: error: = expected
Q.java:1: error: class, interface, or enum expected
               ^
Q.java:2: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
                      ^
Q.java:2: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
                                 ^
Q.java:2: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
Q.java:1: error: class, interface, or enum expected
                                      ^
  (use -source 1.4 or lower to use 'enum' as an identifier)
Q.java:2: error: = expected
Q.java:1: error: class, interface, or enum expected
                                           ^
Q.java:3: error: illegal start of type
^
^
Q.java:4: error: = expected
Q.java:1: error: <identifier> expected
 ^
Q.java:4: error: <identifier> expected
Q.java:1: error: <identifier> expected
      ^
Q.java:4: error: ';' expected
Q.java:1: error: <identifier> expected
       ^
Q.java:4: error: illegal start of type
Q.java:1: error: <identifier> expected
        ^
Q.java:4: error: = expected
Q.java:1: error: <identifier> expected
               ^
Q.java:5: error: '(' expected
Q.java:1: error: class, interface, or enum expected
 ^
Q.java:5: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
      ^
Q.java:5: error: ';' expected
Q.java:1: error: class, interface, or enum expected
       ^
Q.java:5: error: illegal start of type
Q.java:1: error: class, interface, or enum expected
        ^
Q.java:5: error: = expected
Q.java:1: error: class, interface, or enum expected
               ^
Q.java:5: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
                      ^
Q.java:5: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
                                 ^
Q.java:5: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
Q.java:1: error: class, interface, or enum expected
                                      ^
  (use -source 1.4 or lower to use 'enum' as an identifier)
Q.java:5: error: = expected
Q.java:1: error: class, interface, or enum expected
                                           ^
Q.java:6: error: illegal start of type
                      ^
                      ^
Q.java:7: error: = expected
Q.java:1: error: <identifier> expected
 ^
Q.java:7: error: <identifier> expected
Q.java:1: error: <identifier> expected
      ^
Q.java:7: error: ';' expected
Q.java:1: error: <identifier> expected
       ^
Q.java:7: error: illegal start of type
Q.java:1: error: <identifier> expected
        ^
Q.java:7: error: = expected
Q.java:1: error: <identifier> expected
               ^
Q.java:8: error: '(' expected
Q.java:1: error: class, interface, or enum expected
 ^
Q.java:8: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
      ^
Q.java:8: error: ';' expected
Q.java:1: error: class, interface, or enum expected
       ^
Q.java:8: error: illegal start of type
Q.java:1: error: class, interface, or enum expected
        ^
Q.java:8: error: = expected
Q.java:1: error: class, interface, or enum expected
               ^
Q.java:8: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
                      ^
Q.java:8: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
                                 ^
Q.java:8: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
Q.java:1: error: class, interface, or enum expected
                                      ^
  (use -source 1.4 or lower to use 'enum' as an identifier)
Q.java:8: error: = expected
Q.java:1: error: class, interface, or enum expected
                                           ^
Q.java:9: error: illegal start of type
                                 ^
                                 ^
Q.java:10: error: = expected
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
 ^
Q.java:10: error: <identifier> expected
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
      ^
Q.java:10: error: ';' expected
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
       ^
Q.java:10: error: illegal start of type
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
        ^
Q.java:10: error: = expected
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
               ^
Q.java:10: error: = expected
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
                       ^
Q.java:10: error: illegal start of type
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
                               ^
Q.java:10: error: <identifier> expected
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
                                ^
Q.java:10: error: unclosed character literal
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
                                  ^
Q.java:10: error: ';' expected
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
                                    ^
Q.java:10: error: unclosed character literal
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
                                       ^
Q.java:10: error: = expected
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
                                                     ^
Q.java:10: error: = expected
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
                                                           ^
Q.java:10: error: = expected
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
                                                                      ^
Q.java:10: error: = expected
Q.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
                                                                                 ^
Q.java:11: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
      ^
Q.java:11: error: ';' expected
Q.java:1: error: class, interface, or enum expected
       ^
Q.java:11: error: illegal start of type
Q.java:1: error: class, interface, or enum expected
        ^
Q.java:11: error: = expected
Q.java:1: error: class, interface, or enum expected
               ^
Q.java:11: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
                      ^
Q.java:11: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
                                 ^
Q.java:11: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
Q.java:1: error: class, interface, or enum expected
                                      ^
  (use -source 1.4 or lower to use 'enum' as an identifier)
Q.java:11: error: = expected
Q.java:1: error: class, interface, or enum expected
                                           ^
Q.java:12: error: illegal start of type
                                      ^
                                      ^
Q.java:12: error: <identifier> expected
                                      ^
                                       ^
Q.java:13: error: = expected
  (use -source 1.4 or lower to use 'enum' as an identifier)
   ^
Q.java:13: error: ';' expected
  (use -source 1.4 or lower to use 'enum' as an identifier)
      ^
Q.java:13: error: <identifier> expected
  (use -source 1.4 or lower to use 'enum' as an identifier)
              ^
Q.java:13: error: = expected
  (use -source 1.4 or lower to use 'enum' as an identifier)
               ^
Q.java:13: error: ';' expected
  (use -source 1.4 or lower to use 'enum' as an identifier)
                  ^
Q.java:13: error: = expected
  (use -source 1.4 or lower to use 'enum' as an identifier)
                               ^
Q.java:13: error: unclosed character literal
  (use -source 1.4 or lower to use 'enum' as an identifier)
                                   ^
Q.java:13: error: unclosed character literal
  (use -source 1.4 or lower to use 'enum' as an identifier)
                                        ^
Q.java:13: error: = expected
  (use -source 1.4 or lower to use 'enum' as an identifier)
                                                          ^
Q.java:14: error: <identifier> expected
Q.java:1: error: = expected
      ^
Q.java:14: error: ';' expected
Q.java:1: error: = expected
       ^
Q.java:14: error: illegal start of type
Q.java:1: error: = expected
        ^
Q.java:14: error: = expected
Q.java:1: error: = expected
               ^
Q.java:14: error: illegal start of type
Q.java:1: error: = expected
                 ^
Q.java:15: error: = expected
Q.java:1: error: class, interface, or enum expected
^
Q.java:15: error: illegal start of type
Q.java:1: error: class, interface, or enum expected
 ^
Q.java:15: error: = expected
Q.java:1: error: class, interface, or enum expected
      ^
Q.java:15: error: illegal start of type
Q.java:1: error: class, interface, or enum expected
       ^
Q.java:15: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
        ^
Q.java:15: error: = expected
Q.java:1: error: class, interface, or enum expected
          ^
Q.java:15: error: ';' expected
Q.java:1: error: class, interface, or enum expected
               ^
Q.java:15: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
                      ^
Q.java:15: error: <identifier> expected
Q.java:1: error: class, interface, or enum expected
                                 ^
Q.java:15: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
Q.java:1: error: class, interface, or enum expected
                                      ^
  (use -source 1.4 or lower to use 'enum' as an identifier)
Q.java:15: error: = expected
Q.java:1: error: class, interface, or enum expected
                                           ^
Q.java:16: error: illegal start of type
                                           ^
                                           ^
Q.java:17: error: = expected
Q.java:2: error: <identifier> expected
 ^
Q.java:17: error: <identifier> expected
Q.java:2: error: <identifier> expected
      ^
Q.java:17: error: ';' expected
Q.java:2: error: <identifier> expected
       ^
Q.java:17: error: illegal start of type
Q.java:2: error: <identifier> expected
        ^
Q.java:17: error: = expected
Q.java:2: error: <identifier> expected
               ^
100 errors
\$\endgroup\$
16
\$\begingroup\$

TrumpScript - Making PPCG Great Again (TrumpScript)

When trying to run this language on a windows PC, the output is always:

Make sure the currently-running OS is not Windows, because we're not PC

So when running this program:

Make sure the currently-running OS is not Windows, because we're not PC

It won't even parse it because the OS check fails, and you get the error message. Examples can be given for Mac as well if anyone wants them haha. God I've wanted to use this in PPCG for awhile now, good that I finally get to.

Full list of errors that can be triggered using environmental specifics:
https://github.com/samshadwell/TrumpScript/blob/master/src/trumpscript/utils.py


Bonus Answer: ArnoldC (ArnoldC)

ArnoldC requires root declaration of IT'S SHOWTIME, meaning main(), so:

WHAT THE FUCK DID I DO WRONG

Results in the only error message in ArnoldC...

WHAT THE FUCK DID I DO WRONG

Which, is actually... hilarious. You have to run it non-verbose though w/o stack traces.

\$\endgroup\$
  • 8
    \$\begingroup\$ These should be two separate answers. \$\endgroup\$ – mbomb007 Dec 22 '16 at 14:49
15
\$\begingroup\$

ArnoldC

missing IT'S SHOWTIME on first line

Paste the code into this compiler.

\$\endgroup\$
  • 27
    \$\begingroup\$ What's funny is that IT'S SHOWTIME is in fact on the first line \$\endgroup\$ – Cyoce Sep 27 '16 at 22:36
  • 1
    \$\begingroup\$ Should make a PR to fix that :P \$\endgroup\$ – Nick T Oct 11 '16 at 19:11
13
\$\begingroup\$

Z-machine interpreter

I don't know the word "know".

Test against this popular interpreter. Also there's some sort of mostly harmless game hosted there.

\$\endgroup\$
12
\$\begingroup\$

Julia 0.2.0

Another syntax error found iteratively until a fixed point was reached:

ERROR: syntax: extra token "token" after end of expression
\$\endgroup\$
10
\$\begingroup\$

Mathematica

Syntax: "needed." is incomplete; more input is needed.

A . in Mathematica means either a decimal point or function Dot. In this case, the . appears at the end of an expression and cannot be interpreted.


enter image description here

\$\endgroup\$
  • \$\begingroup\$ I didn't think it was possible. \$\endgroup\$ – ngenisis Jan 6 '17 at 1:47
8
\$\begingroup\$

INTERCALL, 90 bytes

Fatal error: A INTERCALL program must start with the mandatory header to prevent golfing.\n

Includes a trailing newline at the end. Note that this isn't STDERR, but it was considered to be error output by many, so I posted it here.

This is the "mandatory header":

INTERCALL IS A ANTIGOLFING LANGUAGE
SO THIS HEADER IS HERE TO PREVENT GOLFING IN INTERCALL
THE PROGRAM STARTS HERE:
\$\endgroup\$
8
\$\begingroup\$

C

I applied the method of repeatedly copying the error messages to the source. It converged in 2 cycles. Compiled on OSX 10.9 with 'cc -c error.c'.

error.c:1:1: error: unknown type name 'error'
error.c:1:1: error: unknown type name 'error'
^
error.c:1:6: error: expected identifier or '('
error.c:1:1: error: unknown type name 'error'
     ^
2 errors generated.

Note: This is not so much an answer as it is a methodology to get one. The result might change depending on your OS or the version of cc you are using.

The exact method to get the result is to execute the instructions

$ cc -c error.c 2>out ; mv out error.c ; cat error.c

repeatedly until the output stops changing.

\$\endgroup\$
  • \$\begingroup\$ I retried. It didn't work at first. To make it work you have to execute cc -c error.c 2>out and then mv out error.c. And with the version of cc I have today it takes a few more iterations. \$\endgroup\$ – Florian F May 6 '17 at 23:53
  • \$\begingroup\$ You may want to note that in your answer, that it requires a specific version of OSX cc; otherwise it is invalid and must be deleted per community guidelines. \$\endgroup\$ – MD XF Dec 7 '17 at 4:11
8
\$\begingroup\$

GHCi (a Haskell interpreter/shell)

Code.hs:1:1: Parse error: naked expression at top level

Usage:

Write the code in a file named Code and load with GHCi.

A nice fact is that, if the words were actual identifiers, this would be a legal expression (as long as it would typecheck). This is basically due to the fact that : is a built in operator, . is used for module-qualified names, and whitespace is used to denote function application.

\$\endgroup\$
  • \$\begingroup\$ . isn't an operator here. It's part of a qualified name. What version of GHCi is this for? \$\endgroup\$ – dfeuer Mar 19 at 4:10
  • \$\begingroup\$ @dfeuer yeah, my bad. Feel free to fix it. The ghci version is probably around whatever was out at the time. \$\endgroup\$ – proud haskeller Mar 19 at 5:42
7
\$\begingroup\$

C++ (g++)

The file must be saved as 1.pas.

g++: error: 1.pas: Pascal compiler not installed on this system
\$\endgroup\$
  • 3
    \$\begingroup\$ Does it still work if the Pascal compiler is installed in the system? \$\endgroup\$ – SuperJedi224 Nov 2 '15 at 13:58
  • \$\begingroup\$ @SuperJedi224 At least installing FreePascal doesn't help. I suppose GNU Pascal might be the right Pascal compiler, but I didn't try. \$\endgroup\$ – jimmy23013 Nov 2 '15 at 14:16
7
\$\begingroup\$

C (gcc)

error.c:1:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
 error.c:1:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
      ^
compilation terminated due to -Wfatal-errors.

Compile with gcc -Wfatal-errors error.c.

\$\endgroup\$
6
\$\begingroup\$

Ruby 2 on Windows

Code:

error.rb:1: syntax error, unexpected tINTEGER, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
error.rb:1: syntax error, unexpected tI...
          ^

The code was found by testing and iterating the process over and over until a fix-point was reached. The code must be inside the file "error.rb".

Demo:

C:\>type error.rb
error.rb:1: syntax error, unexpected tINTEGER, expecting tSTRING_CONTENT or tSTR
ING_DBEG or tSTRING_DVAR or tSTRING_END
error.rb:1: syntax error, unexpected tI...
          ^

C:\>ruby.exe error.rb
error.rb:1: syntax error, unexpected tINTEGER, expecting tSTRING_CONTENT or tSTR
ING_DBEG or tSTRING_DVAR or tSTRING_END
error.rb:1: syntax error, unexpected tI...
          ^
\$\endgroup\$
6
\$\begingroup\$

CJam 0.6.2

Syntax error:
java.lang.RuntimeException: y not handled

Try it online.

\$\endgroup\$
6
\$\begingroup\$

Applescript (in Script Editor)

Syntax Error
A "error" can't go after this identifier.

enter image description here

\$\endgroup\$
  • 7
    \$\begingroup\$ it's an error? \$\endgroup\$ – cat May 18 '16 at 0:32
  • \$\begingroup\$ The article "A" appears before words which start with a consonant or a consonant sound. For words which begin with a vowel or a vowel sound, the correct article is "an". I'm just being nitpicky :) \$\endgroup\$ – cat May 18 '16 at 0:44
  • \$\begingroup\$ @cat I see. Yep, I never claimed grammatical correctness :) \$\endgroup\$ – Digital Trauma May 18 '16 at 1:01
6
\$\begingroup\$

AppleScript

A identifier can’t go after this identifier.

Both A and identifier can be identifiers, so AppleScript says no.

identifiers

\$\endgroup\$
  • 17
    \$\begingroup\$ it should be an identifier... come on.... \$\endgroup\$ – cat May 18 '16 at 0:28
6
\$\begingroup\$

BBC Basic, 7 bytes (or 0 Bytes)

This is a valid 7 byte entry:

Mistake

This is the error message produced by the interpreter when it is completely unable to make sense of the code.

On the other hand, this is not:

ERROR

This is a valid keyword in BBC Basic which is supposed to deliberately introduce an error of a specified code into the program, but the syntax is wrong (no code is given.) Therefore it returns Syntax error (which in turn returns Mistake when it is run.)

In general the procedure described by Falko in his answer leads to Mistake in BBC basic. There are a few exceptions. anything producing the errorsDATA not LOCAL or ON ERROR not LOCAL leads to the famous zero byte quine: an empty source code produces an empty file.

Given that most error messages in BBC basic are lowercase (and therefore not valid keywords) I am pretty sure that any invalid input will ultimately lead to one of these possibilities.

\$\endgroup\$
5
\$\begingroup\$

CoffeeScript

Fails on first error, so it's fairly easy to do:

E:\foo.coffee:1:3: error: unexpected \
E:\foo.coffee:1:3: error: unexpected \
  ^

Demo

E:\>coffee -c foo.coffee
E:\foo.coffee:1:3: error: unexpected \
E:\foo.coffee:1:3: error: unexpected \
  ^

E:\>
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.