# Transpile ;# into your language

Related to: Make a ;# interpreter and Generate ;# code

## ;# - A Whirlwind Guide

This is a simple language with two commands. Its only data structure is an accumulator, which is initialized to 0.

1. ; Increment the accumulator

2. # Calculate the value of the accumulator modulo 127, and print the corresponding ASCII character. Then, reset the accumulator to 0.

The source code may contain additional characters (printable ASCII + whitespace), but these are treated as comments and have no effect on program execution.

## Challenge

Since most computers do not come with ;# preinstalled, it would be very useful to have a tool that can convert ;# code into a different language. In this challenge, you shall write a program to accomplish this.

## Input

Some ;# source code, taken via argument or STDIN. This source code may contain (comment) characters other than ; or #.

## Output

Code, in the same language as your submission, which, when executed, prints/returns the same string as the original ;# code. This resultant code may output a trailing newline after the target string, if that is more convenient for your language.

## Notes

One thing to look out for is escape sequences, such as code that prints backslashes or prints quote marks. Also look out for ;# code that could contain things that look like keywords or commands in your language.

All programs must terminate (I normally consider this a default, but someone asked about it so I'm stating it here).

## Examples

input: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#
output (python): print(";#")
input: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#
output (element): \'

• My computer came with ;# preinstalled... – programmer5000 May 24 '17 at 20:56
• Does the program have to stop execution? Also, can it print no-ops infinitely after the actual code? – totallyhuman May 24 '17 at 23:50
• Will the program always have at least one # character in it? – FryAmTheEggman May 25 '17 at 0:54
• @totallyhuman I'm gonna say that all programs must eventually halt. – PhiNotPi May 25 '17 at 3:33
• Please could we get a test case where the input contains a character (or characters) that aren't ; or #? – streetster Aug 10 '17 at 20:55

# Python 2, 76 69 bytes

### Code

Input is surrounded by quotes.

for y in input('print').split("#")[:-1]:printchr(y.count(";")%127),


Try it online!

### Explanation

The first part of the output is essentially done by the input, using input('print'). We split the input on hashtags and discard the last element. We print the representation of ord(y%127), where y is the number of occurrences of the semicolon. We append the , at the end of the print to make sure that this does not print a newline.

This would give the following Python code for the Hello, World!-program:

print'H' 'e' 'l' 'l' 'o' ',' ' ' 'W' 'o' 'r' 'l' 'd' '!'


Which can be tried online.

# brainfuck, 126 bytes

+++[->+++++<]>[->++++>+++<<],[+<++++++[-<++++>>------<]>[<]<<[>>>>>[--<--.++>]<+.-<.<<<<]>[->>-<<]>>[[-]<]>[>>++++[-->]<[<]],]


Try it online!

The output program will fail in the TIO implementation if the ;# output exceeds 65536 characters. I also made a 130-byte version which outputs [+] instead of <, avoiding this problem:

++[------>++>+<<]>+++++<,[+<++++++[-<++++>>------<]>[<]<<[>>>>>[--<.>]<+++.---<.>.<++.--<<<<]>[->>-<<]>>[[-]<]>[>>++++[-->]<[<]],]


### Explanation

+++[->+++++<]>[->++++>+++<<]        initialize tape with 60 and 45
,[                                  for each input byte:
+<++++++[-<++++>>------<]         subtract 35 (#) from byte
>[<]<<[                           if byte was #
>>>>>[--<--.++>]           output + (43) a number of times equal to accumulator
<+.-<.<<<<                 output . (46) and < (60)
]
>[->>-<<]>>                       subtract 24 from what's left of byte
[[-]<]                            check difference and clear if nonzero
>[                                if byte was originally 59 (;)
>>++++[-->]<[<]                  add 4 to accumulator cell, then subtract 2 if nonzero. Since BF cells are mod 256, this creates an accumulator mod 127.
]
,]


# Whitespace, 291 bytes

NSSTTNNSTNNSTNNSTTNNSSTSNSSNSNSTNTSTTTSSSTSSSTTNTSSTSNSNTSSSSNSSSTTSSSNTSSTNTSSSTNNSNTSNNSSSSSNSNNNSTSSNNSTSTNNSTSTNNSTSNNSTTNNSTSNNSTNNSTSTNNSTTNNSTNNSTNNSNTTNNSSSSTNNSTSSNNSTSNNSTTNNSTSNNSTSSNNSNTSNNSSTNSSSTSTSNTNSSNTNNSSSSNNSTNNSTNNSSNSSSTSSSSSNTNSSNTNNSSSTNNSTSNNSTSNNSSSNSSSTSSTNTNSSNTN


Replace S by space, T by tab and N by a newline.

Generating whitespace in whitespace is not the most efficient thing in the world. Generating any kind of dynamic code requires significant bit-twiddling which, in a language without bitwise operations, would cause the code size to explode. Therefore, this program does not attempt to do something smart, instead opting for just translating the source program one to one. It disassembles to the following:

early:
call S
call S
call N
start:
push  0
dup
ichr
get
push  35
sub
dup
jz    hash
push  24
sub
jz    semi
jmp   start
hash:
pop
call SSS
call TTT
call TTT
call T
call N
call T
call S
call TTT
call N
call S
call S
jmp   early
semi:
call SSS
call T
call N
call T
call SSS
jmp   start
N:
push 10
pchr
ret
SSS:
call S
call S
S:
push 32
pchr
ret
TTT:
call T
call T
T:
push 9
pchr
ret


The code generated by the program looks like:

push  0
push  1
push  1
push  1
push  1
push  1
push  1
push  1
push  1
push  1
push  1
push  1
push  127
mod
pchr
push  0
push  1
...

• Doesn't work for me. In the original whitespace interpreter written in Haskell, the sign bit may not be omitted from a number, so "SSN" is not a valid way to push zero. – aschepler Aug 10 '17 at 22:29
• Due to the vagueness of the specification of whitespace and the differences between the original reference interpreter and the actual specification, it is hard to judge what was to be the intended behaviour. As far as I remember several example programs listed on the original site actually did require the signless behaviour, and furthermore many other implementations do have it. I ran into these issues several times while building my own ws JIT compiler, and in the end I decided to stick with it for compatability with other implementations – CensoredUsername Aug 10 '17 at 23:10

# V, 1920 28 bytes

Bugfix, broke if there was no # at the end

Bugfix, implemented mod 127

Í;û127}
éiA0Í#/0
ò/;
x


Try it online!

Try Generated Code

Explanation:

Í;û127}                            ' Delete runs of 127 ;s (mod 127)
éi                                 ' Insert an i in front of input
A<C-v><esc>0<esc>                ' Append <esc>0 to input
Í#/<C-v><C-v>0  ' Replace all # with <C-v>0
ò                                  ' Recursively
/;                                ' Go to the next ;
<C-a>                              ' Increment the next number come across


In V, in insert mode, any ASCII character can be inserted by code by using <C-v><Code>. The V code replaces all # with <C-v>0, where the zero is a pseudo-accumulator per #. Each # resets the accumulator to 0 so having one per works out fine. Then the code does an increment for each semicolon found, which just increments the next number it finds, which would be the next accumulator. The 0 is appended to the end so that the instruction doesn't fail for ;s without a following #.

Hexdump:

00000000: e969 4116 1b30 1bcd 232f 1616 300a f22f  .iA..0..#/..0../
00000010: 3b0a 7801                                ;.x.


## JavaScript (ES6), 101 bytes

s=>_=>'${s.replace(/[^#;]/g,)}'.replace(/;*(#|$)/g,(l,c)=>c&&String.fromCharCode(~-l.length%127))


Given an input string, deletes all the unnecessary characters, then returns the source of the following function:

_=>'...'.replace(/;*(#|$)/g,(l,c)=>c&&String.fromCharCode(~-l.length%127))  Where ... represents the cleaned ;# source. # 05AB1E, 20 19 18 16 bytes -1 thanks to Adnan -2 thanks to carusocomputing -2 thanks to Kevin Cruijssen '#¡¨vy';¢ƵQ%„çJJ  Try it online! (includes output of executed 05AB1E code) '#¡ # Split on # ¨ # remove the last element vy # For each... ';¢ # count the number of ;s ƵQ% # Mod by 127 „çJ # Push çJ („çJ should work, but it doesn't for some reason) J # Join stack and output implicitly  • ';¢ can be g, žy pushes 128, may work somehow and why not just spell the full word and surround it by quotes? – Magic Octopus Urn May 25 '17 at 21:54 • I need to use ';¢ incase there are characters other than ;. žy< is the same as 127. Printing the word surrounded by quotes will break if one of the characters is a quote. – Riley May 25 '17 at 22:12 • @carusocomputing I forgot to ping you... – Riley May 25 '17 at 22:21 • @carusocomputing and Riley: ƵQ is a compressed version of 127. – Adnan May 25 '17 at 22:38 • @Adnan why/how? – Magic Octopus Urn Jun 1 '17 at 16:36 # Python 2, 75 bytes lambda s:"print"+''.join(chr(x.count(';')%127)for x in s.split('#')[:-1])  Try it online! (includes output from executing the transpiled Python code) Thanks to ovs for many many bytes! ## Explanation This program transpiles the #; code by splitting on #s (s.split('#')[:-1]), counting the number of semicolons in each chunk mod 127 (x.count(';')%127for x in ...), and converting that into the respective ASCII character (chr(...)). That list is then concatenated (''.join(...)), converted into a Python representation of the string (the backticks) and inserted into a skeleton Python program for printing strings ("print"+...). # Jelly, 25 24 16 bytes ṣ”#Ṗċ€”;%127;€”Ọ  A full program printing equivalent Jelly code (as a monadic link it returns a list of lists of mixed types). The first example is at Try it online! which yields this program. ### How? Counts up the ;s in each run between #s takes each modulo 127 and appends a cast to ordinal instruction, the monadic Ọ atom, after each. Jelly implicitly pipes each value to STDOUT as it runs through a program like that i.e. 72Ọ101Ọ108Ọ108Ọ111Ọ44Ọ32Ọ119Ọ111Ọ114Ọ108Ọ100Ọ33Ọ would print Hello, world!. ṣ”#Ṗċ€”;%127;€”Ọ - Main link: list of characters ”# - literal '#' ṣ - split the result at #s Ṗ - pop (remove the last result, list of trailing non-# characters) ”; - literal ';' ċ€ - count for €ach %127 - modulo 127 (vectorises) ”Ọ - literal 'Ọ' (Jelly's cast to ordinal monadic atom) ;€ - concatenate for €ach - making a list of lists like [[72,'Ọ],[101,'Ọ'],...] - implicit print (this smashes, printing something like: 72Ọ101Ọ...)  A note regarding input: Jelly takes string input in Python format. The empty program could be input as "", and the hash-only programs as "#", "##", etc. Other manipulation may be required for input containing backslashes and quotes. # Cubically, 138 137 bytes +1/1+54@6:5+1/1+5@6/1+52@6:4/1+5@6:1/1+54@6:4/1+5@6:5+2/1+4@6(~-61/1=7&6+5/1+51=7?6{+3/1+5@6}:5+3/1+3=7?6{+52@6:5+1@6-1@6+1@6:5+2/1+4@6})  Try it online! Note: You may need to replace &6 with ?6& for it to work on TIO. &6 is in the language spec, though. ### How it works +1/1+54@6 Output 'R' :5+1/1+5@6 Output '3' /1+52@6 Output 'D' :4/1+5@6 Output '1' :1/1+54@6 Output 'R' :4/1+5@6 Output '1' :5+2/1+4@6 Output '+' ( Loop indefinitely ~ Get next character -61/1=7&6 If input is -1 (EOF), exit program +5/1+51=7?6{ If input is ; +3/1+5@6 Output '0' } End if :5+3/1+3=7?6{ If input is '#' +52@6 Output '@' :5+1@6 Output '6' -1@6 Output '-' +1@6 Output '6' :5+2/1+4@6 Output '+' } End if ) End loop  Output program: R3D1R1 Set top face to 1 +00... Add top face to notepad, aka increment notepad @6 Output notepad as character -6 Set notepad to 0 ...  • Save a lot of bytes removing the arguments from @6, %6 and -6. Commands that previously didn't do anything when called implicitly now use the notepad. So @ is the same as @6, % is the same as %6, etc. – MD XF Oct 8 '17 at 21:53 # C, 98969998 97 bytes +3 bytes because I forgot C isn't interpreted :( c,a;f(){printf("f(){puts(\"");for(;~c;c=getchar())c==59?a++:c==35?a=!printf(&a):a;puts("\");}");}  Running with: echo ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#" | ./a.out  Will print: f(){puts("Hello, World!");}  • ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;# produces f(){puts(""");}, which is invalid. The challenge specifically calls out "One thing to look out for is escape sequences, such as code that prints backslashes or prints quote marks." – hvd May 25 '17 at 7:47 • @hvd Fixing.... – MD XF May 25 '17 at 17:25 # Jelly, 26 bytes ”‘x f”;L%127Ç;“Ọø” ṣ”#Ç€ṙ-  Try it online! And try that Jelly code here! ṣ”#Ç€ṙ- Main link, input is a string of ";;;;;;#lala;;;;;;;;;#" ṣ”# Split input on char # Ç€ Call helper link 1 for each segment ṙ- Rotate returns 1 to the right (SPLIT introduces an empty element which is moved up front) f”;L%127Ç;“Ọø” Helper link 1, determines the number of increments f”; Throw out all but semicolons L%127 Take the count mod 127 Ç Call helper 2 ;“Ọø” Add a Jelly link that prints characters and splits print statements ”‘x Helper 2, receives the count of ;'s ”‘ Return the character ‘ (Jelly's increment command x Once for each ; in the input  The Jelly output becomes code like Ọø‘‘‘‘‘‘‘‘‘‘‘‘‘Ọø‘‘‘‘‘‘‘‘‘‘Ọø, which prints chr(13)+chr(10) • Weird example to use (printing only white space) that confused me. – Jonathan Allan May 24 '17 at 21:35 • @JonathanAllan Added examples with links to TIO. – steenbergh May 24 '17 at 21:40 # PHP, 72 bytes for(;~$c=$argn[$i++];)echo[Z=>'$n++;',B=>'echo~$n=~chr($n%127);'][a^$c];


# ><>, 10681 77 bytes

This is my first golf in ><> (fish)! A pretty interesting language I have to say. A lot of fun!

0n01.
>i:1+?!v:";"=?v"#"=?v
^ ;o";"<   .37<
^oo"1+"
^oooooooo'"~"1+%o0' <

• Welcome to the pond ! You can shorten i:1+?! into i:0(?, and I also feel like you could save a few bytes if you constructed the result on the stack and waited for the end of the input to output it. I mean, that's a lot of os ;) – Aaron Jun 2 '17 at 9:51

# C# 169 Bytes

Golfed:

class P{static int Main(string[] args){var r="Console.Write(";foreach(var y in args[0].Split('#')){r+=(char)(-1+y.Split(';').Length%127);}System.Console.Write(r+");");}}


class P
{
static int Main(string[] args)
{
var r="Console.Write(\"";
foreach (var y in args[0].Split('#'))
{
r +=(char)(-1+y.Split(';').Length% 127);
}
System.Console.Write(r+"\");");
}
}


';'!(x:a)=x+1:a;'#'!a=0:a;_!a=a;h s="main=putStr"++(show$""++(toEnum.(mod127)<$>init(foldr(!)[0]s)))


Try it online!

Ungolfed

step ';' (x:acc) = x+1:acc
step '#' acc = 0:acc
step _ acc = acc;

semicolonHash s = toEnum . (mod 127) <$> init (foldr step [0] s) toHaskell s = "main = putStr " ++ (show$ "" ++ semicolonHash s)


# Brachylog, 33 bytes

{";"∧"+₁"|"#"∧"%₁₂₇g~ạw0"}ˢ;"0"↔c


Try it online!

Feeling a bit too tired to explain this at the moment, if anyone sees this and wonders how it works drop a comment to remind me.

# MathGolf, 17 bytes

⌡(¶{gÉ'8=£♣(%$''\  Try it online! ## Explanation ⌡ decrement twice ( decrement this transforms ";;;#;;#" -> "888 88 " ¶ split string on spaces { foreach... gÉ filter using next 3 characters '8 push single character "8" = pop(a, b), push(a==b) this filters out all non-";" £ length of array/string with pop ♣ push 128 ( decrement % modulo$         pop(a), push ord(a) or char(a) (gets character with code)
''       push single character "'"
\      swap top elements


Since any character can be put on the stack (and thus the output) using '<char>, this will output a sequence of such code blocks.

• Forgot how to create a chat.. Anyway,   (discard everything except for the top of the stack) is currently bugged. It gives a Python FileNotFoundError. – Kevin Cruijssen Mar 28 '19 at 8:49
• @KevinCruijssen Check the README! I switched that character in the code page, to avoid having two space characters. The new character is Þ. – maxb Mar 28 '19 at 9:26
• Yeah, @JoKing indeed said it was changed to Þ. (The docs I use still state the old value however.) – Kevin Cruijssen Mar 28 '19 at 9:38
• @KevinCruijssen Oh, that doc needs to be updated, thanks for the reminder! I'll try to write a script to keep them both updated. I'd suggest using this one until I've gotten that in place. – maxb Mar 28 '19 at 13:06

# MATL, 32 28 bytes

35lF4$Yb"@g59=z]xv127\!&D99h  Try it online! Completely different approach based on strsplit rather than an automaton-type program.  Yb % strsplit 4$   %  with 4 inputs, namely:
35       %   Split on '#'
lF     %   Do not (F) collapse delimiters (l).
%   And of course the implicit program input.

"@g    ] % Loop over strings, convert each to a normal char array
59=z  % How many equal to 59 ';'?

xv!127\  % Delete last element, concatenate and flip to horizontal, mod 127
&D       % Convert to MATL representation
99h    % Append a 'c' to output ASCII.


# Actually, 25 bytes

'#@s⌠';@c7╙D@%⌡MdX$"♂cΣ"o  Try it online! (includes output from executing the transpiled Actually code) Explanation: '#@s⌠';@c7╙D@%⌡MdX$"♂cΣ"o
'#@s                       split on "#"
⌠';@c7╙D@%⌡M           for each chunk:
';@c                    count ";"s
7╙D@%               mod by 127 (2**7-1)
$stringify "♂cΣ"o append "♂cΣ": ♂c convert each value to an ASCII character Σ concatenate  # shortC, 48 bytes c,a;AR"AP\"");O;~c;c=G)c==59?a++:c==35?a=!R&a):a  • Can you add the expanded form? – CalculatorFeline May 25 '17 at 23:57 • @CalculatorFeline already done. – MD XF May 25 '17 at 23:58 # Fourier, 32 bytes $(I~S{59}{^}S{35}{%127a0}&i)


Try it on FourIDE!

This was quite an easy challenge since Fourier is basically a superset of ;#:

;# command > Fourier equivalent
; > ^ (Increment the accumulator)
# > %127a0 (Modulo accumulator by 127, output corresponding code point and set accumulator to zero)


## CJam, 14 bytes

q'#/);';fe=:c


Explanation:

q               e# Read input
'#/            e# Split on '#'
);          e# Delete last element
';fe=     e# Count occurrences of ';' in each
:c   e# Convert each to character (code point)
  e# Escape


# APL, 31 bytes

{⍕'⎕UCS',⌽127|+/¨';'=⍵⊂⍨'#'=⍵}⌽


Output:

      ({⍕'⎕UCS',⌽127|+/¨';'=⍵⊂⍨'#'=⍵}⌽) ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#'
⎕UCS 59 35
⍝ evaluate the output
⍎({⍕'⎕UCS',⌽127|+/¨';'=⍵⊂⍨'#'=⍵}⌽) ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#'
;#


Explanation:

• ⌽: reverse the input
• {...}: pass it to this function:
• ⍵⊂⍨'#'=⍵: partition at each # in the string (from the beginning, which is why it had to be reversed first)
• +/¨';'=: count the ;s in each partition
• 127|: modulo 127
• ⌽: reverse it again
• '⎕UCS',: prepend the string ⎕UCS, which is the Unicode function.
• ⍕: string representation
• You can remove the ⍕ as the actual output to STDOUT is the same. – Adám May 25 '17 at 12:13

# Ruby, 47+1=48 bytes

$_=gsub(/.*?#/){"$><<#{$&.count(?;)%127}.chr;"}  +1 byte for -p. Try it online! -30 bytes thanks to @manatwork! • Unfortunately this not plays nice with the “This source code may contain (comment) characters other than ; or #.” part of requirement. – manatwork May 25 '17 at 9:38 • @manatwork Fixed, will make golfier later. – Pavel May 25 '17 at 14:32 • Was enough to change the regular expression /;+#//.*?#/ and the code block s.length-1s.count(?;). BTW, your math is also wrong, as % has higher priority than -, so should be (s.length-1)%127. And in .gsub's code block you can access the captured groups with $&, $1, … so the |s| code block parameter usually is not feasible. And the string interpolation stringifies: {"$><<#{$&.count(?;)%127}.chr;"}. Try it online! – manatwork May 25 '17 at 14:48 • @manatwork thank you so much! I think your comment has doubled my ruby knowledge. – Pavel May 25 '17 at 16:16 • It's late, but the code challenge itself was bumped recently by a modified answer so whatever. gsub modifies $_ directly, which means that you don't need to re-assign it. HOWEVER, you have issues if you have comment characters after your last #... see here – Value Ink Aug 15 '17 at 21:10

# Pyth, 2523 24 bytes

j\\+"jk["mC%/d\;127Pcw\#


+1 bytes thanks to @FryAmTheEggman

Try it!

handles characters that have to be escaped by only using 1-char-strings.

Sample outputs:

jk[\"

jk[\H\e\l\l\o\,\ \W\o\r\l\d\!


Uses my ;# interpreter.

• This doesn't work if there are no # in the input, as it will print 0. You can fix this with jk instead of s. – FryAmTheEggman May 25 '17 at 0:55

# C, 150 bytes

#include<stdio.h>
c;n=0;main(){puts("#include<stdio.h>\nmain(){");while(~(c=getchar()))c-35?c-59?:n++:(printf("putchar(%d);",n%127)&(n=0));puts("}");}


Expanded:

#include<stdio.h>
c;
n=0;
main(){
puts("#include<stdio.h>\nmain(){");
while( ~(
c=getchar()
))
c-35?
c-59?
:
n++
:
( printf("putchar(%d);",n%127)
&(n=0))
;
puts("}");
}


It's a complete program that (should) terminate, ignore comments and produce always correct output code. I assume EOF=-1

Tested on SystemResque-Cd 4.9.6, compiled with gcc 4.9.4

# braingasm, 40 bytes

,[35-z["[127-s[127+.>]]<0*".]24-z[43.],]


Gotta say, that's surprisingly short.

,[                                    ,]     Read a byte until end of input
35-                                          Subtract 35.
z[                     ]                  If the result is zero,
"[127-s[127+.>]]<0*".                     print the code for #.
24-               Subtract 24.
z[   ]         If the result is zero,
43.            print the code for ;


The generated code for ; is a +, which increments the current cell.

The generated code for # contains an akward, manual modulo operation

[127-s[127+.>]]<0*
[             ]       While current cell is not zero
127-                   Subtract 127
s[      ]          If result is negative
127+.              Add 127 again and print current cell
>             Step to next cell to break the loop
<0*      Step back to first cell and clear it


# Braingolf, 55 bytes

V#0VR&,l1-MvMR[R.#;e"+1"MM|.##e"@%+1~#"MMMMMM|$_vv]Rv&@  Try it online! Basically replaces ; with 1+, # with #~1+%@ and pre-pends the whole thing with a 0 because monadic + operator is broken right now. 1+ adds 1 to the last item in the stack. #~1+%@ pushes the char value of ~ (126), adds 1 to make 127, modulus with other item on stack, then pop and print as char. ### Explanation V#0VR&,l1-MvMR Implicit input of each char to stack [R.#;e"+1"MM|.##e"@%+1~#"MMMMMM|$_vv]
Rv&@

V#0                                    Create stack2, push char value of 0
&,                                Reverse stack
l1-                             Push length of stack - 1
MvMR                         Move length to stack2, switch to stack 2
Move length to stack3, switch back to stack1
[R................................vv]  Do-While loop, will run l times
where l is length of input
.#;                                  Duplicate last item and push char value of semicolon
e                                 Pop last 2 items, if they are equal..
"+1"                             ..Push char values of +1 in that order
MM                           ..Move last 2 items to stack2
|                          endif
.##                       Duplicate last item and push char value of hash
e                      Pop last 2 items, if they are equal..
"@%+1~#"              ..Push char values of @%+1~# in that order
MMMMMM        ..Move last 6 chars to stack2
|       endif
$_ Silently pop last item Rv Switch to stack2 &@ Greedy char print, print every item in stack as char  # q/kdb+, 42 bytes Solution: {-1_"c"$mod[;127](#:)@/:"#"vs x inter"#;"}


Examples:

Note that the , is used to signify a list (versus atom) as "\"" is a list of one element, rather than being an atom.

q){-1_"c"$mod[;127](#:)@/:"#"vs x inter"#;"}";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#" ";#" q){-1_"c"$mod[;127](#:)@/:"#"vs x inter"#;"}";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#"
,"\""


Explanation:

Take input string, remove anything that isnt a # or a ;, split into lists on #, count number of elements in each list, perform mod 127 on the result and cast to a string:

{-1_"c"$mod[;127]count each"#"vs x inter"#;"} / ungolfed { } / lambda function x inter"#;" / intersection of input and ';#' to clear out any 'comments' "#"vs / split string on hash count each / length of each sub-list mod[;127] / 127 modulo result (vectorised) "c"$                                      / cast back to string
-1_                                          / drop last character (assuming terminated string)


Notes:

• Assumes that input is terminated by a #, otherwise the last chunk will be erroneously dropped by the -1_.
• Could be 10 bytes shorter if input was guaranteed to only contain ;#.

# Ly, 52 bytes

0ui[[";"=[pp"+1"oo2$]p"#"=[pp"(127)%o0"&o2$]]i]";"o;
`

Try it online!