96 lines
2.9 KiB
C
96 lines
2.9 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <stdbool.h>
|
||
|
#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;
|
||
|
}
|