aboutsummaryrefslogtreecommitdiff
path: root/include/parser.h
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2022-01-20 02:34:32 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2022-01-20 02:34:32 +0300
commitc0cd4e5f199e8567ec3b5e216fbee27837d21bea (patch)
treec78eee02932fc6e85413e367d27ec5b5627e1534 /include/parser.h
downloadcmonkey-c0cd4e5f199e8567ec3b5e216fbee27837d21bea.tar.gz
cmonkey-c0cd4e5f199e8567ec3b5e216fbee27837d21bea.zip
init
Diffstat (limited to 'include/parser.h')
-rw-r--r--include/parser.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/include/parser.h b/include/parser.h
new file mode 100644
index 0000000..b344a7b
--- /dev/null
+++ b/include/parser.h
@@ -0,0 +1,33 @@
+#ifndef CMONKEY_PARSER_H
+#define CMONKEY_PARSER_H
+
+#include "ast.h"
+#include "hmap.h"
+#include "lexer.h"
+#include "token.h"
+#include "vector.h"
+
+struct parser {
+ struct lexer *lexer;
+ struct token cur_token;
+ struct token peek_token;
+ struct vector *errors;
+ struct hmap *prefix_fns;
+ struct hmap *infix_fns;
+ struct hmap *precedences;
+};
+
+typedef struct expression *(*prefix_parse_f)(struct parser *);
+typedef struct expression *(*infix_parse_f)(struct parser *, struct expression *);
+
+struct parser *parser_new();
+
+void parser_reset(struct parser *, const char *input);
+
+void parser_next_token(struct parser *);
+
+struct program *parser_parse_program(struct parser *);
+
+void parser_destroy(struct parser *);
+
+#endif