Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The Aeria Programming Language Compiler
- // Note* Compiles to Brainf*** in a textfile
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- int main(int argc, char *argv[]){
- // The file handling section
- if(argc < 3){
- printf("\nCorrect usage is: abfc <source.txt> <output.txt>\n");
- exit(8); // Exit program
- }
- FILE *file;
- file = fopen(argv[1], "r"); // Read the file to file...
- int p, size;
- p = size = 0; // Set stuff equal to zero
- char c; // Current char beind read
- if(file == NULL){
- printf("\nInput file could not be opened!\n");
- exit(8); // Exit the program
- }
- fseek(file, 0, SEEK_END);
- size = ftell(file);
- fseek(file, 0, SEEK_SET);
- char input[size]; // Set up the input for proper size
- while((c=fgetc(file)) != EOF)
- input[p++] = (char) c; // Read in the file
- fclose(file); // Close the file, we have the input array
- int i, j; // Iterator
- FILE *cfile; // output file
- cfile = fopen(argv[2], "a+");
- for(i = 0; input[i] != 0; i++){ // Go through 1 command at a time
- c = input[i];
- if(isdigit(c)){
- for(j = 0; j < (atoi(&c)); j++)
- fprintf(cfile, "+");
- }
- else if(c == '%')
- fprintf(cfile, "-");
- else if(c == '*')
- fprintf(cfile, ">");
- else if(c == '/')
- fprintf(cfile, "<");
- else if(c == '$') // get input
- fprintf(cfile, ",");
- else if(c == '#') // print current char
- fprintf(cfile, ".");
- else if(c == '{')
- fprintf(cfile, "[");
- else if(c == '}')
- fprintf(cfile, "]");
- else if(c == '&') // Set current register to zero
- fprintf(cfile, "[-]");
- else if(c == '^') // Rewind to the first register.
- fprintf(cfile, "<[<]");
- else{
- continue;
- }
- }
- fclose(cfile); // close out the file
- return 0;
- }
- /* ============================================================================= */
- /* Language Specification */
- /*
- Well, It's a simple programming language.
- { // Brackets for loops (while loop)
- } // Brackets for loops (while loop)
- * // Move pointer 1 unit right
- / // Move pointer 1 unit left
- $ // Get 1 char of input and save it current byte
- # // Print out current character.
- <number> // Increase current value of pointer by <number>
- % // Decrease current value of pointer by 1
- & // Set current register back to zero
- ^ // Rewind to frist empty register.
- @ // Print out all non zero registers, until it hits a zero.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement