summaryrefslogtreecommitdiff
path: root/igen/lexer.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-02-16 17:05:00 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2022-02-18 10:05:01 -0400
commit5f753ddee7d935e0ba4750a6a8c26fe056c77612 (patch)
tree07b152f726bff71f871f3a5a736098a1e0b0bd04 /igen/lexer.c
parent722c7f08e409d1f6f3a26bda666c15d7082f52e3 (diff)
igen: Start work on writing a preprocessor.
Diffstat (limited to 'igen/lexer.c')
-rw-r--r--igen/lexer.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/igen/lexer.c b/igen/lexer.c
index 03f7e87..1d3268e 100644
--- a/igen/lexer.c
+++ b/igen/lexer.c
@@ -4,12 +4,13 @@
#include <string.h>
#include "lexer.h"
#include "misc.h"
+#include "preprocessor.h"
-cond_stmt *lex_cond_stmt(char **str, int dbg) {
+cond_stmt *lex_cond_stmt(source *src, int dbg) {
}
-stmt *lex_comp_stmt(char **str, int dbg) {
+stmt *lex_comp_stmt(source *src, int dbg) {
char *tmp = *str;
if (*tmp++ == '{') {
stmt *s = lex_stmt(&tmp, dbg);
@@ -17,13 +18,13 @@ stmt *lex_comp_stmt(char **str, int dbg) {
*str = tmp;
return s;
} else {
- throw_error("Missing \'}\' in stmt.");
+ throw_error(src, 1, "Missing \'}\' in compound statement.");
}
}
return NULL;
}
-stmt *lex_stmt(char **str, int dbg) {
+stmt *lex_stmt(source *src, int dbg) {
const alt_stmt alts[] = {
{STMT_DIR, offsetof(stmt, dir), lex_dir},
{STMT_FUNC, offsetof(stmt, func), lex_func},
@@ -45,7 +46,7 @@ stmt *lex_stmt(char **str, int dbg) {
return NULL;
}
-stmt *lex_library(char **str, stmt **end, int dbg) {
+stmt *lex_library(source *src, stmt **end, int dbg) {
stmt *start = lex_stmt(str, dbg);
end = (end != NULL) ? end : &start;
for (stmt *s = start; s != NULL; s = lex_stmt(str, dbg)) {
@@ -59,6 +60,8 @@ int lex(char *str, int dbg) {
stmt *start = NULL;
stmt *end = NULL;
+ source *src = preprocess(str, dbg);
start = library(&str, &end, dbg);
+
return (start != NULL && end != NULL);
}