scl/src/main.c

59 lines
1.1 KiB
C
Raw Normal View History

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-10-07 11:48:53 -04:00
#include "include/lexer.h"
2024-11-09 10:27:03 -05:00
#include "include/util.h"
#include "include/exec.h"
2024-11-09 10:27:03 -05:00
#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-28 09:31:23 -04:00
int main(int argc, char** argv) {
2024-11-09 10:27:03 -05:00
while (1) {
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
// Accumulate line.
do {
c = getc(stdin);
switch (c) {
case EOF: dstr_destroy(ln); goto lnskip;
case '\n': goto lnend;
default: dstr_appendch(ln, c); log_dbgf("cchar: %c", c);
}
} while (1);
2024-10-16 08:13:32 -04:00
lnend:
log_dbgf("cline: %s", ln->buf);
if (ln->ln > 0) {
2024-11-23 10:21:34 -05:00
// I hope it's null-terminated.
inp = ln->buf;
if (yyparse() == 0)
2024-11-09 10:27:03 -05:00
printf("Parsed successfully!\n");
else
2024-11-09 10:27:03 -05:00
printf("Parse error.\n");
2024-12-07 10:33:16 -05:00
//exec_expr(root);
ast_print(root);
2024-10-13 23:46:03 -04:00
}
2024-10-31 16:44:17 -04:00
dstr_destroy(ln);
2024-10-13 23:46:03 -04:00
}
lnskip:;
2024-09-28 09:31:23 -04:00
}