Find an Illegal String

85

8

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.

nneonneo

Posted 2017-07-20T04:35:53.570

Reputation: 11 445

2Can a counter-example rely on input from STDIN? – Zacharý – 2017-07-20T14:17:46.420

6Would this make a good CnR? – CalculatorFeline – 2017-07-20T16:59:23.937

@CalculatorFeline: Only for languages where parsing is immediate (not performed in advance) - this is true of Bash and Batch for example. For those languages, I allow for a small exception - see the last Scoring point. – nneonneo – 2017-07-20T17:26:07.667

@Zacharý: I think that a counterexample is valid if any execution of the program can complete successfully (i.e. if there is some way to run the program such that it doesn't crash). Therefore, a string is not illegal if it can be embedded in some program that doesn't crash on some input. – nneonneo – 2017-07-20T17:27:27.053

@CalculatorFeline: As for CnR, I considered it during the sandbox proposal, but decided against it because legitimate solutions will receive zero robber submissions (i.e. things get boring for the robbers). But, if it turns out that a lot of submissions are faulty, I may convert the question to CnR so we can weed out non-illegal strings. – nneonneo – 2017-07-20T17:28:42.517

2Too 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. – user2390246 – 2017-07-21T07:43:31.900

Does it count if the standard IDE crashes at entering the string? (truely crashes) – Mega Man – 2017-07-23T08:16:43.203

5My condolences to the Perl attempts. :) – Kaz – 2017-07-23T15:40:46.197

@Kaz Well, there are only a finite number of Unicode characters that could be doubled to close an s@-like quote... – aschepler – 2017-07-24T11:32:51.727

I think it is impossible in Perl 6 as you can use an arbitrary number of delimiting characters for a string literal Q{{{{{{{{{{ab」}}」cd}}}}}}}}}} (ab」}}」cd), andQ literals don't do any sort of interpretation of their contents. – Brad Gilbert b2gills – 2017-07-26T00:44:47.287

1In forth this seems nearly impossible, given the ability to overwrite effectively any word/symbol. I'm sure there are probably ways to do it by redefining core system words but nothing that couldn't appear after some code that backs those words up as other words first. – reffu – 2018-02-14T17:18:48.167

@reffu Yeah, I tried to create one in Forth when the challenge was first posted. I didn't succeed. – mbomb007 – 2018-03-01T21:09:19.670

Can we assume that the program will not be given input? I have an answer, but only errors when no input is given, but works otherwise. – caird coinheringaahing – 2018-03-25T13:16:57.287

As long as you note that in your answer, I think it’s fair to assume no input. – nneonneo – 2018-03-25T17:56:39.677

2I'm pretty sure it's completely impossible in non-literate Haskell, thanks to nested comments. – dfeuer – 2019-03-19T01:50:46.317

1@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. – Ørjan Johansen – 2019-04-04T01:32:16.053

This challenge rules out Turing Machine Language. – ouflak – 2019-09-12T13:50:43.877

Answers

58

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!

Dennis

Posted 2017-07-20T04:35:53.570

Reputation: 196 637

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.

– user41805 – 2017-07-20T06:10:41.713

2+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." – Zacharý – 2017-07-20T14:46:53.327

1@Cowsquack tfw I forgot about my own language – Skidsdev – 2017-07-21T10:54:14.023

1@Skidsdev tfw I re-forgot about my own language, and forgot about me forgetting about my own language – Skidsdev – 2018-11-19T18:19:16.933

@Zacharý What about 0-byte solutions? – PyRulez – 2018-11-19T23:23:56.133

@PyRulez, then it wouldn't be a language that could do anything. – Zacharý – 2018-11-20T01:06:34.783

@Zacharý I know just the esolang for the job!

– PyRulez – 2018-11-20T01:17:50.637

34

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

user41805

Posted 2017-07-20T04:35:53.570

Reputation: 16 320

Doesn't work - one could have a string literal like "\\u;". – feersum – 2017-07-20T06:57:10.687

@feersum Fixed at the cost of one byte – user41805 – 2017-07-20T07:07:49.623

Does this work for the /* and // comments? – TheLethalCoder – 2017-07-20T08:43:25.150

21@TheLethalCoder: Java preprocesses source code to alter \uXXXX escapes before doing anything else, so yes, this will work even inside comments.za – nneonneo – 2017-07-20T08:58:27.693

4I think this is the shortest Java answer in the history of this site still.. – Magic Octopus Urn – 2018-03-02T18:31:37.320

1

@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. :)

– Kevin Cruijssen – 2018-03-20T16:13:12.263

26

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>

user41805

Posted 2017-07-20T04:35:53.570

Reputation: 16 320

2/* */\u0045 = 3 seems valid JavaScript code. – tsh – 2017-07-20T05:36:31.890

@tsh Fixed at the cost of one byte. – user41805 – 2017-07-20T05:38:30.793

23 */\u;/ is still valid. – tsh – 2017-07-20T05:55:25.110

@tsh Fixed by changing the ; to a ) – user41805 – 2017-07-20T05:58:39.160

It is strange that Node.js accept code 0&&3 */\u)/, but javascript shell reject it. – tsh – 2017-07-20T06:36:15.843

Doesn't work. Add 1||1 to the beginning and / to the end. Evaluates to 1 , and the 1*/\u)/ is never executed, so the invalid regex doesn't come into play. – asgallant – 2017-07-20T14:30:42.197

@asgallant Fixed at the cost of one byte, a semicolon at the beginning of the second line. – user41805 – 2017-07-20T14:42:44.747

3

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 *.)

– ETHproductions – 2017-07-20T15:28:13.477

I believe this solution is also valid for C? All the relevant syntax is identical, although you don't need to guard against regex stuff. (It's probably a polyglot for several curly-brace languages.) – Leushenko – 2017-07-21T18:10:31.687

1

@Leushenko But this doesn't work against #if 0 as seen here: Try it online!

– user41805 – 2017-07-21T18:17:08.820

@ETHproductions Fixed now – user41805 – 2017-07-21T18:26:33.510

@Cowsquack yeah I misunderstood the C tokenization rules. Seems \u doesn't start a universal char name unless there is an actual hex-quad to follow it, so it's just a well-formed punctuator+identifier pair that can be safely escaped (6.4p4).

– Leushenko – 2017-07-21T18:30:23.250

@feersum But alas, there is a leading newline (before the semicolon), so that cannot work. – user41805 – 2017-07-26T09:49:00.870

@Cowsquack. You can save 1 byte by reverting to the old answer. See this issue. According to the ES spec, even if you put the regex into if(0) block (for example) such that it "never come into play", it is still syntax error (v8 engine currently doesn't throw an error because of the bug I posted, which will be fixed soon). You can also check section "Early syntax errors and RegExp errors" section from the latest ES spec.

– None – 2017-07-26T13:24:21.340

@ThePirateBay Which particular old answer are you referring to? – user41805 – 2017-07-26T13:29:25.937

@Cowsquack. To the asnwer */\u). In the comments asgallant said that you can put 1||1*/\u)/ and it will be correct (because regex will never be evaluated). But, it is wrong. In my previous comment I posted documented v8 bug (you can read all comments there and you can read whole ES spec section "Early errors"). The spec says that 1||1*/\u)/ is not a correct code (but v8 engine (which is Chrome and Node.js) doesn't throw error). The v8 issue is documented and will be fixed soon, so you can revert to 6 bytes answer, because it is perfectly valid. – None – 2017-07-26T14:13:37.927

@ThePirateBay Until the bug gets fixed, or until there is an implementation that allows */\u) as a valid string, I will have to stick with this version, as languages in PPCG are defined by their interpreter/implementation. – user41805 – 2017-07-26T14:21:36.443

@Cowsquack. Then you should change your answer's title from JavaScript to JavaScript (v8 engine only). The bug appears only in v8 engine and it is unconsistent with the spec. If you're looking for an interpreter which rejects 1||1*/\u)/ as a valid code, you can test it in Mozilla Firefox, ParseHub, Babel Interpreter, Opera, Safari, and every other browser except Chrome. – None – 2017-07-26T14:33:01.633

4

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`

– iovoid – 2018-02-14T04:23:49.573

26

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.

PhilDenfer

Posted 2017-07-20T04:35:53.570

Reputation: 361

34Also, you just lost the game. I almost downvoted – Stephen – 2017-07-21T13:30:33.877

17

Python, 10 bytes (not cpython)


?"""?'''?

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

Edit 2:

In the comments @EdgyNerd has found this crack taking advantage of a non-ascii encoding declaration! This seems to decode to print(""). I don't know exactly how this was found but I imagine the way to fix this sort of exploit would maybe be to try different combinations of any invalid characters where the ?s are, and find one that doesn't behave well with any encoding.


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.

KSab

Posted 2017-07-20T04:35:53.570

Reputation: 5 984

@isaacg hmm, I actually did think of that but https://repl.it/JaHm/0 didn't work

– KSab – 2017-07-20T05:10:27.863

@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. – KSab – 2017-07-20T05:12:32.077

@isaacg like others said, that code produces errors under the debug menu. – JungHwan Min – 2017-07-20T05:15:35.030

You're right, I don't know how to use TIO. Sorry about that. – isaacg – 2017-07-20T05:17:33.703

I think this is valid, even when we remove the 1st and 3rd question marks?? – officialaimm – 2017-07-20T05:18:39.153

1@officialaimm consider """?'''""" – KSab – 2017-07-20T05:20:56.300

Oh, yes. Silly me!! – officialaimm – 2017-07-20T05:24:24.457

3I 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? – feersum – 2017-07-20T07:54:10.173

@feersum I edited the answer, does your program work on any online interpreters? Even if not I'd be interested in seeing the actual code – KSab – 2017-07-20T17:11:41.453

Unless you stick a second newline in front, people can just comment this out with #\. – user2357112 supports Monica – 2017-07-20T17:42:12.730

@user2357112 see above comments, backslash continuation apparently doesn't work inside comments https://repl.it/JaHm/0

– KSab – 2017-07-20T17:44:34.790

Apparently comments always end at the end of the physical line, so you can't line-continue them. – user2357112 supports Monica – 2017-07-20T17:47:43.543

1

Python 3 on Windows 7 happens to be exactly where my crack is working. Pastebin of base64-encoded program

– feersum – 2017-07-20T18:19:49.653

1I can crack this one as well. Simply put a 0x1A character at the beginning of the file, and all the rest of it is ignored (this actually works for Python 3 as well). – feersum – 2017-07-24T02:55:43.500

Corrected crack for Pythons 2 and 3 on Linux. I realized I forgot to insert the leading newline. – feersum – 2017-07-25T07:51:57.620

2

I know this is really old, but after working with some people over in the Python Discord, we found this crack, although I don't know if changing the encoding can be considered cheating

– EdgyNerd – 2019-10-05T18:40:06.343

@feersum Could you explain how your crack work? What does the first line # ␀␄␀␄ of your script do?… – Rémi Peyre – 2019-11-25T10:21:39.390

16

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

Anders Kaseorg

Posted 2017-07-20T04:35:53.570

Reputation: 29 242

5Cracked again. – feersum – 2017-07-20T07:18:49.907

3Also since C++11 raw strings seem to work, a solution is impossible with gcc. – feersum – 2017-07-20T07:22:54.113

1@feersum Huh, TIL that GCC accepts those in C code. I could specify -std=c99, but let’s try switching to clang. – Anders Kaseorg – 2017-07-20T07:28:35.710

3I'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. – nneonneo – 2017-07-20T17:29:32.583

Can they close raw string again? @feersum – l4m2 – 2018-11-01T17:56:44.833

2@l4m2 I can't parse your question (who is they, and what do you mean by again?), but note that a C++ raw string literal supports a custom delimeter: R"foobar(...)foobar", and only a right paren followed by the matching delimeter and a quote will close it. – Anders Kaseorg – 2018-11-02T00:41:46.937

13

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.

xaambru

Posted 2017-07-20T04:35:53.570

Reputation: 131

2Welcome to the site! :) – James – 2017-07-21T16:57:55.473

12

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.

isaacg

Posted 2017-07-20T04:35:53.570

Reputation: 39 268

9

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

Peter Cordes

Posted 2017-07-20T04:35:53.570

Reputation: 2 810

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. – Cody Gray – 2017-07-21T06:02:45.103

@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. – Peter Cordes – 2017-07-21T07:58:17.363

@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) – Peter Cordes – 2017-07-21T08:02:39.637

Don't quite satisfy. Your solution may be just in .data. (though it makes it impossible) – l4m2 – 2018-11-01T02:29:33.943

@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. – Peter Cordes – 2018-11-01T02:38:24.743

7

APL and MATL and Fortran, 3 bytes


'

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

Adám

Posted 2017-07-20T04:35:53.570

Reputation: 37 779

This applies to MATL too – Luis Mendo – 2017-07-20T07:39:13.183

I think this would work in Fortran too. – Steadybox – 2017-07-21T02:27:05.987

Also J I believe – Jonah – 2019-11-16T04:45:02.030

1

@Jonah Nope.

– Adám – 2019-11-16T19:16:13.427

Ah. Would \n)\n'\n work for J? – Jonah – 2019-11-16T19:38:18.660

@Jonah It seems so. – Adám – 2019-11-16T19:41:15.097

7

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.

TheLethalCoder

Posted 2017-07-20T04:35:53.570

Reputation: 6 930

1Weird that you decided to include T4 templates in your code. Isn't T4 considered a separate language? – Arturo Torres Sánchez – 2017-07-20T21:07:18.153

1@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. – TheLethalCoder – 2017-07-21T07:59:16.310

7

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").

Mark

Posted 2017-07-20T04:35:53.570

Reputation: 2 099

If I append =0 then this just becomes an assignment statement... – Neil – 2017-07-21T09:54:26.243

1@Neil, that would be a valid immediate-mode command, but not a valid program. – Mark – 2017-07-21T10:05:04.383

6

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.

Unrelated String

Posted 2017-07-20T04:35:53.570

Reputation: 5 300

There might be a few other compile-time errors which can fire before ICL993I I GAVE UP LONG AGO. – Unrelated String – 2019-04-04T01:47:17.810

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! – Unrelated String – 2019-04-08T01:19:05.917

5

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.

Ørjan Johansen

Posted 2017-07-20T04:35:53.570

Reputation: 6 914

5

Shakespeare Programming Language, 2 bytes

.:

Explanation: If this string is in the title of the play, the . ends it and the : is not a valid character name. Similar problems occur in an act and scene name. No character can speak a line beginning with :, and the . will end a Recall statement, which can otherwise create a comment.

Hello Goodbye

Posted 2017-07-20T04:35:53.570

Reputation: 442

4

Free Pascal, 18 bytes


*)}{$else}{$else}

First close all possible comments, then handle conditional compile.

Please comment here if I forgot something.

tsh

Posted 2017-07-20T04:35:53.570

Reputation: 13 072

3@user902383 Does your example contain the leading newline of his snippet? – Brian J – 2017-07-20T18:44:25.010

@BrianJ nope, i thought it was just formatting issue, my bad – user902383 – 2017-07-21T09:23:39.950

I don't think it's possible in Free Pascal. Just put them after begin end.. – jimmy23013 – 2017-07-24T15:28:18.033

@jimmy23013 but it seems that codes after the end. become valid is allowed by the question. – tsh – 2017-07-25T01:13:46.590

4

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!

Riley

Posted 2017-07-20T04:35:53.570

Reputation: 11 345

How do you do comments in Brain-Flak? I don't know of any way to do those. – Erik the Outgolfer – 2017-07-20T18:26:45.187

@EriktheOutgolfer # TIO

– Riley – 2017-07-20T18:27:26.840

Huh undocumented behavior. – Erik the Outgolfer – 2017-07-20T18:29:04.163

@EriktheOutgolfer I always assumed they were documented somewhere. I'll look at adding them. – Riley – 2017-07-20T18:34:20.547

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 (()){()}. – Post Rock Garf Hunter – 2017-08-07T23:26:40.710

3

CJam, 7 bytes

"e#"
:"

Try it online!

Erik the Outgolfer

Posted 2017-07-20T04:35:53.570

Reputation: 38 134

3

AWK, 4 bytes



/

Try it online!

Since AWK doesn't have a method to do multi-line comments, need 2 newlines before and 1 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.

With previous crack

Robert Benson

Posted 2017-07-20T04:35:53.570

Reputation: 1 339

1I enjoyed this. – stephanmg – 2019-11-15T15:48:33.483

Thanks. I enjoyed coming up with it :) – Robert Benson – 2019-11-18T15:54:35.953

3

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


_

Taylor Scott

Posted 2017-07-20T04:35:53.570

Reputation: 6 709

You do depend on your pattern starting on a new line... so, add a newline. – Deduplicator – 2017-07-20T19:18:03.250

@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 – Taylor Scott – 2017-07-20T19:48:24.163

What if it is embedded like this: myfunction( \n_ )? – Deduplicator – 2017-07-20T20:00:33.293

@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 – Taylor Scott – 2017-07-20T21:00:25.327

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. – Deduplicator – 2017-07-20T21:34:08.947

@Deduplicator I am not sue what you mean. There is no way to escape a newline (or any character) in VBA so it should not be necessary to add a newline before, and appending literally anything to the end of this VBA code will cause the illegal character error - eg \n_"test", \n_12321 , \n_#if, \n__ and \n_\n will all result in the the error as will all of the above with any prepended code – Taylor Scott – 2017-07-21T12:35:18.313

so, myfunction(_ (newline) _ (newline) ) would be an error? – Deduplicator – 2017-07-21T12:40:27.770

Yes, that would cause an error. example test code function myfunction( _\n_ (slightly changed from your example as you cannot have a _ directly following a ( or any other character - I believe that this is why this works in VBA) - of note is that function myfunction( _\n _... would be valid (note the added space) – Taylor Scott – 2017-07-21T12:46:48.343

In VBA, every string is illegal and results in an error... – Mega Man – 2017-07-23T08:19:36.937

@MegaMan I am not sure what you mean ... I'll just take that as a joke – Taylor Scott – 2017-07-23T15:44:23.450

3

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.

12Me21

Posted 2017-07-20T04:35:53.570

Reputation: 6 110

oh, for some reason when I edited the post it was duplicated... – 12Me21 – 2018-03-01T20:11:47.337

2

Fortran, 14 bytes


end program
e

No multiline comments or preprocessor directives in Fortran.

Steadybox

Posted 2017-07-20T04:35:53.570

Reputation: 15 798

1Is there a good way to test this online? Also, which version/compiler of Fortran? – Robert Benson – 2017-07-23T15:21:02.030

2

TI-Basic (83+/84+/SE, 24500 bytes)

A

(24500 times)

TI(-83+/84+/SE)-Basic does syntax checking only on statements that it reaches, so even 5000 End statements in a row can be skipped with a Return. This, in contrast, cannot fit into the RAM of a TI-83+/84+/SE, so no program can contain this string. Being a bit conservative with the character count here.

The original TI-83 has 27000 bytes of RAM, so you'll need 27500 As in that case.

TI-Basic (89/Ti/92+/V200, 3 bytes)

"

Newline, quote, newline. The newline closes any comments (and disallows embedding the illegal character in a string, since AFAIK multiline string constants are not allowed), the other newline disallows closing the string, and the quote gives a syntax error.

You can get to 2 bytes with

±

without the newline, but I'm not sure whether this counts because ± is valid only in string constants.

bb94

Posted 2017-07-20T04:35:53.570

Reputation: 1 831

Done, thanks :) – bb94 – 2019-04-05T07:52:02.570

2

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

Shieru Asakoto

Posted 2017-07-20T04:35:53.570

Reputation: 4 445

"Template literal... multiplied by a regex." Only in JavaScript would that be a legal expression. – Andrew Ray – 2019-11-26T20:52:29.233

2

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

Skidsdev

Posted 2017-07-20T04:35:53.570

Reputation: 9 656

What about (()"""), wouldn't that be a no-op? – ბიმო – 2018-11-21T23:46:21.510

@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 – Skidsdev – 2018-11-22T01:20:39.030

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.

– ბიმო – 2018-11-22T17:13:38.137

@BMO good point, can be fixed by inserting a newline inbetween ) and """ – Skidsdev – 2018-11-23T18:21:09.010

2

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.

Veskah

Posted 2017-07-20T04:35:53.570

Reputation: 3 580

Smart! What about this '"#>\n@{= : protectors + @{= – mazzy – 2018-11-19T22:16:09.253

1Or protectors + @= – mazzy – 2018-11-19T22:26:13.410

Cool! It may also be worth looking in the direction LFCR (reverse of CRLF), EOF and other control chars. – mazzy – 2018-11-20T08:01:30.363

Embedding in $( ') makes it legal $( #> '@ "@" @= ') – GreyOrGray – 2019-01-25T20:37:27.670

1@IsItGreyOrGray AAAAAAAAAAAw heck. – Veskah – 2019-01-25T21:12:14.340

2It 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. :) – GreyOrGray – 2019-01-25T21:38:27.030

Sorry... Embed between write-host ' and '@ – GreyOrGray – 2019-01-25T22:57:48.963

1@IsItGreyOrGray Sonofagun. Now featuring semi-colon armor? – Veskah – 2019-01-25T23:06:20.210

1Nice! I've got nothing. Everything I've tried has failed. – GreyOrGray – 2019-01-28T14:31:26.830

2

Ruby, 58 23 27 bytes AND proof of impossibility at bottom

This snippet is valid in any Ruby version prior to Ruby 2.3 (when heredocs were added):


=end
)}end/;[}'"\//;[}#{]}

Old version (invalid):


=end
)}end/;kill(Process.pid,-9)'"\//;kill Process.pid,-9

This cannot be used anywhere in a Ruby program except after __END__.

Proof of impossibility

This solution is impossible in any Ruby version after and including Ruby 2.3.

Any Ruby solution can be inserted into this snippet and function as a valid program:

<<'string'

# Insert code here

string

With this particular snippet, you can add (note leading newline)


string

to your solution in order to invalidate the program. However, changing the "name" of the heredoc will again invalidate your solution. Heredocs can have infinite placeholders, meaning a solution accounting for all of them would be infinitely long. Thus an answer in Ruby 2.3+ is impossible.

Thanks to histocrat for pointing this out.

CG One Handed

Posted 2017-07-20T04:35:53.570

Reputation: 133

Invalid, cannot appear. Needing a kill command means it can be put in a program that still runs – ASCII-only – 2019-01-24T06:14:57.917

Can kill be redefined to not work properly? For example define kill to do nothing with the input? – Post Rock Garf Hunter – 2019-01-24T13:40:55.417

@ASCII-only--yes, that's true. I thought that the question was to raise an error, not disallow a valid program. Sorry about that. Will remove. – CG One Handed – 2019-01-25T00:05:36.370

1

Not quite--If you put single quotes around the heredoc terminator like so, it won't interpolate with #{. I don't think this is solvable in Ruby due to this feature.

– histocrat – 2019-09-06T17:11:48.760

@histocrat I was wondering how long it would take for someone to notice! Congrats, I guess. – CG One Handed – 2019-09-11T00:04:11.033

Invalid answers need to be deleted. – pppery – 2019-09-11T01:40:27.717

2Proof of impossibility is still a valid answer. Though I think the proof might need to be a little more strict – Jo King – 2019-09-11T01:43:08.820

Updated solution to reflect impossibility in Ruby 2.3+. @JoKing The proof depends on allowing infinitely long answers or not. I'm too lazy to check atm whether infinitely long answers are allowed; but if they are, then I can add one to this answer – CG One Handed – 2019-09-12T03:28:36.063

2

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.

Draco18s no longer trusts SE

Posted 2017-07-20T04:35:53.570

Reputation: 3 053

2

Go, 6 bytes


*/```

Try to crack it online!

The grave accent (`) marks a raw string literal, inside which all characters except `, including newlines and backslashes, are interpreted literally as part of the string. Three `'s in a row are the core: adjacent string literals are invalid and ` always closes a ` string, so there's no way to make sense of them. I had to use 3 more bytes for anti-circumvention, a newline so we can't be inside a single-line comment or a normal quoted string, and a */ so we can't be inside a multi-line comment.

Purple P

Posted 2017-07-20T04:35:53.570

Reputation: 919

1

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!

Rohan Jhunjhunwala

Posted 2017-07-20T04:35:53.570

Reputation: 2 569

Why doesn't ax+ error out? – Erik the Outgolfer – 2017-07-20T18:40:53.443

undefined compiler behavior @EriktheOutgolfer – Rohan Jhunjhunwala – 2017-07-20T19:27:39.953

1

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) try to start a invalid string.

Try it online!

iovoid

Posted 2017-07-20T04:35:53.570

Reputation: 411

Appending a slash at the end cracks ;) – Shieru Asakoto – 2018-11-01T02:05:56.740

The ES5 answer used a ) after the \u, maybe that would work here? – Neil – 2018-11-01T09:12:54.007

1

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.


*/`"

nelsontruran

Posted 2017-07-20T04:35:53.570

Reputation: 241

1

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.

W. K.

Posted 2017-07-20T04:35:53.570

Reputation: 51

1

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

– ბიმო – 2018-11-22T17:27:23.827

There's a leading newline. – W. K. – 2018-11-22T21:15:42.947

1

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

ბიმო

Posted 2017-07-20T04:35:53.570

Reputation: 15 345

An inference failure would have been fun, but this is probably shorter than that would be anyhow. – Unrelated String – 2019-04-04T02:28:17.023

1

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.

Deadcode

Posted 2017-07-20T04:35:53.570

Reputation: 3 022

1

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

Deadcode

Posted 2017-07-20T04:35:53.570

Reputation: 3 022

1

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.

user85052

Posted 2017-07-20T04:35:53.570

Reputation:

3 bytes using strings – Lyxal – 2019-11-26T20:51:24.080

But this is valid.

– None – 2019-11-27T04:06:03.447

0

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.

Business Cat

Posted 2017-07-20T04:35:53.570

Reputation: 8 927

0

Ly, 6 bytes


\""{)

(note the leading newline)

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.

LyricLy

Posted 2017-07-20T04:35:53.570

Reputation: 3 313

0

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.

Conor O'Brien

Posted 2017-07-20T04:35:53.570

Reputation: 36 228

0

Ink, 5 bytes


*/{}

Leading newline ends single-line comments.
*/ 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.

Sara J

Posted 2017-07-20T04:35:53.570

Reputation: 2 576

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!

ouflak

Posted 2017-07-20T04:35:53.570

Reputation: 925

0

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!

user85052

Posted 2017-07-20T04:35:53.570

Reputation:

0

Unreadable, 2 bytes

''

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): '.

Robin Ryder

Posted 2017-07-20T04:35:53.570

Reputation: 6 625

0

Haskell, 5 bytes

-}
''

By itself, this produces parse error on input '}', because the curly brace isn't closing anything.

If it's preceded by {-, you get parse error (possibly incorrect indentation or mismatched brackets.

If you wrap that in a block do:

main=do{{-
-}
''}

you get parse error on input '}' again, because the parser sees an incomplete character literal.

You cannot wrap this sequence in a string because newlines in strings must be wrapped in backslashes, which can otherwise only contain other whitespace.

Please note that I am not considering language extensions like Template Haskell.

Andrew Ray

Posted 2017-07-20T04:35:53.570

Reputation: 101

Cracked. Note also that Haskell supports nested block comments, so I can always add more {-s than you have -}s. – Anders Kaseorg – 2020-01-25T13:35:31.153

0

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>

Konrad Borowski

Posted 2017-07-20T04:35:53.570

Reputation: 11 185

cracked. i'm pretty sure this could be fixed with two newlines at the start. edit: nevermind – randomdude999 – 2020-01-13T20:52:33.550