if you missed the PHP reference implementation here it is: <?php
if (substr(php_sapi_name(), 0, 3) != 'cli') show_source(__FILE__) xor die();
$prog=file_get_contents("php://stdin");
$ascii=false;
$acc=0;
for($i=0;$i<strlen($prog);$i++) {
$c=$prog[$i];
switch($c) {
case 'a': $acc++; break;
case 'b': $acc--; break;
case 'c': if($ascii) echo chr($acc); else echo $acc; break;
case 'd': $acc*=-1; break;
case 'r': $acc=mt_rand(0,$acc); break;
case 'n': $acc=0; break;
case '$': $ascii=!$ascii; break;
case 'l': $i=-1; break;
case ';': echo $acc.chr($acc); break;
}
}
Name:
Anonymous2008-08-04 12:54
rather then adding another letter to the ABC Programming Language to handle control structures how about taking an ascii control character that never gets used and make it an escape character for the sequence that defines the branch
>>126
There's more programming discussion on /prog/ right now than there has been in many months.
Name:
Anonymous2008-08-05 11:38
Even if it IS an esoteric one.
Name:
Anonymous2008-08-05 13:42
Name:
Anonymous2008-08-05 13:59
I write that PHP implementation, even though I didn't make that program language ABC. Does it still a reference implementation? I guess it is if User:Orange decides it to be.
Name:
Anonymous2008-08-05 18:59
looks pretty much like a knockoff version of Brainfuck to me...
Name:
Anonymous2008-08-06 1:05
I'm surprised no one even touched the wiki page.
Name:
Anonymous2008-08-06 6:49
You didn't look very closely (or too soon, whatever)
Name:
Anonymous2008-08-06 6:50
Apparently Orange himself visits /prog/ and linked to this thread
Name:
Anonymous2008-08-06 8:35
>>136
Then there's only two possibilities: either you're User:Orange, or the Sussman invented the ABC programming language.
int main()
{
int acc = 0, asc = 0;
srandomdev();
EOF
$post = <<EOF;
putchar('\\n');
}
EOF
$post_loop = <<EOF;
}
}
EOF
%ops = (
a => 'acc++',
b => 'acc--',
c => 'asc ? putchar(acc) : printf("%d", acc)',
d => 'acc = -acc',
r => 'acc = random() % (acc+1)',
n => 'acc = 0',
'$'=>'asc = !asc',
';'=>'printf("%d%c", acc, (char)acc)'
);
sub compile {
my ($abc) = @_;
die "Syntax error: unrecognized operator $1 at char $+[1]\n"
if $abc =~ /([^abcdrn\$l;\s])/;
warn "Unreachable code detected at char @{[$-[1]+(1)]}: $1\n"
if $abc =~ /l\s*(\S+.*)/s;
You could do it like php with <?abc ?> tags - ABC outside of the tags would be printed to stdout and ABC inside of the tags would be instructions for an interpreter/opcodes for a vm.
Name:
Anonymous2008-08-26 6:37
>>151
Let's not emulate the worst language in mainstream use today, for a change.
>>155,157
I'd much rather do PHP than Sepples, Visual Basic, Java, and probably C and C#. PHP's standard library sucks, but the language itself is dynamically-typed, simple, and cleaner than Perl and Ruby (though dirtier than most others), and it's getting first-class functions and anonymous closures in 5.3.