From c3c0f8f78085bdc4698263513aea0c9b2d33bae4 Mon Sep 17 00:00:00 2001 From: c+1 Date: Tue, 21 Nov 2023 10:16:23 -0500 Subject: Basic block, expression, and number parsing. --- src/include/parser.h | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/include/parser.h') diff --git a/src/include/parser.h b/src/include/parser.h index b39f481..59bbbb5 100644 --- a/src/include/parser.h +++ b/src/include/parser.h @@ -11,6 +11,8 @@ typedef struct PARSER { /* The AST being produced. */ tree_t* tree; + + /* Pointer to the part of the tree the parser is currently working on. */ } parser_t; /* Creates a new parser. */ @@ -26,26 +28,31 @@ void parser_destroy(parser_t* parser); /* Step the parser forward by 1 token. */ int parser_nxt_token(parser_t* parser); -/* Check whether the current token matches the given type. */ +/* + Check whether the current token matches the given type. + - If it doesn't, return 0 and throw error. +*/ int parser_match(parser_t* parser, token_type_t type); -/* - parse lit: converting everything from strings to value in the tree - parse expr: (For now) call parse lit - parse blk: loop over all expressions until reaching an end block. +/* Steps the parser forward by one token, then check whether the new token matches the given type. */ +int parser_nxt_token_match(parser_t* parser, token_type_t type); +/* + Parse a single literal value. + - Only does integers for now. */ +tree_t* parser_parse_lit(parser_t* parser); + +/* Return a tree for a single semicolon-separated expression.*/ +tree_t* parser_parse_expr(parser_t* parser); -/* Parse a single literal value. */ -void parser_parse_lit(parser_t* parser); +/* Return a tree for a single curly-brace-separated expression. */ +tree_t* parser_parse_block(parser_t* parser); -/* Parse a single expression. */ -void parser_parse_expr(parser_t* parser); -/* Parse a single block. */ -void parser_parse_blk(parser_t* parser); +tree_t* parser_parse(parser_t* parser); -/* Parse the given tokens. */ -void parser_parse(parser_t* parser); +/* Parse with the given parser. */ +void parser_run(parser_t* parser); #endif -- cgit v1.2.3