diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/parser.h | 33 | ||||
-rw-r--r-- | src/include/tree.h | 7 |
2 files changed, 27 insertions, 13 deletions
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 diff --git a/src/include/tree.h b/src/include/tree.h index 3dfb5be..ba1f5a5 100644 --- a/src/include/tree.h +++ b/src/include/tree.h @@ -5,6 +5,7 @@ typedef enum TREE_TYPE { TREE_TYPE_BLOCK, + TREE_TYPE_EXPR, TREE_TYPE_LINT, TREE_TYPE_LSTR, TREE_TYPE_TAG, @@ -30,6 +31,12 @@ typedef struct TREE { struct TREE* nxt; } block; + /* Expression. */ + struct TREE_DATA_EXPR { + /* The contents of the expression. */ + struct TREE* val; + } expr; + /* Literal integer. */ struct TREE_DATA_LINT { int val; |