Added stacks to parser.

This commit is contained in:
Jacob Signorovitch 2024-10-26 11:02:42 -04:00
parent 5b345e6bf5
commit 1c0dd7aa0b
2 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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);
}