Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

ITT the ABC Programming Language

Name: Anonymous 2008-07-29 19:29

#include <stdio.h>

int main(int argc,char argv*[]){
  int i = 0;
  int BUFFA;

  while(argv[i]!='\0'){
    if(argv[i]='a')
      BUFFA++;
    else if(argv[i]='b')
      BUFFA--;
    else if(argv[i]='c')
      printf("%i\n",BUFFA);
    else printf("%s","Error.\n");
  }
}

Name: Anonymous 2008-08-06 12:33

This thread still lacks compiler.

#!/usr/bin/perl

$pre = <<EOF;
#include <stdio.h>

int main()
{
    int acc = 0, asc = 0;
EOF

$pre_rand = <<EOF;
#include <stdio.h>
#include <stdlib.h>

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;
   
    $abc =~ s/\s+//g;
    $has_rand = $abc =~ /r/;
    $has_loop = $abc =~ s/l.*//;
    $indent = "\t" . "\t" x $has_loop;
   
    (my $c = $abc) =~ s/(.)/$indent.$ops{$1}.";\n"/ge;
    $c = ($has_rand ? $pre_rand : $pre) .
         ($has_loop ? "\tfor(;;)\n\t{\n" : "") .
         $c .
         ($has_loop ? $post_loop : $post);
}

undef $/;
print compile <>;

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List