aboutsummaryrefslogtreecommitdiff
path: root/interpreter/fuspel.c
diff options
context:
space:
mode:
authorCamil Staps2016-08-28 15:53:04 +0200
committerCamil Staps2016-08-28 15:53:04 +0200
commit1237de832250ef81076ff9647bd68ad0eded32ea (patch)
treef236268e580ea26ab0941c29a8234d11d2b8ae8a /interpreter/fuspel.c
parentfuspelc -> fuspel (diff)
Adds an import construct; resolves #1
Diffstat (limited to 'interpreter/fuspel.c')
-rw-r--r--interpreter/fuspel.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/interpreter/fuspel.c b/interpreter/fuspel.c
index 0e1d82b..10319d0 100644
--- a/interpreter/fuspel.c
+++ b/interpreter/fuspel.c
@@ -7,17 +7,30 @@
#include "parse.h"
#include "print.h"
-int main(void) {
- token_list* tokens;
+#define LINE_LENGTH 139
+
+fuspel* parse_file(fuspel* already_parsed, char* fname) {
+ token_list* tokens = NULL;
fuspel* pgm;
- expression* result;
+ FILE* f;
+ char* fname_;
+
+ fname_ = my_calloc(1, strlen(fname) + 6);
+ strcpy(fname_, fname);
+ strcat(fname_, ".fusp");
+
+ f = fopen(fname_, "r");
+ if (!f) {
+ fprintf(stderr, "Couldn't read %s\n", fname_);
+ exit(EXIT_FAILURE);
+ }
- tokens = NULL;
+ printf("Lexing %s...\n", fname_);
- while (!feof(stdin)) {
- char program[79];
- if (!fgets(program, 79, stdin)) {
- if (feof(stdin))
+ while (!feof(f)) {
+ char program[LINE_LENGTH];
+ if (!fgets(program, LINE_LENGTH, f)) {
+ if (feof(f))
break;
fprintf(stderr, "Couldn't read input.\n");
exit(EXIT_FAILURE);
@@ -29,10 +42,31 @@ int main(void) {
exit(EXIT_FAILURE);
}
}
-
+
+ printf("Parsing %s...\n", fname_);
+
pgm = parse(tokens);
free_token_list(tokens);
my_free(tokens);
+
+ concat_fuspel(pgm, already_parsed);
+
+ return pgm;
+}
+
+int main(int argc, char* argv[]) {
+ expression* result;
+ fuspel* pgm = NULL;
+ int i;
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s file [file [file [..]]]\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ for (i = 1; i < argc; i++) {
+ pgm = parse_file(pgm, argv[i]);
+ }
if (!pgm) {
fprintf(stderr, "Couldn't parse program.\n");