diff --git a/main.c b/main.c new file mode 100644 index 0000000..2046fae --- /dev/null +++ b/main.c @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#define MAX 2056 + +int main(int argc, char *argv[]) { + printf("Starting up...\n"); + if (argc == 1) { + printf("Usage: curly-lang /path/to/file\n"); + return 1; + } + char *file = argv[1]; + FILE *fileopen = fopen(file, "r"); + if (NULL == fileopen) { + printf("Error Opening: %s\n", file); + return 1; + } + // declare variables + int intv[MAX] = {}; + char intname[MAX][256] = {}; + bool boolv[MAX] = {}; + char boolname[MAX][256] = {}; + float floatv[MAX] = {}; + char floatname[MAX][256] = {}; + char charv[MAX] = {}; + char charname[MAX][256] = {}; + //base + int i = 0; + char line[2056]; + char string[1028]; + int integer; + float floatd; + char string2[1028]; + bool boolt; + while (fgets(line, sizeof(line), fileopen)) { + line[strcspn(line, "\n")] = '\0'; + + if (sscanf(line, "print.{out.newline}={%1027[^}]}={end};", string) == 1) { + printf("%s\n", string); + } else if (sscanf(line, "print.{out}={%1027[^}]}={end};", string) == 1) { + printf("%s", string); + } else if (sscanf(line, "system.{exec.command}={%1027[^}]}={end};", string) == 1) { + system(string); + } else if (sscanf(line, "var.{int}={%1027[^}]}={%d}={end};", string, &integer) == 2) { + for (int i = 0; i < MAX; i++) { + if (intv[i] == 0) { + strcpy(intname[i], string); + intv[i] = integer; + break; + } + } + } else if (sscanf(line, "print.{out.newline.var.int}={%1027[^}]}={end};", string) == 1) { + for (int i = 0; i < MAX; i++) { + if (strcmp(intname[i], string) == 0) { + printf("%d\n", intv[i]); + break; + } + } + } else if (sscanf(line, "var.{bool}={%1027[^}]}={%1027[^}]}={end};", string, string2) == 2) { + if (strcmp(string2, "true")) { + boolt = true; + } else if (strcmp(string2, "TRUE")) { + boolt = true; + } else if (strcmp(string2, "false")) { + boolt = false; + } else if (strcmp(string2, "FALSE")) { + boolt = false; + } + for (int i = 0; i < MAX; i++) { + if (boolv[i] == 0) { + strcpy(boolname[i], string); + boolv[i] = boolt; + break; + } + } + } else if (sscanf(line, "print.{out.newline.var.bool}={%1027[^}]}={end};", string) == 1) { + for (int i = 0; i < MAX; i++) { + if (strcmp(boolname[i], string) == 0) { + if (boolv[i] == true) { + printf("true\n"); + } else if (boolv[i] == false) { + printf("false"); + } + break; + } + } + } else { + printf("Error with line: %s\n", line); + return EXIT_FAILURE; + } + } + + fclose(fileopen); + return EXIT_SUCCESS; +} \ No newline at end of file