aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authors-over-42023-06-23 01:57:04 -0400
committers-over-42023-06-23 01:57:04 -0400
commite850a08fa7a763140b9c86308cfdff9bae421c2e (patch)
tree0042d0bba020391f956ed95160dca8375d9c64db /src/include
parent76e952ec1756deae78d9a88a67b97eff3550959e (diff)
parser groundwork
Diffstat (limited to 'src/include')
-rw-r--r--src/include/parser.h53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/include/parser.h b/src/include/parser.h
index 2811469..32cd4bc 100644
--- a/src/include/parser.h
+++ b/src/include/parser.h
@@ -1,45 +1,52 @@
#ifndef PARSER_H
#define PARSER_H
-#include "token.h"
-#include "tree.h"
#include "lexer.h"
-
+#include "tree.h"
typedef struct PARSER_STRUC {
- lexer_t* lexer;
- token_t* token;
+ lexer_t* lexer; // lexer used by the parser
+ token_t* token; // current token
} parser_t;
-// initialize a parser
parser_t* parser_init(lexer_t* lexer);
void parser_destroy(parser_t* parser);
-// check for expected token, or throw syntax error
+// expect token, or die
void parser_token_expect(parser_t* parser, int (*expected_token)(token_t*));
// do the parse
tree_t* parser_parse(parser_t* parser);
-tree_t* parser_parse_token(parser_t* parser);
-// parse hunks
-tree_t* parser_parse_hunk(parser_t* parser);
-tree_t* parser_parse_hunks(parser_t* parser);
+// parse statements
+// - end in semicolon or ) or }
+// - can contain one expression
+// - return what they evaluate to
+tree_t* parser_parse_statements(parser_t* parser);
+tree_t* parser_parse_statement(parser_t* parser);
+
+// parse expressions
+// - in parenthetical
+// - contain only one statement
+// - return what that statement evaluates to
+// - adds layer of scope)
+// basically a statement, but with a layer of scope
+tree_t* parser_parse_exprs(parser_t* parser);
+tree_t* parser_parse_expr(parser_t* parser);
+
+// parse blocks
+// - in curly brackets
+// - many statements
+// - return what last statement evaluates to
+tree_t* parser_parse_blocks(parser_t* parser);
+tree_t* parser_parse_block(parser_t* parser);
+
+// blocks contain many statements, any of which may contain any number of expressions
-// leaves of the tree
-tree_t* parser_parse_prim(parser_t* parser);
-tree_t* parser_parse_subtree(parser_t* parser);
tree_t* parser_parse_def(parser_t* parser);
tree_t* parser_parse_call(parser_t* parser);
-// primitives
-tree_t* parser_parse_prim_str(parser_t* parser);
-tree_t* parser_parse_prim_int(parser_t* parser);
-tree_t* parser_parse_prim_unkwn(parser_t* parser);
-
-// defs
-tree_t* parser_parse_def_tags(parser_t* parser);
-int parser_is_def_tag(char* maybe_tag);
-
+tree_t* parser_parse_type_str(parser_t* parser);
+tree_t* parser_parse_type_int(parser_t* parser);
#endif