TREE interpreter so far...

Off topicProgramming → TREE interpreter so far...

10/13/2015 UTC -06:00

Here is the TREE interpreter in C so far (prepare to see shitty work):

#include <stdio.h>
#include <stdlib.h>

void main() {
	int debug_choice;
	printf("Do you want to run debugging? (0 or 1)\n");
	scanf("%i", &debug_choice);
	
	switch(debug_choice) {
		case 0:
			interpret();
			break;
		case 1:
			debug();
			interpret();
			break;
		default:
			printf("Invalid input. Terminating interpreter...\n");
			getchar();
			exit(0);
	}
}

void interpret() {
	printf("Start of program:\n\n");
	
	FILE *program = fopen("some path to a txt file", "r");
	int command;
	int stop_loop[1000000];
	int mem_array[1000000][8];
	int direct_put_test[13];
	int mem_buffer[8];
	int count;
	fpos_t pos_0 = 0;
	fsetpos(program, &pos_0);
	
	for(command = 1; command <= 1000000; command++) {
		switch((int)fgetc(program)) {
			case 0:
				stop_loop[command] = 0;
				break;
			case 1:
				stop_loop[command] = 1;
				break;
		}
			
		switch((int)fgetc(program)) {
			case 0:
				switch((int)fgetc(program)) {
					case 0:
						for(count = 1; count <= 13; count++) {
							direct_put_test[count] = (int)fgetc(program);
						}
						
						fsetpos(program, ftell(program) - (fpos_t)13);
						
						if(direct_put_test[1] == 0 && direct_put_test[2] == 0 && direct_put_test[3] == 0 && direct_put_test[4] == 0 && direct_put_test[5] == 0 && direct_put_test[6] == 0 && direct_put_test[7] == 0 && direct_put_test[8] == 0 && direct_put_test[9] == 0 && direct_put_test[10] == 0 && direct_put_test[11] == 0 && direct_put_test[12] == 0 && direct_put_test[13] == 0) {
							fsetpos(program, ftell(program) + (fpos_t)13);
							
							switch((int)fgetc(program)) {
								case 0:
									for(count = 1; count <= 8; count++) {
										mem_buffer[count] = (int)fgetc(program);
									}
									
									break;
								case 1:
									
									
									break;
							}
						
						break;
				
				case 1:
					
					
					break;
				}
				
				break;
			
			case 1:
				
				
				break;
		}
	}
	
	printf("\n\nProgram terminated.");
	getchar();
}

void debug() {
	
}

The main() function is done, and I mainly work on the interpreter() function now, because it is the most core and important function: even more important than main(), because all what main() does is just accepts user input and makes choices on calling what function. debug() is empty, containing no code.

Too much extreme indentation >.<
dat indentation doe.
The big thing now is just to decode binary into decimal.
Easy in python :) Also any particular reason you are choosing C over cpp?
@Pan, the only reason I use C is because I hate classes and objects, and that because older languages tend to get more into the fundamental level. X-D
What are the commands?
@nalaek2004, the unit of TREE is commands. Each command is 34 bits long (TREE is composed of 0s and 1s), and each command goes through a differentiation and execution process.