Advertisement
theelitenoob

Aeria Language Compiler

Jul 22nd, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.36 KB | None | 0 0
  1. // The Aeria Programming Language Compiler
  2. // Note* Compiles to Brainf*** in a textfile
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7.  
  8. int main(int argc, char *argv[]){
  9.     // The file handling section
  10.     if(argc < 3){
  11.         printf("\nCorrect usage is: abfc <source.txt> <output.txt>\n");
  12.         exit(8); // Exit program
  13.     }
  14.     FILE *file;
  15.     file = fopen(argv[1], "r"); // Read the file to file...
  16.     int p, size;
  17.     p = size = 0; // Set stuff equal to zero
  18.     char c; // Current char beind read
  19.     if(file == NULL){
  20.         printf("\nInput file could not be opened!\n");
  21.         exit(8); // Exit the program
  22.     }
  23.     fseek(file, 0, SEEK_END);
  24.     size = ftell(file);
  25.     fseek(file, 0, SEEK_SET);
  26.     char input[size]; // Set up the input for proper size
  27.     while((c=fgetc(file)) != EOF)
  28.         input[p++] = (char) c; // Read in the file
  29.     fclose(file); // Close the file, we have the input array
  30.     int i, j; // Iterator
  31.     FILE *cfile; // output file
  32.     cfile = fopen(argv[2], "a+");
  33.     for(i = 0; input[i] != 0; i++){ // Go through 1 command at a time
  34.         c = input[i];
  35.         if(isdigit(c)){
  36.             for(j = 0; j < (atoi(&c)); j++)
  37.                 fprintf(cfile, "+");
  38.         }
  39.         else if(c == '%')
  40.             fprintf(cfile, "-");
  41.         else if(c == '*')
  42.             fprintf(cfile, ">");
  43.         else if(c == '/')
  44.             fprintf(cfile, "<");
  45.         else if(c == '$') // get input
  46.             fprintf(cfile, ",");
  47.         else if(c == '#') // print current char
  48.             fprintf(cfile, ".");
  49.         else if(c == '{')
  50.             fprintf(cfile, "[");
  51.         else if(c == '}')
  52.             fprintf(cfile, "]");
  53.         else if(c == '&') // Set current register to zero
  54.             fprintf(cfile, "[-]");
  55.         else if(c == '^') // Rewind to the first register.
  56.             fprintf(cfile, "<[<]");
  57.         else{
  58.             continue;
  59.         }
  60.     }
  61.     fclose(cfile); // close out the file
  62.     return 0;
  63. }
  64.  
  65. /* ============================================================================= */
  66.  
  67. /* Language Specification */
  68.  
  69. /*
  70. Well, It's a simple programming language.
  71.  
  72. {       // Brackets for loops (while loop)
  73. }       // Brackets for loops (while loop)
  74. *       // Move pointer 1 unit right
  75. /       // Move pointer 1 unit left
  76. $       // Get 1 char of input and save it current byte
  77. #       // Print out current character.
  78. <number>    // Increase current value of pointer by <number>
  79. %       // Decrease current value of pointer by 1
  80. &       // Set current register back to zero
  81. ^       // Rewind to frist empty register.
  82. @       // Print out all non zero registers, until it hits a zero.
  83. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement