/* Copyright (c) 2024 Freya Murphy */ #ifndef __PARSE_H__ #define __PARSE_H__ #include "lex.h" #include #include #include /// /// reference /// enum reference_type { REF_NONE, REF_OFFESET, REF_TARGET, }; struct reference { enum reference_type type; /// symbol name char name[MAX_LEX_LENGTH]; /// integer addend int64_t addend; }; struct const_expr { char name[MAX_LEX_LENGTH]; uint32_t value; }; struct ins_expr { /// pesudo instructions can return /// more than one instruction size_t ins_len; struct mips_instruction ins[2]; /// instructions can reference symbols. /// instruction `n` will be paried with reference `n` struct reference ref[2]; }; enum expr_type { EXPR_DIRECTIVE, EXPR_CONSTANT, EXPR_INS, EXPR_LABEL, }; struct expr { enum expr_type type; union { // directive struct mips_directive directive; // constant struct const_expr constant; // instruction struct ins_expr ins; // label char label[MAX_LEX_LENGTH]; }; }; struct parser { struct lexer *lexer; struct token peek; }; /* get the next expression in the parser */ int parser_next(struct parser *parser, struct expr *expr); /* initalize the base parser */ int parser_init(struct lexer *lexer, struct parser *parser); /* free the base parser */ void parser_free(struct parser *parser); #endif /* __PARSE_H__ */