Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

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.

share|improve this question
5  
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? –  Peter Taylor Aug 16 at 9:24

30 Answers 30

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.

share|improve this answer
8  
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. :/ –  Ingo Bürk Aug 16 at 16:24
10  
@IngoBürk Fortunately this is a popularity contest, not a golf. –  fluffy Aug 16 at 20:11
    
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). –  impinball Aug 17 at 8:28
3  
@IngoBürk Many real-life problems are about cleverly choosing the language, too. :P –  Sarge Borsch Aug 18 at 14:32
    
@fluffy Wow, I completely missed that. :) I take back everything I said. –  Ingo Bürk Aug 18 at 14:55

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
});
share|improve this answer

Windows Command Prompt

& was unexpected at this time.

enter image description here

share|improve this answer

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!

share|improve this answer
2  
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. :-) –  rink.attendant.6 Aug 16 at 9:30
7  
@rink.attendant.6: That's when our much-valued expert knowledge about software engineering is required. ;) –  Falko Aug 16 at 9:33
    
@rink.attendant.6 Or when you are sent off running in circles. Try it in the Excel-VBA immediate window. –  Dennis Jaheruddin Aug 18 at 13:14

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

share|improve this answer

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.

share|improve this answer
3  
If the parser gets confused and throws a syntax error, doesn't that make it not syntactically valid? –  Martin Büttner Aug 16 at 10:16
2  
@MartinBüttner, that really depends on which you consider the authority for "valid syntax": the language description, or the language implementation. –  Mark Aug 16 at 10:18
9  
I see, so technically is syntactically valid but it's tripping up the parser due to a bug of a particular implementation? –  Martin Büttner Aug 16 at 10:22
2  
More or less, confounded by the fact that there is only one implementation. –  Mark Aug 18 at 19:16

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! ;)

share|improve this answer

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
share|improve this answer

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!

share|improve this answer
1  
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 :-) –  rink.attendant.6 Aug 17 at 7:00
    
Who sad that the program source has to be valid? –  NightElfik Aug 18 at 18:54
2  
No one, however, invalid syntax errors have been thoroughly explored in this thread, so I wanted to try something different. –  xleviator Aug 18 at 19:22

Julia 0.2.0

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

ERROR: syntax: extra token "token" after end of expression
share|improve this answer

Fish - 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.

share|improve this answer

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:\>
share|improve this answer

C

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.

share|improve this answer

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
share|improve this answer

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.

share|improve this answer

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...
          ^
share|improve this answer

Lua

Code:

lua: ERROR.lua:1: function arguments expected near '.'

It seems fairly easy to do with lua. I also modified it to work on ideone.com as:

luac: prog.lua:1: function arguments expected near '.'

Try it.

share|improve this answer

Go

Another fairly easy one using the "general approach" provided in the other answer. I still like my JavaScript ones better.

can't load package: package : 
prog.go:1:1: expected 'package', found 'IDENT' can
prog.go:2:2: invalid package name _

Try it.

share|improve this answer

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.

share|improve this answer

C

I applied the method to repeatedly copy 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.
share|improve this answer

Lua (console), 35 bytes

This is what you get in the Lua console with the usual iterative approach:

stdin:1: '<name>' expected near '1'

which is a bit shorter than the one obtained for putting the code in a file.

share|improve this answer

ksh

$ ksh: ksh::  not found.
ksh: ksh::  not found.
share|improve this answer
    
Also works with bash: bash: bash:: comand not found –  shelvacu Aug 20 at 0:54

Rebol

Interestingly, the error message here parses as symbols/tokens:

x
** Script error: x has no value
** Where: do either either either -apply-
** Near: do intern code

So despite looking error-like, it could be made a valid Rebol program if you gave all the words meanings.

However if you wanted an error at the parse phase vs. a runtime error in the code, the program/error could be:

1A
** Syntax error: invalid "integer" -- "1A"
** Where: to case load either either -apply-
** Near: (line 1) 1A

So given that distinction is possible, you can do fun things if you redefine ** from exponentiation into something else (which I can't think of how to make useful for this particular challenge, given it's a quine.)

(Note: Trying to abuse it for a trick uncovered a peculiarity of what happens when ** (an infix operator) is redefined and then used immediately after. I tried:

**: function [:a :b :c :d :e :f] []
** Syntax error: invalid "integer" -- "1A"
** Where: to case load either either -apply-
** Near: (line 1) 1A

My goal was to override the ** so that it would accept its arguments unevaluated. That way ** Syntax error: invalid "integer" -- "1A" (or whatever) would not attempt to assign invalid to error, but pass the symbols to **. But because ** is infix it attempted to raise the function body to the power of Syntax prior to the completion of the assignment of **:.

It can be remedied by putting any token between the [] and the **. But it helps to remember how your language evaluator works. :-P)

share|improve this answer

R (GUI)

Error: unexpected symbol in "Error: unexpected symbol"

The issue here is replicating the ", which causes the error message to change from unexpected symbol to unexpected string constant. Pretty much any error R throws will have the form Error: <something> in "<bad code>", so you will pretty much always have to contend with the quoting. I tried this several other ways and always ended up falling back here.

share|improve this answer
1  
Error: unexpected string constant in "Error: unexpected string" gives the output Error: unexpected symbol in "Error: unexpected symbol" so it isn't quite right. –  Richie Cotton Aug 19 at 20:05

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 both : and . are built in operators of Haskell, and that whitespace is used to denote function application.

share|improve this answer

Befunge on Wasabi v1.4

There is an interpreter for Befunge called Wasabi, and when an error appears the error message is in the format of a dialog box. This is the program:

Unsupported Command : 'U' at (1, 0). Ignore next syntax error(s)?

To test, download Wasabi v1.4 and insert the above program.

share|improve this answer

Cobra

test.cobra(1): error: Expecting use, assembly, namespace, class, interface or enum, but got "test".
Compilation failed - 1 error, 0 warnings
Not running due to errors above.
share|improve this answer

CJam 0.6.2

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

Try it online.

share|improve this answer

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.

share|improve this answer

g++

The file must be saved as 1.pas.

g++: error: 1.pas: Pascal compiler not installed on this system
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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