-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
File minimizer removes all extraneous characters, making execution faster. Bash script simplifies execution of Bologna files
- Loading branch information
1 parent
d0e6a59
commit 06bb231
Showing
12 changed files
with
200 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
gcc ./src/bologna_parser.c -o ./bologna_parser | ||
gcc ./src/bologna_interpreter.c -o ./bologna_interpreter | ||
|
||
touch temp.bf | ||
|
||
./bologna_parser $1 temp.bf | ||
./bologna_interpreter temp.bf | ||
|
||
rm temp.bf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
BrainFuck "Hello World" | ||
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++. | ||
Bologna Shorthand Syntax of "Hello World" | ||
+8[>+3[>+2>+3>+3>+<4-]>+>+>->2+[<]<-]>2.>-3.+6.2+3.>2.<-.<.+3.-6.-8.>2+.>+2. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 9 additions & 3 deletions
12
bologna_files/tic_tac_toe.bf → bologna_examples/tic_tac_toe.bf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
>{:10+:#10+#10+48}9:10_+10.:11+32:12+124:13+88:14+79:0_+45.7_#10._#12.#1.#12.#2.#12.#3.#12.#10._+45.7_#10._#12.#4.#12.#5.#12.#6.#12.#10._+45.7_#10._#12.#7.#12.#8.#12.#9.#12.#10._+45.7_#10.{#10._+80._+108._+97._+121._+101._+114._+32._+49._+32._+45._#11.+80._+105._+99._+107._+32._+97._+32._+67._+101._+108._+108._+32._+49._+32._+45._+32._+57._+41._#11.:100_+1[:50_,:0#10.:#50?(#>78){:0_+84._+104._+97._+116._+32._+99._+101._+108._+108._+32._+105._+115._+32._+97._+108._+114._+101._+97._+100._+121._+32._+116._+97._+107._+101._+110._+33._+32._+80._+108._+101._+97._+115._+101._+32._+99._+104._+111._+111._+115._+101._+32._+97._+110._+32._+101._+109._+112._+116._+121._+32._+111._+110._+101._+46._#10._+80._+108._+97._+121._+101._+114._+32._+49._+32._+45._#11.+80._+105._+99._+107._+32._+97._+32._+67._+101._+108._+108._+32._+49._+32._+45._+32._+57._+41._#11.}:#50?(#<#14){:100_:#50_+#13:0}:100]_+45.7_#10._#12.#1.#12.#2.#12.#3.#12.#10._+45.7_#10._#12.#4.#12.#5.#12.#6.#12.#10._+45.7_#10._#12.#7.#12.#8.#12.#9.#12.#10._+45.7_#10.:0_?(#1=#2){?(#2=#3){?(#1>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#1=#13){+49._}?(#1=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#4=#5){?(#5=#6){?(#4>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#1=#13){+49._}?(#1=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#7=#8){?(#8=#9){?(#7>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#1=#13){+49._}?(#1=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#1=#4){?(#4=#7){?(#1>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#1=#13){+49._}?(#1=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#2=#5){?(#5=#8){?(#2>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#2=#13){+49._}?(#2=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#3=#6){?(#6=#9){?(#3>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#3=#13){+49._}?(#3=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#1=#5){?(#5=#9){?(#1>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#1=#13){+49._}?(#1=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#3=#5){?(#5=#7){?(#3>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#3=#13){+49._}?(#3=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}#10._+80._+108._+97._+121._+101._+114._+32._+50._+32._+45._#11.+80._+105._+99._+107._+32._+97._+32._+67._+101._+108._+108._+32._+49._+32._+45._+32._+57._+41._#11.:100_+1[:50_,:0#10.:#50?(#>78){:0_+84._+104._+97._+116._+32._+99._+101._+108._+108._+32._+105._+115._+32._+97._+108._+114._+101._+97._+100._+121._+32._+116._+97._+107._+101._+110._+33._+32._+80._+108._+101._+97._+115._+101._+32._+99._+104._+111._+111._+115._+101._+32._+97._+110._+32._+101._+109._+112._+116._+121._+32._+111._+110._+101._+46._#10._+80._+108._+97._+121._+101._+114._+32._+50._+32._+45._#11.+80._+105._+99._+107._+32._+97._+32._+67._+101._+108._+108._+32._+49._+32._+45._+32._+57._+41._#11.}:#50?(#<#14){:100_:#50_+#14:0}:100]_+45.7_#10._#12.#1.#12.#2.#12.#3.#12.#10._+45.7_#10._#12.#4.#12.#5.#12.#6.#12.#10._+45.7_#10._#12.#7.#12.#8.#12.#9.#12.#10._+45.7_#10.:0_?(#1=#2){?(#2=#3){?(#1>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#1=#13){+50._}?(#1=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#4=#5){?(#5=#6){?(#4>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#1=#13){+50._}?(#1=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#7=#8){?(#8=#9){?(#7>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#1=#13){+50._}?(#1=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#1=#4){?(#4=#7){?(#1>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#1=#13){+50._}?(#1=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#2=#5){?(#5=#8){?(#2>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#2=#13){+50._}?(#2=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#3=#6){?(#6=#9){?(#3>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#3=#13){+50._}?(#3=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#1=#5){?(#5=#9){?(#1>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#1=#13){+50._}?(#1=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}?(#3=#5){?(#5=#7){?(#3>78){+71._+97._+109._+101._+32._+79._+118._+101._+114._+46._+32._+80._+108._+97._+121._+101._+114._+32._?(#3=#13){+50._}?(#3=#14){+50._}32._+87._+105._+110._+115._+33._#10.#10.~}}}}5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* BOLOGNA LANGUAGE INTERPRETER | ||
* ============================= | ||
* | ||
* Bologna is an esoteric, interpreted language | ||
* made to see what is possible with a minimilastic | ||
* programming paradigm. | ||
* | ||
* OSS under the MIT License. | ||
*/ | ||
|
||
/*----------------------------------------------------------------*/ | ||
|
||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
#include "bologna_interpreter.h" | ||
|
||
/*----------------------------------------------------------------*/ | ||
|
||
void close_files(FILE *fr, FILE *fw) { | ||
fclose(fr); | ||
fr = NULL; | ||
fclose(fw); | ||
fw = NULL; | ||
} /* close_files() */ | ||
|
||
|
||
|
||
/* | ||
* Reads arguments passed to commands, and returns the integer values passed. | ||
* | ||
* Takes in a file read pointer, and an operator character (i.e. ><.,+-.,#) | ||
*/ | ||
int operator_args(FILE *fr, char operator_char) { | ||
int value = 0; | ||
|
||
if (operator_char == PTR_VALUE) { | ||
|
||
// Read in the integer representing the memory index | ||
int num_in = fscanf(fr, "%d\n", &value); | ||
|
||
// If mem index was read in successfully | ||
if (num_in == 1) { | ||
// Give the value to the value at the memory index | ||
return value; | ||
} else { | ||
// Give the value of the current memory index | ||
value = -1; | ||
} | ||
|
||
// If the argument is just an integer | ||
} else if (fscanf(fr, "%d", &value) == 1) { | ||
return value; | ||
} | ||
|
||
return -1; | ||
} /* read_args() */ | ||
|
||
|
||
|
||
/* | ||
* Condenses a file by removing comments, whitespace, and any other | ||
* non-command characters. Creates a new minimized output file. | ||
*/ | ||
|
||
int file_condense(FILE *fr, FILE *fw) { | ||
int is_comment = 0; | ||
int argument = 0; | ||
char operator_char = '\0'; | ||
while ((feof(fr) == 0) && (ferror(fr) == 0) && (ferror(fw) == 0)) { | ||
operator_char = fgetc(fr); | ||
|
||
if (is_comment == 1) { | ||
|
||
if (operator_char == COMMENT) { | ||
is_comment = 0; | ||
} | ||
continue; | ||
|
||
} else { | ||
|
||
switch(operator_char) { | ||
|
||
case COMMENT: | ||
is_comment = 1; | ||
break; | ||
|
||
|
||
// Operators that do not take arguments | ||
case ZERO: | ||
case CHAR_IN: | ||
case BRACE_START: | ||
case QUERY: | ||
case LOGIC_START: | ||
case LOGIC_END: | ||
case EQUAL: | ||
case NOT: | ||
fputc(operator_char, fw); | ||
break; | ||
|
||
|
||
// Arguments that do take operators | ||
case PTR_LEFT_SHIFT: | ||
case PTR_RIGHT_SHIFT: | ||
case INCREMENT: | ||
case DECREMENT: | ||
case CHAR_OUT: | ||
case BRN_FCK_LOOP_START: | ||
case BRN_FCK_LOOP_END: | ||
case ABSOLUTE_SHIFT: | ||
case MULTIPLY: | ||
case DIVIDE: | ||
case PTR_VALUE: | ||
case BRACE_END: | ||
case EXIT: | ||
fputc(operator_char, fw); | ||
argument = operator_args(fr, operator_char); | ||
if (argument != -1) { | ||
fprintf(fw, "%d", argument); | ||
} | ||
break; | ||
|
||
default: | ||
continue; | ||
} | ||
|
||
} | ||
} | ||
|
||
if ((feof(fr) == 1)) { | ||
return 0; | ||
} | ||
|
||
return -1; | ||
} /* file_condense() */ | ||
|
||
/*----------------------------------------------------------------*/ | ||
|
||
|
||
|
||
int main(int argc, char **argv) { | ||
|
||
// If no filename argument was passed, throw error | ||
if (argc < 2) { | ||
printf("\n\nError: Specify a Brainfuck file to interpret.\n\n"); | ||
return -1; | ||
} | ||
|
||
FILE * fr; | ||
FILE * fw; | ||
|
||
// If the given file does not exist or cannot be opened, throw error | ||
fr = fopen(argv[1], "r"); | ||
if (!fr) { | ||
printf("\n\nError: Brainfuck file '%s' not found.\n\n", argv[1]); | ||
return -1; | ||
} | ||
|
||
fw = fopen(argv[2], "w"); | ||
if (!fr) { | ||
printf("\n\nError: Unable to create file '%s'\n\n", argv[1]); | ||
return -1; | ||
} | ||
|
||
if (file_condense(fr, fw) == -1) { | ||
printf("\n\nError: Error condesing file '%s'.\n\n", argv[1]); | ||
close_files(fr, fw); | ||
return -1; | ||
} | ||
|
||
|
||
return 0; | ||
} |
Binary file not shown.