diff --git a/src/include/parser.h b/src/include/parser.h index 708f3c3..2ad30fd 100644 --- a/src/include/parser.h +++ b/src/include/parser.h @@ -3,17 +3,23 @@ #include "token.h" #include "ast.h" +#include "stack.h" typedef struct { size_t tokenc; // Number of tokens in tokenv; Token* ctoken; // The current token. Token** tokenv; // Token vector. AST* ast; // Abstract syntax tree. + Stack* ops; + Stack* nums; } Parser; Parser* parser_init(size_t tokenc, Token** tokenv); void parser_destroy(Parser* parser); +// Increment parser->ctoken. void parser_inc(Parser* parser); +// Step forward 1 token and add to stacks. +void parser_step(Parser* parser); #endif diff --git a/src/parser.c b/src/parser.c index fa6b0e1..f61daf1 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,3 +1,4 @@ +#include "include/stack.h" #include "include/util.h" #include "include/parser.h" @@ -8,6 +9,8 @@ Parser* parser_init(size_t tokenc, Token** tokenv) { parser->ctoken = *tokenv; parser->tokenv = tokenv; parser->ast = NULL; + parser->ops = stack_init(); + parser->nums = stack_init(); return parser; } @@ -19,6 +22,9 @@ void parser_destroy(Parser* parser) { for (int i = 0; i < parser->tokenc; i++) token_destroy(parser->tokenv[i]); ast_destroy(parser->ast); + + stack_destroy(parser->ops); + stack_destroy(parser->nums); }