10
\$\begingroup\$

It's simple, simply output text to STDERR containing the string EOF.

Input/Output

Your input will be none; however, you should output the message to STDERR.

Rules

  • Since this is , the shortest answer wins.
  • No standard loopholes please.
  • Any method approved by Standard I/O is allowed.
  • Your code may not contain the "EOF" that you will output as-is in your error.
  • Outputting "EOI" is technically allowed, because the input can also be considered as a separate file.
\$\endgroup\$
15
  • 2
    \$\begingroup\$ What are compiled languages supposed to do? Do we have to write a program that makes the compiler output "EOF" among other things? \$\endgroup\$ Oct 4, 2019 at 9:16
  • 7
    \$\begingroup\$ Is this valid? \$\endgroup\$
    – nimi
    Oct 4, 2019 at 9:35
  • 1
    \$\begingroup\$ @nimi Invalidated. \$\endgroup\$
    – user85052
    Oct 4, 2019 at 10:00
  • 3
    \$\begingroup\$ Seeing as several answers output end of input or end of file instead of EOF, you should clarify explicitly whether this is allowed. \$\endgroup\$
    – Grimmy
    Oct 4, 2019 at 11:14
  • 3
    \$\begingroup\$ voting to close as unclear. First sentence says to raise an EOF error. Next sentence says to output text to stderr containing EOF. I/O section says you should output a message to STDERR that proves that the program generates an EOFError. All three are asking different things. \$\endgroup\$
    – qwr
    Oct 6, 2019 at 3:02

19 Answers 19

23
\$\begingroup\$

APL (Dyalog Unicode) 17.0, 0 bytes

Dyalog 17.0 expects programs to terminate themselves cleanly and will throw an EOF INTERRUPT (and exit with a code 2) if they don't: Try it online!

In contrast, here is the minimal program which does terminate itself cleanly, causing no error (and code 0 upon exit): Try it online!

\$\endgroup\$
9
\$\begingroup\$

Python 3, 1 byte

(

Try it online!

A plain opening bracket is interpreted as the start of a tuple. Just having one bracket is enough to raise an EOF error. Also works with [ and {.

\$\endgroup\$
0
7
\$\begingroup\$

Keg, 1 byte

?

Try it online!

When there's no input, an EOF is raised:

Traceback (most recent call last):
 File "/opt/keg/Keg.py", line 500, in <module>
   exec(header + code + footer)
 File "<string>", line 6, in <module>
 File "/opt/keg/KegLib.py", line 119, in Input
   item = input()
 EOFError: EOF when reading a line

Also works with ¿

\$\endgroup\$
4
\$\begingroup\$

JavaScript, 1 byte / 7 solutions

The following tokens trigger SyntaxError: Unexpected end of input, or a similar message depending on the JS engine.

!
(
+
-
[
{
~

Or to summarize:

  • unary operators
  • opening parenthesis / bracket / brace

Exhaustive test on all ASCII characters

for(n = 0; n < 127; n++) {
  code = String.fromCharCode(n);
  res = false;

  try {
    eval(code);
  }
  catch(e) {
    res = e.toString() == 'SyntaxError: Unexpected end of input';
  }
  if(res) {
    console.log(code);
  }
}

Try it online!

\$\endgroup\$
4
\$\begingroup\$

Turbo Assembler, 0 bytes

Borland Turbo Assembler will print an "Unexpected end of file" when assembling a zero-byte file.

\$\endgroup\$
4
\$\begingroup\$

For the python users; the ones posting one character code, technically that is a SyntaxError which happens to read as an EOFERROR. (FYI, here's an example of all printable single characters that would cause this same error I'm getting a total of 34:)

from string import printable

chars = []
for c in printable:
    try: eval(c)
    except Exception as e:
        if 'EOF' in str(e):
            chars += [c]
print(chars)

This prints:

['!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '`', '{', '|', '}', '~', ' ','\t', '\n', '\r', '\x0b', '\x0c']

I'm not sure if raise EOFError would be considered an answer as unfortunately that's the shortest code I can think of to raise a legitimate EOFError in Python 3:


Python 3, 14 bytes

raise EOFError

Try it online!

OR

Without implicitly raising the error in Python 2 you could use this at the expense of an extra byte:


Python 2, 15 bytes

input('\u0004')

Try it online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ raise EOFError is considered invalid because the output contains the exact text EOFError that appears in the source code. \$\endgroup\$
    – user85052
    Oct 4, 2019 at 22:56
  • \$\begingroup\$ Why does it not count as an EOF error if it only “happens to read as” one? It does not matter where the EOF comes from, so long as it is an EOF — in the case of single brackets, a source input EOF. \$\endgroup\$
    – Dúthomhas
    Oct 4, 2019 at 23:05
  • \$\begingroup\$ Because I am avoiding the trivial answer: hard-coding the EOF error output like the program EOF. \$\endgroup\$
    – user85052
    Oct 4, 2019 at 23:07
  • \$\begingroup\$ Either way I was simply stating that the one char method doesn’t technically produce a real EOFError but in py2 the input method does \$\endgroup\$
    – Jab
    Oct 6, 2019 at 3:45
3
\$\begingroup\$

Haskell using hugs, 1 byte

{

The error message contains unexpected end of input.

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Japt v2.0a0, 1 byte

Each throws: SyntaxError: Unexpected end of input

´
¥
¶
ª
©
«
§
¨
±
µ
÷
Á
Â
Ò
Ó

Test it (Errors are displayed below the output field)

There are also a number of other possibilities, not specific to Japt, that are covered in Arnauld's JS solution, such as:

!
&
|
~
^
\$\endgroup\$
3
\$\begingroup\$

PHP, 1 byte

1

Try it online!

Run like this: php -r 1

Error: PHP Parse error: syntax error, unexpected end of file in ...

Any other characters apart from ;, #, space and new line should cause a similar error. So PHP probably has ASCII characters count - 4 single byte solutions.

\$\endgroup\$
3
\$\begingroup\$

R, 1 byte, 10 solutions

Any of these characters alone will trigger Error: unexpected end of input.

"
'
`
(
{
+
-
!
?
~
\$\endgroup\$
1
  • 3
    \$\begingroup\$ You missed ~ to bring it to an even 10 :-) \$\endgroup\$
    – Giuseppe
    Oct 4, 2019 at 21:56
2
\$\begingroup\$

Python 3, 1 byte

Sorry for the edit, misunderstood the question at first :P. We can do [ or ( or { to get unexpected EOF error. In first case, it expects a list, in second a tuple and so on.

[

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Perl, 1 byte

(

Try it with

 perl -e "("
 syntax error at -e line 1, at EOF
 Execution of -e aborted due to compilation errors.
\$\endgroup\$
2
\$\begingroup\$

Java, 1 byte

e

Try it online!


Old method that's more fun :]

void a()throws Exception{new java.io.DataInputStream(System.in).readInt();}

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ I was expecting a one-byte solution... Clever encoding of EOFException though. \$\endgroup\$
    – user85052
    Oct 6, 2019 at 1:10
  • \$\begingroup\$ I'll find one for ya. \$\endgroup\$
    – Poke
    Oct 6, 2019 at 1:11
  • \$\begingroup\$ @A_ turns out many single characters yield an EOF, haha. At least I've got a runtime version as well :P \$\endgroup\$
    – Poke
    Oct 6, 2019 at 1:13
2
\$\begingroup\$

T-SQL, 21 bytes

RAISERROR('EOF',11,1)
\$\endgroup\$
0
1
\$\begingroup\$

Bash, 1

"

Output

.code.tio: line 1: unexpected EOF while looking for matching `"'
.code.tio: line 2: syntax error: unexpected end of file

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Ruby, 1 byte

!

Try it online!

Any of ["!", "(", "*", "+", "-", ":", "[", "{", "~"] will work depending on the environment.

\$\endgroup\$
1
  • \$\begingroup\$ You could add ["\"", "%", "'", "/", "`"]. It depends on the exact requirement, though. Some will raise SyntaxError mentioning "end of file" or "end-of-input", but I couldn't find any which includes "EOF". \$\endgroup\$ Oct 6, 2019 at 13:39
1
\$\begingroup\$

Ruby, 1 byte

/ 

Outputs unterminated regexp meets end of file

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Perl 5, 1 byte

"

Try it online!

Not very inspired, but it is the shortest possible in the language.

Outputs Can't find string terminator '"' anywhere before EOF at .code.tio line 1.

\$\endgroup\$
1
\$\begingroup\$

Go, 0 bytes

All Go files must begin with package [identifier]. The error message is:

can't load package: package main: 
src/test.go:1:1: expected 'package', found 'EOF'
\$\endgroup\$