2024-09-28 09:31:23 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2024-11-09 10:27:03 -05:00
|
|
|
#include "include/ast.h"
|
2024-10-13 23:46:03 -04:00
|
|
|
#include "include/dstr.h"
|
2024-12-14 20:35:36 -05:00
|
|
|
#include "include/exec.h"
|
2024-10-07 11:48:53 -04:00
|
|
|
#include "include/lexer.h"
|
2024-11-09 10:27:03 -05:00
|
|
|
#include "include/util.h"
|
|
|
|
|
|
|
|
#include "../build/grammars/grammar.tab.h"
|
|
|
|
|
|
|
|
// Global Abstract Syntax Tree.
|
2024-11-23 09:30:35 -05:00
|
|
|
extern AST* root;
|
2024-11-09 10:27:03 -05:00
|
|
|
|
2024-11-23 10:21:34 -05:00
|
|
|
// Global input text.
|
|
|
|
char* inp = NULL;
|
|
|
|
|
2024-11-09 10:27:03 -05:00
|
|
|
extern int yyparse();
|
2024-09-30 09:00:37 -04:00
|
|
|
|
2024-09-28 09:31:23 -04:00
|
|
|
int main(int argc, char** argv) {
|
2024-11-30 10:24:31 -05:00
|
|
|
|
2024-11-09 10:27:03 -05:00
|
|
|
while (1) {
|
2024-11-30 10:24:31 -05:00
|
|
|
Dstr* ln = dstr_init();
|
|
|
|
char c;
|
|
|
|
|
2024-10-13 23:46:03 -04:00
|
|
|
printf("> ");
|
|
|
|
fflush(stdout);
|
2024-10-07 11:48:53 -04:00
|
|
|
|
2024-11-30 10:24:31 -05:00
|
|
|
// Accumulate line.
|
|
|
|
do {
|
|
|
|
c = getc(stdin);
|
|
|
|
switch (c) {
|
2024-12-14 20:35:36 -05:00
|
|
|
case EOF: dstr_destroy(ln); goto lnskip;
|
|
|
|
case '\n': goto lnend;
|
|
|
|
default: dstr_appendch(ln, c); log_dbgf("cchar: %c", c);
|
2024-11-30 10:24:31 -05:00
|
|
|
}
|
|
|
|
} while (1);
|
2024-10-16 08:13:32 -04:00
|
|
|
|
2024-11-30 10:24:31 -05:00
|
|
|
lnend:
|
|
|
|
|
|
|
|
log_dbgf("cline: %s", ln->buf);
|
|
|
|
|
|
|
|
if (ln->ln > 0) {
|
|
|
|
inp = ln->buf;
|
2024-12-14 20:35:36 -05:00
|
|
|
if (yyparse() == 0) printf("Parsed successfully!\n");
|
|
|
|
else printf("Parse error.\n");
|
2024-11-30 10:24:31 -05:00
|
|
|
|
2024-12-21 10:12:30 -05:00
|
|
|
exec_print(exec_expr(root));
|
2024-12-07 10:33:16 -05:00
|
|
|
ast_print(root);
|
2024-10-13 23:46:03 -04:00
|
|
|
}
|
2024-10-31 16:44:17 -04:00
|
|
|
|
2024-11-30 10:24:31 -05:00
|
|
|
dstr_destroy(ln);
|
2024-10-13 23:46:03 -04:00
|
|
|
}
|
2024-11-30 10:24:31 -05:00
|
|
|
lnskip:;
|
2024-09-28 09:31:23 -04:00
|
|
|
}
|