78
\$\begingroup\$

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
'''

so it isn't admissible.

\$\endgroup\$
  • 2
    \$\begingroup\$ Can a counter-example rely on input from STDIN? \$\endgroup\$ – Zacharý Jul 20 '17 at 14:17
  • 4
    \$\begingroup\$ Would this make a good CnR? \$\endgroup\$ – CalculatorFeline Jul 20 '17 at 16:59
  • 2
    \$\begingroup\$ Too late now I guess, but it seems like this could have been a cops and robbers challenge. There's a lot of skill evident in the attempts to make valid programs, as well as coming up with the strings in the first place. \$\endgroup\$ – user2390246 Jul 21 '17 at 7:43
  • 4
    \$\begingroup\$ My condolences to the Perl attempts. :) \$\endgroup\$ – Kaz Jul 23 '17 at 15:40
  • 2
    \$\begingroup\$ I'm pretty sure it's completely impossible in non-literate Haskell, thanks to nested comments. \$\endgroup\$ – dfeuer Mar 19 at 1:50

46 Answers 46

54
\$\begingroup\$

Changeling, 2 bytes




That's two linefeeds. Valid Changeling must always form a perfect square of printable ASCII characters, so it cannot contain two linefeeds in a row.

The error is always a parser error and always the same:

This shape is unpleasant.

accompanied by exit code 1.

Try it online!

\$\endgroup\$
  • \$\begingroup\$ This also works with 2Col. Try it online!. But the reason this breaks in 2Col is that every line needs to consist of exactly 2 characters, but the empty line breaks that. \$\endgroup\$ – Cows quack Jul 20 '17 at 6:10
  • 2
    \$\begingroup\$ +1 because this is automatically the winner, since 1-byte solutions are not allowed because "you can't just use a character which is always rejected." \$\endgroup\$ – Zacharý Jul 20 '17 at 14:46
  • 1
    \$\begingroup\$ @Cowsquack tfw I forgot about my own language \$\endgroup\$ – Skidsdev Jul 21 '17 at 10:54
  • 1
    \$\begingroup\$ @Skidsdev tfw I re-forgot about my own language, and forgot about me forgetting about my own language \$\endgroup\$ – Skidsdev Nov 19 '18 at 18:19
  • \$\begingroup\$ @Zacharý What about 0-byte solutions? \$\endgroup\$ – PyRulez Nov 19 '18 at 23:23
32
\$\begingroup\$

Java, 4 bytes

;\u;

Try it online!

This is an invalid Unicode escape sequence and will cause an error in the compiler.

error: illegal unicode escape
\$\endgroup\$
  • \$\begingroup\$ Doesn't work - one could have a string literal like "\\u;". \$\endgroup\$ – feersum Jul 20 '17 at 6:57
  • \$\begingroup\$ @feersum Fixed at the cost of one byte \$\endgroup\$ – Cows quack Jul 20 '17 at 7:07
  • 20
    \$\begingroup\$ @TheLethalCoder: Java preprocesses source code to alter \uXXXX escapes before doing anything else, so yes, this will work even inside comments.za \$\endgroup\$ – nneonneo Jul 20 '17 at 8:58
  • 3
    \$\begingroup\$ I think this is the shortest Java answer in the history of this site still.. \$\endgroup\$ – Magic Octopus Urn Mar 2 '18 at 18:31
  • 1
    \$\begingroup\$ @MagicOctopusUrn Actually, there is this 0 bytes Java answer (which isn't relevant anymore in the current meta, since it outputs to STDERR instead of STDOUT). Although both are pretty amazing and clever. :) \$\endgroup\$ – Kevin Cruijssen Mar 20 '18 at 16:13
24
\$\begingroup\$

JavaScript, 7 bytes


;*/\u)

Note the leading newline.

  • \u) is an invalid Unicode escape sequence and this is why this string is invalid
  • 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 \u) exposed
  • As stated by @tsh, the bottom line can be turned into a regex by having a / after the string, so by having the ) in front of the \u, we can ensure that the regex literal will always be invalid
  • As stated by @asgallant, one could do 1||1(string)/ to avoid having to evaluate the regex. The semi-colon at the beginning of the second line stops that from happening by terminating the expression 1||1 before it hits the second line, thus forcing a SyntaxError with the ;*.

Try it!

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

\$\endgroup\$
  • 2
    \$\begingroup\$ /* */\u0045 = 3 seems valid JavaScript code. \$\endgroup\$ – tsh Jul 20 '17 at 5:36
  • 2
    \$\begingroup\$ 3 */\u;/ is still valid. \$\endgroup\$ – tsh Jul 20 '17 at 5:55
  • 3
    \$\begingroup\$ Interesting to note that as of ES2018 (which won't be official until the end of this year) you can just wrap the whole thing in backticks due to this. You could probably fix this though just by inserting a backtick after the / (not that you need to fix it). (Also, the ; doesn't force the parsing of the bad regex, it forces a SyntaxError with the *.) \$\endgroup\$ – ETHproductions Jul 20 '17 at 15:28
  • 1
    \$\begingroup\$ @Leushenko But this doesn't work against #if 0 as seen here: Try it online! \$\endgroup\$ – Cows quack Jul 21 '17 at 18:17
  • 2
    \$\begingroup\$ In newer JS versions, String.raw with a template string can make this not break, because the invalid escape fails. Would be: String.raw`code here` \$\endgroup\$ – iovoid Feb 14 '18 at 4:23
22
\$\begingroup\$

COBOL (GNU), 8 bytes


THEGAME

First, a linefeed to prevent you from putting my word in a commented line.

Then, historically, COBOL programs were printed on coding sheets, the compiler relies heavily on 80-character limited lines, there are no multiline comments and the first 6 characters are comments (often used as editable line numbers), you can put almost anything there, AFAIK. I chose THEGAM at the beginning of the next line.

Then, the 7th symbol in any line only accepts a very restricted list of characters : Space (no effect), Asterisk (comments the rest of the line), Hyphen, Slash, there may be others, but certainly not E.

The error given by GnuCobol, for instance, is :

error: invalid indicator 'E' at column 7

Try it online!

Also, you just lost the game.

\$\endgroup\$
  • 27
    \$\begingroup\$ Also, you just lost the game. I almost downvoted \$\endgroup\$ – Stephen Jul 21 '17 at 13:30
15
\$\begingroup\$

Python, 10 bytes (not cpython)


?"""?'''?

Note the leading newline. Cannot be commented out due to the newline, and no combination of triple quoted strings should work if I thought about this correctly.

@feersum in the comments seems to have completely broken any cpython program on Windows as far as I can tell by adding the 0x1A character to the beginning of a file. It seems that maybe (?) this is due to the way this character is handled by the operating system, apparently being a translated to an EOF as it passes through stdin because of some legacy DOS standard.

In a very real sense this isn't an issue with python but with the operating system. If you create a python script that reads the file and uses the builtin compile on it, it gives the more expected behavior of throwing a syntax error. Pypy (which probably does just this internally) also throws an error.

Edit:

Due to @feersum's diligence in finding obscure ways to break the Python interpreter, this answer is completely invalidated for any typical cpython environment as far as I can tell! (Python 2 and 3 for both Windows and Linux) I do still believe that these cracks will not work for Pypy on any platform (the only other Python implementation I have tested).

\$\endgroup\$
  • \$\begingroup\$ @isaacg hmm, I actually did think of that but repl.it/JaHm/0 didn't work \$\endgroup\$ – KSab Jul 20 '17 at 5:10
  • \$\begingroup\$ @isaacg Oh I didn't notice, on that site you have to click the debug tab to see that it does indeed produce an error. \$\endgroup\$ – KSab Jul 20 '17 at 5:12
  • 1
    \$\begingroup\$ @officialaimm consider """?'''""" \$\endgroup\$ – KSab Jul 20 '17 at 5:20
  • 3
    \$\begingroup\$ I made a program with this substring that runs on my machine. However, I think it does not run on many interpreters/platforms/versions. Can you specify which version of Python interpreter and OS this answer is targeting? \$\endgroup\$ – feersum Jul 20 '17 at 7:54
  • 1
    \$\begingroup\$ Python 3 on Windows 7 happens to be exactly where my crack is working. Pastebin of base64-encoded program \$\endgroup\$ – feersum Jul 20 '17 at 18:19
14
\$\begingroup\$

C (clang), 16 bytes

 */
#else
#else

Try it online!

*/ closes any /* comment, and the leading space makes sure we didn’t just start one. The newline closes any // comment and breaks any string literal. Then we cause an #else without #if or #else after #else error (regardless of how many #if 0s we might be inside).

\$\endgroup\$
  • 5
    \$\begingroup\$ Cracked again. \$\endgroup\$ – feersum Jul 20 '17 at 7:18
  • 2
    \$\begingroup\$ Also since C++11 raw strings seem to work, a solution is impossible with gcc. \$\endgroup\$ – feersum Jul 20 '17 at 7:22
  • \$\begingroup\$ @feersum Huh, TIL that GCC accepts those in C code. I could specify -std=c99, but let’s try switching to clang. \$\endgroup\$ – Anders Kaseorg Jul 20 '17 at 7:28
  • 3
    \$\begingroup\$ I'm really surprised that gcc accepts C++11 raw strings. Specifying the compiler version or implementation is perfectly OK, so if it's illegal in Clang, it's fair game. \$\endgroup\$ – nneonneo Jul 20 '17 at 17:29
  • \$\begingroup\$ Can they close raw string again? @feersum \$\endgroup\$ – l4m2 Nov 1 '18 at 17:56
11
\$\begingroup\$

Pyth, 6 bytes

¡¡$¡"¡

¡ is an unimplemented character, meaning that if the Pyth parser ever evaluates it, it will error out with a PythParseError. The code ensures this will happen on one of the ¡s.

There are three ways a byte can be present in a Pyth program, and not be parsed: In a string literal (" or .", which are parsed equivalently), in a Python literal ($) and immediately after a \.

This code prevents \ from making it evaluate without error, because that only affects the immediately following byte, and the second ¡ errors.

$ embeds the code within the $s into the compiled Python code directly. I make no assumptions about what might happen there.

If the program reaches this code in a $ context, it will end at the $, and the ¡ just after it will make the parser error. Pyth's Python literals always end at the next $, regardless of what the Python code might be doing.

If the program starts in a " context, the " will make the string end, and the final ¡ will make the parser error.

\$\endgroup\$
11
\$\begingroup\$

Ada - 2 bytes

I think this should work:


_

That's newline-underscore. Newline terminates comments and isn't allowed in a string. An underscore cannot follow whitespace; it used to be allowed only after letters and numbers, but the introduction of Unicode made things complicated.

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to the site! :) \$\endgroup\$ – DJMcMayhem Jul 21 '17 at 16:57
9
\$\begingroup\$

x86 32-bit machine code, 11 bytes (and future-proof 64-bit)

90 90 90 90 90 90 90 90 90 0f 0b

This is times 9 nop / ud2. It's basically a NOP sled, so it still runs as 0 or more nops and then ud2 to raise an exception, regardless of how many of the 0x90 bytes were consumed as operands to a preceding opcode. Other single-byte instructions (like times 9 xchg eax, ecx) would work, too.

x86 64-bit machine code, 10 bytes (current CPUs)

There are some 1-byte illegal instructions in 64-bit mode, until some future ISA extension repurposes them as prefixes or parts of multi-byte opcodes in 64-bit mode only, separate from their meaning in 32-bit mode. 0x0e is push cs in 32-bit mode, but illegal on current CPUs (tested on Intel Skylake) in 64-bit.

0e 0e 0e 0e 0e 0e 0e 0e 0e 0e

Rules interpretation for executable machine code:

  • The bytes can't be jumped over (like the "not parsed" restriction), because CPUs don't raise exceptions until they actually try to decode/execute (non-speculatively).

  • Illegal means always raises an exception, for example an illegal-instruction exception. (Real programs can catch that with an exception handler on bare metal, or install an OS signal handler, but I think this captures the spirit of the challenge.)


It works because a shorter byte-string ending in ud2 could appear as an imm32 and/or part of the addressing mode for another instruction, or split across a pair of instructions. It's easiest to think about this in terms of what you could put before the string to "consume" the bytes as part of an instruction, and leave something that won't fault.

I think an instruction can consume at most 9 bytes of arbitrary stuff: a SIB byte, a disp32, and an imm32. i.e. the first 2 bytes of this instruction can consume 8 NOPs and a ud2, but not 9.

c7 84 4b 00 04 00 00 78 56 34 12        mov dword [rbx+rcx*2+0x400],0x12345678

Can't beat 9 nops:

    db 0xc7, 0x84   ; opcode + mod/rm byte: consumes 9 bytes (SIB + disp32 + imm32)
    times 9 nop          ; 1-byte xchg eax, ecx or whatever works, too
    ud2
  ----
   b:   c7 84 90 90 90 90 90 90 90 90 90        mov    DWORD PTR [rax+rdx*4-0x6f6f6f70],0x90909090
  16:   0f 0b                   ud2    

64-bit mode:

 c7 84 0e 0e 0e 0e 0e 0e 0e 0e 0e        mov    DWORD PTR [rsi+rcx*1+0xe0e0e0e],0xe0e0e0e
 0e                      (bad)  

But the bytes for 8 NOPs + ud2 (or times 9 db 0x0e) can appear as part of other insns:

    db 0xc7, 0x84   ; defender's opcode + mod/rm that consumes 9 bytes

    times 8 nop          ; attacker code
    ud2

    times 10 nop    ;; defenders's padding to be consumed by the 0b opcode (2nd half of ud2)
----
  18:   c7 84 90 90 90 90 90 90 90 90 0f        mov    DWORD PTR [rax+rdx*4-0x6f6f6f70],0xf909090
  23:   0b 90 90 90 90 90       or     edx,DWORD PTR [rax-0x6f6f6f70]
  29:   90                      nop
  2a:   90                      nop
  ...
\$\endgroup\$
  • \$\begingroup\$ The rules here weren't really clear enough for me to consider posting an asm/machine code answer. For example, why can't you just do ud2? It seems you're saying that you interpret the rules as forbidding jumping over the bytes, so ud2 would work just fine on its own, no? Oh…I guess you're saying the issue is that ud2 can appear as a prefix to a valid instruction? The second part of this answer was a little difficult for me to understand. \$\endgroup\$ – Cody Gray Jul 21 '17 at 6:02
  • \$\begingroup\$ @CodyGray: Right, the 2 bytes that encode ud2 can appear in the imm32 of any instruction. I was thinking about this in terms of what bytes can you put before such a string that "consume" 0f 0b as part of an earlier instruction instead of decoding as ud2. I wasn't totally happy with how I ended up presenting it, but I wanted to illustrate why only 8 nops wasn't enough, and what happened with 9 nops + ud2. \$\endgroup\$ – Peter Cordes Jul 21 '17 at 7:58
  • \$\begingroup\$ @CodyGray: An asm source program would be a totally different answer. That would have to error the parser used by the assembler, not produce faulting machine-code. So something like %else / %else might work to defeat %if 0, which can normally protect any invalid text from being parsed. (idea from a CPP answer) \$\endgroup\$ – Peter Cordes Jul 21 '17 at 8:02
  • \$\begingroup\$ Don't quite satisfy. Your solution may be just in .data. (though it makes it impossible) \$\endgroup\$ – l4m2 Nov 1 '18 at 2:29
  • \$\begingroup\$ @l4m2: To make the question answerable / interesting, I had to limit it to code that's executed (and not jumped over). See the rules interpretation bullet points in my answer. That would also rule out static data, of course. Because then it's not machine code at all, it's just data. This question required more adaptation than most for a machine-code answer to make sense, because there is no compile/assemble stage where you can error the parser, we're just talking about bytes already in memory. \$\endgroup\$ – Peter Cordes Nov 1 '18 at 2:38
6
\$\begingroup\$

C#, 16 bytes


*/"
#endif<#@#>

Works because:

  • // comment won't work because of the new line
  • /* comment won't work because of the */
  • You can't have constants in the code alone
  • Adding #if false to the start won't work because of the #endif
  • The " closes any string literal
  • The <#@#> is a nameless directive so fails for T4 templates.
  • The new line tricks it so having / at the start won't trick the */

Each variation fails with a compilation error.

\$\endgroup\$
  • 1
    \$\begingroup\$ Weird that you decided to include T4 templates in your code. Isn't T4 considered a separate language? \$\endgroup\$ – Arturo Torres Sánchez Jul 20 '17 at 21:07
  • 1
    \$\begingroup\$ @ArturoTorresSánchez I don't know I had never heard of them. Someone commented this didn't work when you included T4 templates so I added the fix. \$\endgroup\$ – TheLethalCoder Jul 21 '17 at 7:59
6
\$\begingroup\$

APL and MATL and Fortran, 3 bytes


'

Newline, Quote, Newline always throws an error since block comments do not exist:

\$\endgroup\$
  • \$\begingroup\$ This applies to MATL too \$\endgroup\$ – Luis Mendo Jul 20 '17 at 7:39
  • \$\begingroup\$ I think this would work in Fortran too. \$\endgroup\$ – Steadybox Jul 21 '17 at 2:27
5
\$\begingroup\$

TI-BASIC, 2 bytes, cracked :-(

:
:▫

This is a newline followed by a , which is a plotting symbol. Plotting symbols are only legal as arguments in plotting functions, or strings, which is impossible in this case because is prefaced with a new line.

\$\endgroup\$
  • 1
    \$\begingroup\$ What about :If 0:Then::▫:End \$\endgroup\$ – Timtech Jul 24 '17 at 17:09
  • 3
    \$\begingroup\$ This is a bit of a nitpick and not pertinent to your solution, but since the leading colons are a UI element of the program editor and not part of the program itself, I don't think they should be reproduced here (i.e. only newline characters should be used as line separators). They could also be confusing to people who haven't written TI BASIC on the TI 83/84. \$\endgroup\$ – Jakob Aug 8 '17 at 15:43
  • 3
    \$\begingroup\$ Yep, I doubt that there's a string illegal in any TI-Basic program, since you can skip even syntax errors with an If 0. \$\endgroup\$ – bb94 Mar 2 '18 at 2:31
  • \$\begingroup\$ @Jakob that is completely false. Colons count towards the total byte count of a program, even the ones automatically placed by the program editor. To prove this, create a new program called prgmA. When viewed in the memory management menu, it will have used 10 bytes. Then, press [ENTER] to create a new line. The byte count will now be 11 bytes. TI-BASIC does not have newline characters, so this additional byte must be that colon added in by the editor. \$\endgroup\$ – Tau Mar 19 at 2:02
  • 2
    \$\begingroup\$ @Tau Actually, TI-BASIC does have a newline character independent of the colon (0x3F, see here. The editor displays the newline character as a newline followed by a colon. \$\endgroup\$ – Scott Milner Mar 19 at 18:43
5
\$\begingroup\$

Literate Haskell, 15 bytes

Repairing a deleted attempt by nimi.


\end{code}
5
>

Try it online!

nimi's original attempt is the last two lines, based on Literate Haskell not allowing > style literate code to be on a neighboring line to a literate comment line (5 here). It failed because it can be embedded in a comment in the alternate ("LaTeX") literate coding style:

\begin{code}
{-
5
>
-}
\end{code}

However, the \begin{code} style of Literate Haskell does not nest, neither in itself nor in {- -} multiline comments, so by putting a line with \end{code} just before the line with the 5, that workaround fails, and I don't see a different one.

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

Free Pascal, 18 bytes


*)}{$else}{$else}

First close all possible comments, then handle conditional compile.

Please comment here if I forgot something.

\$\endgroup\$
  • 3
    \$\begingroup\$ @user902383 Does your example contain the leading newline of his snippet? \$\endgroup\$ – Brian J Jul 20 '17 at 18:44
  • \$\begingroup\$ @BrianJ nope, i thought it was just formatting issue, my bad \$\endgroup\$ – user902383 Jul 21 '17 at 9:23
  • \$\begingroup\$ I don't think it's possible in Free Pascal. Just put them after begin end.. \$\endgroup\$ – jimmy23013 Jul 24 '17 at 15:28
  • \$\begingroup\$ @jimmy23013 but it seems that codes after the end. become valid is allowed by the question. \$\endgroup\$ – tsh Jul 25 '17 at 1:13
4
\$\begingroup\$

Commodore 64 Basic, 2 bytes


B

(that's a newline followed by the letter "B").

Any line in a Commodore 64 program must begin with either a line number or a BASIC keyword, and stored programs only permit line numbers. There are no keywords beginning with "B" (or "H", "J", "K", "Q", "X", "Y", or "Z").

\$\endgroup\$
  • \$\begingroup\$ If I append =0 then this just becomes an assignment statement... \$\endgroup\$ – Neil Jul 21 '17 at 9:54
  • 1
    \$\begingroup\$ @Neil, that would be a valid immediate-mode command, but not a valid program. \$\endgroup\$ – Mark Jul 21 '17 at 10:05
4
\$\begingroup\$

Brain-Hack (a variation of Brain-Flak), 3 2 bytes

Thanks to Wheat Wizard for pointing out that Brain-Hack doesn't support comments, saving me a byte.

(}

Try it online!

\$\endgroup\$
  • \$\begingroup\$ How do you do comments in Brain-Flak? I don't know of any way to do those. \$\endgroup\$ – Erik the Outgolfer Jul 20 '17 at 18:26
  • \$\begingroup\$ @EriktheOutgolfer # TIO \$\endgroup\$ – Riley Jul 20 '17 at 18:27
  • \$\begingroup\$ Huh undocumented behavior. \$\endgroup\$ – Erik the Outgolfer Jul 20 '17 at 18:29
  • \$\begingroup\$ @EriktheOutgolfer I always assumed they were documented somewhere. I'll look at adding them. \$\endgroup\$ – Riley Jul 20 '17 at 18:34
  • \$\begingroup\$ You don't need the newline in BrainHack or Craneflak, Rain-Flak is the only one of the three versions that has line comments. Although Craneflak parses on the fly so its impossible to solve this in Craneflak, any solution could be beaten by prepending (()){()}. \$\endgroup\$ – Sriotchilism O'Zaic Aug 7 '17 at 23:26
3
\$\begingroup\$

CJam, 7 bytes

"e#"
:"

Try it online!

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

Logicode, 10 bytes


var A
A()

Try it online!

Newline prevents commenting the variable declaration. Results in TypeError: 'list' object is not callable and we aren't able to define a lambda expression A() to make this valid code (will still throw the same error).

circ A>

Looks like it might work, but unfortunately, we can define vars A and circ that make this valid:

var A=0
var circ
circ A>
\$\endgroup\$
  • \$\begingroup\$ Cracked. \$\endgroup\$ – feersum Jul 26 '17 at 6:31
  • \$\begingroup\$ @feersum Oh hey, nice job. \$\endgroup\$ – Draco18s Jul 26 '17 at 12:54
  • \$\begingroup\$ @Draco18s I think feersum meant that this answer is invalid. \$\endgroup\$ – Erik the Outgolfer Mar 23 '18 at 21:36
  • \$\begingroup\$ @EriktheOutgolfer He cracked it, thus my answer is invalid? Yes, I suppose, but I couldn't find a way to make it valid after that and have no interest in doing so now, nine months later. Logicode is not a language I am very familiar with. I was congratulating him on proving my answer wrong. \$\endgroup\$ – Draco18s Mar 24 '18 at 1:46
3
\$\begingroup\$

VBA, 2 Bytes

A linefeed followed by an underscore - the _ functions as the line continuation character in VBA, and as there is nothing in the line directly to the left or above the line continuation, coupled with VBA's lack of multiline comments means that this will always throw the compile time error Compile Error: Invalid character


_
\$\endgroup\$
  • \$\begingroup\$ You do depend on your pattern starting on a new line... so, add a newline. \$\endgroup\$ – Deduplicator Jul 20 '17 at 19:18
  • \$\begingroup\$ @Deduplicator it already has a new line, - it does not matter what follows the _, only that there is no valid line to the left or above it \$\endgroup\$ – Taylor Scott Jul 20 '17 at 19:48
  • \$\begingroup\$ What if it is embedded like this: myfunction( \n_ )? \$\endgroup\$ – Deduplicator Jul 20 '17 at 20:00
  • \$\begingroup\$ @Deduplicator the line continuation character must be on the same line as it is continuing ie Public Function Foo( ByVal bar as Integer, _ (new line) bas as long) as double - so yes, it would result in an error if you called the function you described \$\endgroup\$ – Taylor Scott Jul 20 '17 at 21:00
  • \$\begingroup\$ Ok, in that case it's more like myfunction( _ \n_ ). Sorry for the confusion. To put it another way, you should have used two newlines. \$\endgroup\$ – Deduplicator Jul 20 '17 at 21:34
3
\$\begingroup\$

AWK, 3 bytes


/

Try it online!

Since AWK doesn't have a method to do multi-line comments, need newline before and after / to prevent commenting out or turning this into a regex, e.g. add 1/. The most common message being unexpected newline or end of string.

\$\endgroup\$
  • 1
    \$\begingroup\$ I think he intended for the newline to come before the slash \$\endgroup\$ – Skidsdev Jul 21 '17 at 11:25
  • \$\begingroup\$ I think I need newlines before and after. That's what I get for posting when tired. \$\endgroup\$ – Robert Benson Jul 21 '17 at 15:43
  • 2
    \$\begingroup\$ Cracked. \$\endgroup\$ – feersum Jul 22 '17 at 5:14
  • \$\begingroup\$ If I add enough newlines in there, I'm sure it'll break... not sure if there's anything more clever I could do. :( \$\endgroup\$ – Robert Benson Jul 23 '17 at 15:20
3
\$\begingroup\$

SmileBASIC, 2 bytes


!

Nothing continues past the end of a line, so all you need is a line break followed by something which can't be the start of a statement. ! is the logical not operator, but you aren't allowed to ignore the result of an expression, so even something like !10 would be invalid (while X=!10 works, of course)

Similar things will work in any language where everything ends at the end of a line, as long as it parses the code before executing it.

There are a lot of alternative characters that could be used here, so I think it would be more interesting to list the ones that COULD be valid.

@ is the start of a label, for example, @DATA; ( could be part of an expression like (X)=1 which is allowed for some reason; any letter or _ could be a variable name X=1, function call LOCATE 10,2, or keyword WHILE 1; ' is a comment; and ? is short for PRINT.

\$\endgroup\$
  • \$\begingroup\$ oh, for some reason when I edited the post it was duplicated... \$\endgroup\$ – 12Me21 Mar 1 '18 at 20:11
2
\$\begingroup\$

Fortran, 14 bytes


end program
e

No multiline comments or preprocessor directives in Fortran.

\$\endgroup\$
  • 1
    \$\begingroup\$ Is there a good way to test this online? Also, which version/compiler of Fortran? \$\endgroup\$ – Robert Benson Jul 23 '17 at 15:21
2
\$\begingroup\$

R (base package), 6 7 bytes


%"'`% 

Note leading newline and trailing space.

One character (backtick) added to prevent the crack that @Giuseppe found, which involves creating a weird function name such as % %. From experimenting, it appears that a backtick cannot appear in such a name without breaking things. I fully expect to be proven wrong though!

Other important features:

  • Newline prevents commenting it out
  • % is a special character that only appears in certain commands such as %% and %in%. As far as I know it can't be followed by a space (except in a function name, see above) or a string
  • If both % characters are contained inside quotes, that gives two consecutive quoted strings with no separator, which yields an error.

(There may well be packages out there that might make valid code out of this, so this only applies to the base package.) <- Actually, thinking about it, this probably isn't true. I think packages are all built on R code, so if it can be in a package, it can be coded from scratch.

\$\endgroup\$
  • \$\begingroup\$ Nice idea, but this cracks it. \$\endgroup\$ – Giuseppe Jul 20 '17 at 11:52
  • \$\begingroup\$ Heck, that even works without quote \$\endgroup\$ – Giuseppe Jul 20 '17 at 12:01
  • 1
    \$\begingroup\$ @Giuseppe Clever! I forgot about backquotes. Will have to revisit this when I have the time. Maybe a carefully placed backquote in the string might fix it. \$\endgroup\$ – user2390246 Jul 20 '17 at 12:31
  • \$\begingroup\$ Maybe \n%"'(backquote)"'% ? \$\endgroup\$ – Giuseppe Jul 20 '17 at 16:30
  • 1
    \$\begingroup\$ This is a tough language for this challenge. Currently, if you precede this code with ‘\n%"'‘ = 1; ‘% %‘ = c; ‘ (replace the ‘s with backticks) and follow it with % 1 it runs fine. \$\endgroup\$ – rturnbull Jul 22 '17 at 21:26
2
\$\begingroup\$

C (GCC), 7 bytes

Has been broken, can't think of anything else that's not already been submitted.



*/)"#

\*/ - Stops you from inserting /* before it

)" - Stops this:

\# - Causes the following error

stray ‘#’ in program

You shouldn't be able to #define # because that will give an error. I am using GCC 6.4.0. The lack of a semicolon after )" will cause an error even if you append a valid preprocessor statement after #.

\$\endgroup\$
  • \$\begingroup\$ ... there is // lol \$\endgroup\$ – HyperNeutrino Jul 21 '17 at 0:06
  • \$\begingroup\$ Inserting 2 newlines before the current snippet should actually stop // from working (1 doesn't work because you can backslash escape it) \$\endgroup\$ – Value Ink Jul 21 '17 at 0:09
  • 1
    \$\begingroup\$ Welcome to PPCG! Very nice first submission. If you restrict your answer to Clang (like the other C answer), I think you can cut this down to 5 bytes (removing the )" part). \$\endgroup\$ – Steadybox Jul 21 '17 at 2:32
  • 3
    \$\begingroup\$ You can't work around raw strings as they take arbitrary delimiters. Example. \$\endgroup\$ – feersum Jul 21 '17 at 4:17
  • 2
    \$\begingroup\$ Also, you can just #if 0 the entire thing. \$\endgroup\$ – Anders Kaseorg Jul 21 '17 at 4:53
2
\$\begingroup\$

Taxi,  4  5 bytes

'"]'"

Fixed with help in comments from EngineerToast.

I believe this works correctly. '" terminates any strings we are in and ] terminates any comments we are in. Taxi does not allow inline comments (comments must start as the first character in a line) so this code must always be prepended by \n[. After \n[<comment>], '" again makes sure that the first '" ended a string, so the second '" starts a string, which is invalid directly after a comment.

\$\endgroup\$
  • \$\begingroup\$ '"]:' is waiting at Writer's Depot. is valid. Try just '"'" \$\endgroup\$ – Engineer Toast Jul 20 '17 at 15:51
  • \$\begingroup\$ @EngineerToast oh, right, I'm dumb. But then you have ['"'"] I think \$\endgroup\$ – Stephen Jul 20 '17 at 15:53
  • \$\begingroup\$ Good point. '"]'" is the combination of both, I think. \$\endgroup\$ – Engineer Toast Jul 20 '17 at 15:54
  • \$\begingroup\$ @Zacharý the comment is that I have to add (non-breaking) spaces around it for it to look right \$\endgroup\$ – Stephen Jul 20 '17 at 16:05
  • \$\begingroup\$ Cracked. \$\endgroup\$ – feersum Jul 24 '17 at 3:16
2
\$\begingroup\$

JavaScript (Node.js), 9 8 bytes

`*/
\u`~

Try it online!

I think this should be illegal enough.

Previous JS attempts in other answers


;*/\u)

By @Cows quack

As an ES5 answer this should be valid, but in ES6 wrapping the code with a pair of backticks wrecks this. As a result valid ES6 answers must involve backticks.

`
`*/}'"`\u!

By @iovoid

This is an improved version involving backticks. However a single / after the code breaks this (It becomes a template literal being multiplied by a regex, useless but syntactically valid.) @Neil made a suggestion that changing ! to ). This should theoretically work because adding / at the end no longer works (due to malformed regex.)

Explanation

`*/
\u`~

This is by itself illegal, and also blocks all single and double quotes because those quotes cannot span across lines without a \ at the end of a line

//`*/
\u`~

and

/*`*/
\u`~

Blocks comments by introducing illegal escape sequences

``*/
\u`~

Blocks initial backtick by introducing non-terminated RegExp literal

console.log`*/
\u`~

Blocks tagged template literals by introducing an expected operator between two backticks

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

Rockstar, 4 5 bytes

Crossed out 4 is still 4 :(

)
"""

Rockstar is a very... wordy language.
While " can be used to define a string, such as Put "Hello" into myVar, to my knowledge there is no way for 3 quotes to appear outside of a comment, and the close paren ensures that won't happen either (Comments in Rockstar are enclosed in parentheses, like this).

Rockstar also has a poetic literal syntax, in which punctuation is ignored, so the newline makes sure that the 3 quotes are the start of a line of code, which should always be invalid

\$\endgroup\$
  • \$\begingroup\$ What about (()"""), wouldn't that be a no-op? \$\endgroup\$ – ბიმო Nov 21 '18 at 23:46
  • \$\begingroup\$ @BMO first paren opens a comment, 2nd paren does nothing because it's commented, 3rd paren closes the comment, then you have """) being parsed as code, which is invalid \$\endgroup\$ – Skidsdev Nov 22 '18 at 1:20
  • \$\begingroup\$ Hmm, nested comments are not in the specs. Comments seem to be discouraged anyways. But you oversaw poetic string literals which allow any string, so Goethe says )""" is valid. \$\endgroup\$ – ბიმო Nov 22 '18 at 17:13
  • \$\begingroup\$ @BMO good point, can be fixed by inserting a newline inbetween ) and """ \$\endgroup\$ – Skidsdev Nov 23 '18 at 18:21
2
\$\begingroup\$

Powershell, 10 8 12 14 13 14 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.

\$\endgroup\$
  • 1
    \$\begingroup\$ Or protectors + @= \$\endgroup\$ – mazzy Nov 19 '18 at 22:26
  • 1
    \$\begingroup\$ @IsItGreyOrGray AAAAAAAAAAAw heck. \$\endgroup\$ – Veskah Jan 25 at 21:12
  • 2
    \$\begingroup\$ 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. :) \$\endgroup\$ – GreyOrGray Jan 25 at 21:38
  • 1
    \$\begingroup\$ @IsItGreyOrGray Sonofagun. Now featuring semi-colon armor? \$\endgroup\$ – Veskah Jan 25 at 23:06
  • 1
    \$\begingroup\$ Nice! I've got nothing. Everything I've tried has failed. \$\endgroup\$ – GreyOrGray Jan 28 at 14:31
2
\$\begingroup\$

Runic Enchantments, 3 bytes

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.

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

INTERCAL, 12 bytes

DOTRYAGAINDO

Try to crack it online!

INTERCAL's approach to syntax errors is a bit special. Essentially, an invalid statement won't actually error unless the program tries to execute it. In fact, the idiomatic syntax for comments is to start them with PLEASE NOTE, which really just starts a statement, declares that it isn't to be executed, and then begins it with the letter E. If your code has DODO in the middle of it, you could prepend DOABSTAINFROM(1)(1) and tack any valid statement onto the end and you'll be fine, if it's DODODO you can just bend execution around it as (1)DON'TDODODOCOMEFROM(1). Even though INTERCAL lacks string literal syntax for escaping them, there's no way to use syntax errors to create an illegal string, even exhausting every possible line number with (1)DO(2)DO...(65535)DODODO, since it seems that it's plenty possible to have duplicate line numbers with COME FROM working with any of them.

To make an illegal string, we actually need to use a perfectly valid statement: TRY AGAIN. Even if it doesn't get executed, it strictly must be the last statement in a program if it's in the program at all. 12 bytes is, to my knowledge, the shortest an illegal string can get using TRY AGAIN, because it needs to guarantee that there is a statement after it (executed or not) so DOTRYAGAIN is just normal code, and it needs to make sure that the entire statement is indeed TRY AGAIN, so TRYAGAINDO doesn't work because it can easily be turned into an ignored, normal syntax error: DON'TRYAGAINDOGIVEUP, or PLEASE DO NOT TRY TO USE TRYAGAINDO NOT THAT IT WOULD WORK. No matter what you put on either side of DOTRYAGAINDO, you'll error, with either ICL993I I GAVE UP LONG AGO, ICL079I PROGRAMMER IS INSUFFICIENTLY POLITE, or ICL099I PROGRAMMER IS OVERLY POLITE.

\$\endgroup\$
  • \$\begingroup\$ There might be a few other compile-time errors which can fire before ICL993I I GAVE UP LONG AGO. \$\endgroup\$ – Unrelated String Apr 4 at 1:47
  • \$\begingroup\$ If, while using every line label, you also COME FROM every line label, it might be a bit difficult to divert control flow around the block, but there's nothing at all stopping you from just GIVING UP! \$\endgroup\$ – Unrelated String Apr 8 at 1:19

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.