Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Esoteric language: Timef**k


  • Please log in to reply
No replies to this topic

#1 Aereshaa

Aereshaa

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 638 posts

Posted 10 December 2009 - 08:31 PM

I wrote this interpreter in C for my esoteric language Timef**k
#include "stdio.h"
#include "stdlib.h"

char code[1000];
char data[10][100];
int ip[100];
int dx[100];
int dt[100];
char output[100];
int op[100];

int skip(int i){
	while(code[i] != ')')
		if(code[i] == '(') i = skip(i+1);
		else  i++;
	return i;
}

int exec(int ct,int ei){
	printf("exec %d %d\n",ct,ei);
	int i = ip[ct];
	int x = dx[ct];
	int t = dt[ct];
	int o = op[ct];
	while(i<ei){
		printf("%d %d %d %d : %c\n",ct,i,x,t,code[i]);
		if(code[i] == '>') if(x<9) x++; else x=0;
		if(code[i] == '<') if(x>0) x--; else x=9;
		if(code[i] == 'v'){
			exec(t,i+1);
			if(t<99) t++;
		}
		if(code[i] == '^') if(t>0) t--;
		if(code[i] == '(') if(data[x][t] == 0) i = skip(i+1);
		if(code[i] == '|') {
			int j;
			for(j=0;j<10;j++) data[j][ct+1] = data[j][ct];
			ip[ct]=i;
			dx[ct]=x;
			dt[ct]=t;
			op[ct]=o;
			ct++;
			t++;
		}
		if(code[i] == '+')data[x][t]++; 
		if(code[i] == '-')data[x][t]--;
		if(code[i] == '.'){
			output[o++] = data[x][t];
			printf("%d was %d or '%c' at %d\n",x,data[x][t],data[x][t],t);
		}
		i++;
	}
	printf("end exec\n");
}


int main(){
	int i;
	for(i=0;i<1000;i++)
		if((code[i]=getchar())=='#')
			break;
	code[i]=0;
	puts(code);
	exec(0,i);
	puts(output);
	for(i=0;i<10;i++)printf("%d\n",output[i]);
}

  • 0
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download