diff options
author | Camil Staps | 2016-08-25 20:29:50 +0200 |
---|---|---|
committer | Camil Staps | 2016-08-25 20:29:50 +0200 |
commit | 821939c6a6eb5761708146783ebd562422c2a7f7 (patch) | |
tree | dd26b29c65431801f4ca45d6952b7806534f9c8c /interpreter/fuspelc.c | |
parent | Remove unnecessary includes (diff) |
pedantic
Diffstat (limited to 'interpreter/fuspelc.c')
-rw-r--r-- | interpreter/fuspelc.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/interpreter/fuspelc.c b/interpreter/fuspelc.c new file mode 100644 index 0000000..5edb48c --- /dev/null +++ b/interpreter/fuspelc.c @@ -0,0 +1,64 @@ +#include <stdio.h> +#include <string.h> + +#include "eval.h" +#include "lex.h" +#include "mem.h" +#include "parse.h" +#include "print.h" + +int main(void) { + token_list* tokens; + fuspel* pgm; + expression to_eval, *evaled; + + tokens = NULL; + + while (!feof(stdin)) { + char program[79]; + if (!fgets(program, 79, stdin)) { + if (feof(stdin)) + break; + fprintf(stderr, "Couldn't read input."); + exit(EXIT_FAILURE); + } + + tokens = lex(tokens, program); + if (!tokens) { + fprintf(stderr, "Couldn't lex program."); + exit(EXIT_FAILURE); + } + } + + pgm = parse(tokens); + free_token_list(tokens); + free(tokens); + + if (!pgm) { + fprintf(stderr, "Couldn't parse program."); + exit(EXIT_FAILURE); + } + + printf("\nParsed program:\n"); + print_fuspel(pgm); + printf("\n\n\n"); + + to_eval.kind = EXPR_NAME; + to_eval.var1 = my_calloc(1, 5); + strcpy(to_eval.var1, "main"); + + evaled = eval(pgm, &to_eval); + free_expression(&to_eval); + if (evaled) { + print_expression(evaled); + printf("\n"); + + free_expression(evaled); + free(evaled); + } + + free_fuspel(pgm); + free(pgm); + + return 0; +} |