scl/src/main.c

42 lines
939 B
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 "../build/grammars/grammar.tab.h"
// Global Abstract Syntax Tree.
AST* root = NULL;
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) {
2024-10-13 23:46:03 -04:00
Dstr* cline = dstr_init(); // The current line.
printf("> ");
fflush(stdout);
2024-10-16 08:13:32 -04:00
for (char cch; (cch = getc(stdin)) != '\n';) {
log_dbgf("cchar: %c", cch);
dstr_appendch(cline, cch);
2024-10-13 23:46:03 -04:00
}
2024-10-07 11:48:53 -04:00
2024-10-16 08:13:32 -04:00
log_dbgf("cline: %s", cline->buf);
2024-10-13 23:46:03 -04:00
if (cline->ln > 0) {
2024-11-07 19:41:14 -05:00
lexer_init(cline->buf);
lexer_lex();
lexer_print();
2024-11-09 10:27:03 -05:00
if (yyparse() == 0) {
printf("Parsed successfully!\n");
} else {
printf("Parse error.\n");
}
2024-11-07 19:41:14 -05:00
lexer_destroy();
2024-10-13 23:46:03 -04:00
}
2024-10-31 16:44:17 -04:00
dstr_destroy(cline);
2024-10-13 23:46:03 -04:00
}
2024-09-28 09:31:23 -04:00
}