# Find an Illegal String

The challenge is to find a string of characters that cannot appear in any legal program in your programming language of choice. That includes comments, strings, or other "non-executable" parts.

## Challenge

• 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 (e.g. passing a flag to convert warnings into errors).
• If your programming language requires a specific encoding (e.g. UTF-8), your string must also be correctly encoded (i.e. strings which fail solely due to character decoding errors are not allowed).
• Every individual character in your submission must be admissible in a legal program; that is, you can't just use a character which is always rejected.
• The compiler/interpreter/runtime must give an error when given any source code that contains your string as a substring. The error does not have to be the same across programs - one embedding of your string might cause a syntax error, while another might cause a runtime error.

## Scoring

• Shortest illegal string for each language wins.
• You should explain why your string is illegal (why it cannot appear anywhere in a legal program).
• Dispute incorrect solutions in the comments. More specifically, you should provide a link to TIO or equivalent demonstrating a legal program (i.e. one that doesn't produce any errors) that contains the proposed substring.
• Some languages (e.g. Bash, Batch, Perl) allow arbitrary binary data to be appended to a program without affecting validity (e.g. using __DATA__ in Perl). For such languages, you may submit a solution that can appear only in such a trailing section. Make sure to make a note of that in your answer. (The definition of this "trailing section" is language-dependent, but generally means any text after the parser has entirely stopped reading the script).

## Example

In Python, I might submit

x
"""
'''


but this can be embedded into the larger program

"""
x
"""
'''
y
'''


• Can a counter-example rely on input from STDIN? Jul 20 '17 at 14:17
• Would this make a good CnR? Jul 20 '17 at 16:59
• My condolences to the Perl attempts. :)
– Kaz
Jul 23 '17 at 15:40
• I'm pretty sure it's completely impossible in non-literate Haskell, thanks to nested comments. Mar 19 '19 at 1:50
• @dfeuer That was my conclusion too. I even looked through GHC's lexer code to see if there was a loophole, but it seems very diligent about allowing absolutely every byte sequence inside sufficiently nested {- -} brackets. Apr 4 '19 at 1:32

# JavaScript, 7 bytes

 */
##

• Adding a // at the beginning will still not work because of the leading newline, leaving the second line uncommented.

• Adding a /* will not uncomment the string completely because of the closing */ that completes it, leaving the # exposed.

• Adding  will not quote the string completely, because of  that completes a string, leaving the # exposed.

• Regular expressions won't work because of # following / character.

• / following * cannot be parsed as a regular expression, as regular expressions cannot have newlines

### Try it!

clicky.onclick=a=>{console.clear();console.log(eval(before.value+" */\n##"+after.value));}
textarea {
font-family: monospace;
}
<button onclick="console.clear();">Clear console</button>
<br>
<textarea id=before placeholder="before string"></textarea>
<pre><code> */
##</code></pre>
<textarea id=after placeholder="after string"></textarea>
<br>
<button id=clicky>Evaluate</button>

# JavaScript, 11 characters


*/}'"\u)


The backticks make sure to kill template strings, the quotes get rid of strings, the newline avoid commented lines, the end of comment avoids block comments, and the last backtick and escape (with a ) to avoid appending numbers or /) try to start a invalid string.

Try it online!

# Fortran, 14 bytes


end program
e


No multiline comments or preprocessor directives in Fortran.

• Is there a good way to test this online? Also, which version/compiler of Fortran? Jul 23 '17 at 15:21

# Scratch (scratchblocks2), 3 bytes

There's no such thing as an error in scratchblocks2 - just red-colored blocks - but this can't be expressed in actual Scratch, so I think it's OK.


<?

Leading newline to avoid this just being commented or ::ed out.

Then a predicate block with it's label starting with ? - there's no such block.

• Can't test it (I'm not going to install scratchblocks2), but I don't see why say [\n<?] breaks. The [] seem to support parsing \n (like for drop-down menus). Nov 22 '18 at 17:27
• There's a leading newline. Nov 22 '18 at 21:15
• I think define\n<? defines the <?> block as a custom block, here Jun 1 '21 at 14:49

# Powershell, 10812141314 16 bytes

-2 byte thanks to Mazzy finding a better way to break it
+4 -1 bytes thanks to IsItGreyOrGray

$#> '@'; "@"; @=  I hope this works. ' and " to guard against quotes, #> to break the block-comment, new lines to stop the single-line comment, both '@ and "@ to catch another style of strings, and then starts an improper array to throw a syntax error. The logic being they can't use either set of quotes to get in, they can't block-comment it out, If @" is used, it'll create a here-string which can't have a token afterwards, and if they leave it alone, it'll try to make a broken array. This statement wants to live so hard, I keep finding even more holes in the armor. • Or protectors + @= Nov 19 '18 at 22:26 • @IsItGreyOrGray AAAAAAAAAAAw heck. Jan 25 '19 at 21:12 • It looks like changing #> to$#> will break it as "not recognized as the name of a cmdlet..." It might be made legal again somehow, but I don't have a way. Yet. :) Jan 25 '19 at 21:38
• @IsItGreyOrGray Sonofagun. Now featuring semi-colon armor? Jan 25 '19 at 23:06
• Nice! I've got nothing. Everything I've tried has failed. Jan 28 '19 at 14:31

# ECMAScript Regex, 4 bytes

]](+


Try it on regex101

This is a quite a bit easier than PCRE. There's no \Q...\E, no free-spacing mode, and no comments. But if we used just ](+ we could still be inside a character class and have our ] escaped, as [\](+] which would be treated as a character class of ](+. So we still need the double ] to make sure we exit any character class we may have been in, which works even if a range was started, e.g. [!-]](+.

(+ is illegal in any context other than a character class, and will give an error message such as "Nothing to repeat" or "Incomplete group structure" / "The preceding token is not quantifiable".

# PCRE Regex, 6 7 bytes

\E
)](+


Try it on regex101

Any string not containing \E would be legal inside a \Q...\E literal sequence. By starting this one with \E, we break out of such a sequence if we were in one. And if we weren't in one, but are preceded by a \, then it will be treated as a literal \E, and we'll still be guaranteed not to be inside a \Q...\E.

(+ is not part of any legal group structure, and will generate a compile-time error ("Incomplete group structure" and/or "The preceding token is not quantifiable" / "quantifier does not follow a repeatable item") anywhere other than:

1. Within a \Q...\E. We've handled this. We can't be inside one thanks to the \E.
2. Immediately after a \. But since we have it immediately after a \E, it can't be immediately after a \. Note that \E alone is valid, even if there was no \Q before it.
3. Inside a #... style comment. This can only happen in free-spacing mode, but this can be turned on by (?x) anywhere in a regex, so we need to handle it.
4. Inside a (?#...) style comment.
5. Inside a character class, e.g. [(+] or [\Q\E(+] – or even [\Q\E](+], which will be treated as [](+], which, since an empty character class is not part of PCRE syntax (except in PCRE2 with the PCRE2_ALLOW_EMPTY_CLASS option enabled), is treated as a character class consisting of ](+ (the beginning of a character class is the only place where ] does not need to be escaped).

Because of #3, we need a newline, to break out of any #... comment we may be in.

Because of #4, we need a ), to break out of any (?#...) comment we may be in.

And it is because of #5 that we need to put ] in front of the (+. This closes any character class we might have been in. If we hadn't already put a newline and/or a ) to close a potential comment, we'd need this to be ]], because a character class can't be empty and ] is allowed to be the first character in a class without being escaped. In any case, thanks to having a character before our ], it even works if a range was started, e.g. [!-\E)](+.

Edit: Silly me, didn't protect it from being inside comments. Fixed.

# Runic Enchantments, 3 bytes

Ṷ


One of many possible variations.

Try it online!

Runic utilizes unicode combining characters in a "M modifies the behavior of C" (where C is a command). As such, no two modifiers are allowed to modify the same command and the parser will throw an error if such an occurrence is found.

Similarly, certain commands that redirect the IP cannot be modified in any way, due to the existence of direction modifying modifier characters (and both in the same cell makes no sense).

There is no way to escape or literal-ize the string to make it valid. Tio link contains a ; in order to bypass the higher-priority "no terminator" error.

# Jelly, 3 bytes

»
€


Try it online!

Jelly has no comments, and every line in the code is parsed whether or not it is reachable. The only way to prevent some code from being executed is starting a string literal using “. This is countered by », which terminates a string (and interprets it as a dictionary-compressed string).

Thus € (each) will always be executed on a link (line) of its own. It tries to get a link from its left; since none exists, the interpreter errors.

# Scratch (1.x, except 1.2 beta), scratchblocks syntax, 26 bytes


when gf clicked
say(()/()


Leading new line ensures that "when gf clicked" will not be in a comment, so that what's below it will run.

This errors when run in the Stage, because the Stage cannot use the say block.

This errors when run in a sprite by itself, because a divide by zero is attempted. (When a number argument is blank, it is read as 0.)

This errors when run in a sprite when ) or a new line is added after it, because it doesn't change what the existing code does.

This errors when run in a sprite when something else is added after it, because it creates an undefined block which causes an error when run.

1.2 beta is excluded because it featured comment blocks (different from modern comments), which supported multiline, which this could be put into.

Versions past 1.4, including the Experimental Viewer, are excluded because dividing by zero does not cause an error.

## NDBall 2 bytes

specificly in NDBallSim V1.0.1

##


a hashtag is a memory cell instructor and requires a direction, two of them anywhere will cause the error

NDBall Parse ERROR @ LINE (whatever line): Memory cell requires a direction ex: #>12


this double character trick can actually be done with many more chars, to be exact all of these )(,}{|><+-pP\$%Y][E and newline

This is actually all (discounting digits) of the useable chars in the lang itself because it never has a case where you use the same char twice

# Dis, 2 bytes.

))


## How it works

• ( to the nearest ) is a comment.
• But nothing can match the second ) above in this syntax.
• Thus it is syntax error.
• What about (())? Does Dis not support parentheses inside comments? Nov 5 '21 at 15:01
• @mayube Comments may be used, enclosed in parentheses. They can't be nested.
– user100411
Nov 6 '21 at 3:27

# Pip Classic, 10 bytes


;\"
;
*;


Try it online!

I think this should be solid, but I welcome anyone to prove me wrong.

### How?

A semicolon at the start of a line begins a single-line comment, so our code is effectively

*;


and Pip complains because * is a binary operator and needs a left operand.

If we add any expression before the snippet, we still get an error because * needs a right operand. No operand can be supplied because * is followed by the expression terminator ;.

We can't wrap the snippet in a string, because every possible string delimiter (", \", and ) is matched by a delimiter in the snippet. (In a regular "-delimited string, the backslash is not an escape character, so it doesn't mess anything up.)

Finally, we can't comment out the last line of the snippet because Pip Classic doesn't have block comments.

# S.I.L.O.S, 4 bytes

Silos is competitive \o/


x+



S.I.L.O.S runs on a two pass interpreter / compiler. Before execution a "compiler" attempts to simplify the source into an array describing the sourc Each line is treated separately. x+a is an assignment operator that will add ea to the value of x and store it into x. However the "compiler" will break. Therefore, we take this string and add a new line before and after ensuring it's on its own line and breaks the compiler.

Try it online!

• Why doesn't ax+ error out? Jul 20 '17 at 18:40
• undefined compiler behavior @EriktheOutgolfer Jul 20 '17 at 19:27

## AutoHotkey, 5 bytes

 is the escape character. You can only escape a " when assigning it to a variable.

\n*/ prevents it from being commented out or assigned to a variable.


*/"


# Husk1, 3 bytes


◊



Try it online!

### Explanation

The newlines force ◊ to be parsed as a supposed built-in, however since it's not (yet) implemented the parsing fails with unexpected "\9674" or an error because of empty lines.

Note: Initially I tried to force an inference failure, but the type-checking is done lazily and one can easily "un-break" programs with adding a valid main function.

1: The code might work at some point in the future. So to be precise any version of Husk as of before the date of this post (ie. at least up to commit 0806b9d).

• An inference failure would have been fun, but this is probably shorter than that would be anyhow. Apr 4 '19 at 2:28

# Keg, 3 4 bytes

Fixed a for loop bug noted by @Jono2906


)ø.


Try it online!

## Explanation

\n    Terminate a line-comment
)     End a for loop
ø    Clear the stack
.   Try to print the TOS item, which will create an error to the program.

• 3 bytes using strings Nov 26 '19 at 20:51
• But this is valid.
– user85052
Nov 27 '19 at 4:06

# naz, 2 bytes

0d


This command will attempt to divide the register by zero, throwing the error division by zero.

Also 2 bytes:

0p


This command will attempt to find the remainder of dividing the register by zero, which will also throw the error division by zero.


";


Try it online!

• This can be commented out Nov 16 '21 at 18:08
• @Mayube Fixed. Thx. Nov 16 '21 at 18:11
• Add++ doesn't seem to support multi-line strings or comments so 2 bytes Nov 16 '21 at 18:28
• @Mayube Nope Try it online! Nov 16 '21 at 18:32

# Gaia, 3 bytes


#“


Try it online!

Each line in Gaia is a separate function, so the newline ensures that the code starts at the beginning of a function. Even putting a newline in a string literal will start a new function, since Gaia allows omitting closing quotes. In addition, all functions are parsed before execution, so adding additional functions below won't help.

The # is a meta, which has to directly follow an operator. At the start of the function, there is no operator, so it's a syntax error.

The “ is an opening quote for string literals. It's there because Gaia also allows omitting the opening quote of strings at the start of a function. If this opening quote wasn't here, you could write #” which is entirely legal.

# Ly, 6 bytes


\""{)


The newline prevents line comments, Ly doesn't have block comments, the \"" ensures that all open string literals will close, and the unmatched brackets raise the error.

# FRACTRAN, 2 bytes

()


Try it online!

Since FRACTRAN doesn't have any way of including comments or literals (AFAICT), this will always error any valid program, since all valid programs must be a valid fraction, and this string can never be part of a valid fraction.

# Ink, 5 bytes


*/{}

*/ ends multi-line comments. Thanks to the leading newline, you can't put a / in front of it to make it the start of a comment rather than the end of one.
{ and } enclose things meant to be parsed, rather than simply printed. If there's nothing between them, the compiler gets sad because it Expected some kind of logic, conditional or sequence within braces: { ... } but saw '}'. This happens even inside string literals, so there's no need to check if we're inside one of those.

# Milky Way, 2 bytes

Tries to execute an undefined opcode. Milky Way does not have comments. The newline is for ending strings.


)


Try it online!

''


Try it online!

All Unreadable commands must be of the form '""…", with one ' followed by 1 to 10 "s. Having two successive 's anywhere in the program leads to error: parser failed: invalid command (0): '.

# Turing Machine Code 5 bytes

Assuming block editing isn't allowed:

0


Or with the symbols showing:

< cr >< lf >
0
< cr >< lf >


Without block editing, it is impossible to stick this behind the comment symbol (';'), as the '0' will end up on the next line anyway. There is no block commenting in Turing Machine Code, a fact that is taken advantage of in other answers here as well. This patch of code would not only not run, it would kill the whole program before it can begin to execute, no matter where it is placed.

Try it online!

# Zig 0.6.0, 2 bytes





(\n)

A newline will reset the tokenizer state, escaping any comments or multiline strings and erroring for single line strings. Backticks are not a valid character except in strings.

Try it online!

# Lean Mean Bean Machine, 7 bytes

OO
0/
&


Try it online!

Unfortunately this is basically an entire invalid program, but it can be inserted into larger programs, and there's no way to my knowledge to prevent the runtime error.

LMBM creates a 'marble' (aka instruction pointer) at every O in the code, and there is no way to prevent this (which now that I think about it causes some issues if you need an O in a string). & is the division operator in LMBM.

In short, this snippet causes a ZeroDivisionError: division by zero runtime error.

# KonamiCode, 3 bytes

]()

Explanation:

First, the ] closes any comments this string might be placed in. Then, the () attempts to pass an empty number to the comment closing sign. Using the pynami interpreter, this will always result in an "This command doesn't have a parameter!" error, even if you put it inside a comment.

# Chicken, 1 byte

a


## Explanation:

Only This chars are allowed

chicken