Compare commits

..

27 Commits

Author SHA1 Message Date
0177d86054 Modify main to use the new print ast functionality
All checks were successful
Validate the build / validate-build (push) Successful in 26s
2025-04-01 23:55:32 +02:00
faaf4111bb TODO: REVIEW THIS FUNCTION Add function to print AST 2025-04-01 23:54:31 +02:00
71f1b0aa64 Add more grammar rules to the parser
All checks were successful
Validate the build / validate-build (push) Successful in 26s
2025-04-01 23:43:05 +02:00
c3fcb917fc Add a parser combinator to parse a delimited list 2025-04-01 23:39:48 +02:00
333991e05e make parse_success always skip past trivia in the tokenlist 2025-04-01 23:39:01 +02:00
a1b4cc21f4 TODO: REVIEW ME AND WRITE PROPER MESSAGE
Fix lexer issue where consuming n tokens always fails if there are n
tokens and always succeeds if they aren't n tokens
2025-04-01 23:36:08 +02:00
80957326bc fix operands list grammar rule 2025-04-01 23:22:29 +02:00
da51d66bb2 Match ast nodes to new grammar 2025-04-01 22:09:36 +02:00
42445338a4 Update grammar to match implementation 2025-04-01 22:01:33 +02:00
03fc44f339 Use new validator function for parse_token calls on all primitives
Also adds new validated primitives for NODE_SECTION and NODE_REGISTER
2025-04-01 21:54:27 +02:00
eec02d6237 Fix incorrect error returned in parse_consecutive 2025-04-01 21:53:19 +02:00
39a4b2b0a7 Fix memory leak in ast.
If a node has children the array of children was never freed.
2025-04-01 21:51:48 +02:00
048b8fcf9d Extend parse_token to accept an optional validator function 2025-04-01 21:10:19 +02:00
1b21364939 Expose err_parse_no_match in parser_util.h 2025-04-01 20:57:34 +02:00
41114d7f9c Add basic parser combinators 2025-04-01 20:05:35 +02:00
dfc89a7493 Add "primitive" parsers for all the semantic tokens in the lexer grammar 2025-04-01 20:03:53 +02:00
43a62095bf Add basic parser utilities 2025-04-01 20:03:28 +02:00
ff7d33bf2a Add functions to skip over trivia in a tokenlist 2025-04-01 19:55:00 +02:00
208f30ac48 Expand AST node ids to support the lexer tokens and grammar rules 2025-04-01 19:26:54 +02:00
988b54aee3 Adjust grammar so that it never depends on newline tokens 2025-04-01 19:26:27 +02:00
ed1491db33 Fix parse_token to add the correct information to a parse node 2025-04-01 17:20:50 +02:00
0bf4ba3a1b Fix ast nodes now containing token entry instead of token 2025-04-01 17:20:32 +02:00
e632764bf2 Partial parser implementation 2025-04-01 17:16:21 +02:00
a298e99895 Add invalid ast node id 2025-04-01 15:06:42 +02:00
126905a092 FIXME REORDER COMMIT -- Change main so it can parse the ast
FIXME THIS COMMIT NEEDS TO BE REORDERED
FIXME THIS COMMIT NEEDS TO BE REORDERED
FIXME THIS COMMIT NEEDS TO BE REORDERED
FIXME THIS COMMIT NEEDS TO BE REORDERED
2025-04-01 15:06:20 +02:00
0f6efa8050 Add basic AST functionality
All checks were successful
Validate the build / validate-build (push) Successful in 24s
2025-03-31 18:43:50 +02:00
36af377ba0 Add a parser grammar
Currently this is a subset of the grammar, enough to get reasonable work
going.
2025-03-31 18:43:34 +02:00
4 changed files with 7 additions and 25 deletions

View File

@ -34,7 +34,7 @@ parse_result_t parse_section_directive(tokenlist_entry_t *current) {
parse_result_t parse_directive(tokenlist_entry_t *current) {
parser_t parsers[] = {parse_dot, parse_section_directive, nullptr};
return parse_consecutive(current, NODE_DIRECTIVE, parsers);
return parse_consecutive(current, NODE_LABEL, parsers);
}
parse_result_t parse_instruction(tokenlist_entry_t *current) {

View File

@ -50,8 +50,7 @@ parse_result_t parse_list(tokenlist_entry_t *current, node_id_t id,
}
parse_result_t parse_any(tokenlist_entry_t *current, parser_t parsers[]) {
parser_t parser;
while ((parser = *parsers++)) {
for (parser_t parser = *parsers; parser; parser = *parsers++) {
parse_result_t result = parser(current);
if (result.err == nullptr)
return result;
@ -107,8 +106,7 @@ parse_result_t parse_consecutive(tokenlist_entry_t *current, node_id_t id,
all->id = id;
parser_t parser;
while ((parser = *parsers++) && current) {
for (parser_t parser = *parsers; parser && current; parser = *parsers++) {
result = parser(current);
if (result.err) {
ast_node_free(all);

View File

@ -62,19 +62,9 @@ parse_result_t parse_dot(tokenlist_entry_t *current) {
return parse_token(current, TOKEN_DOT, NODE_DOT, nullptr);
}
const char *registers[] = {
// 64-bit registers
"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi", "r8", "r9", "r10",
"r11", "r12", "r13", "r14", "r15",
// 32-bit registers
"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "r8d", "r9d",
"r10d", "r11d", "r12d", "r13d", "r14d", "r15d",
// 16-bit registers
"ax", "cx", "dx", "bx", "sp", "bp", "si", "di", "r8w", "r9w", "r10w",
"r11w", "r12w", "r13w", "r14w", "r15w",
// 8-bit low registers
"al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil", "r8b", "r9b", "r10b",
"r11b", "r12b", "r13b", "r14b", "r15b", nullptr};
const char *registers[] = {"rax", "rcx", "rdx", "rbx", "rsp", "rbp",
"rsi", "rdi", "r8", "r9", "r10", "r11",
"r12", "r13", "r14", "r15", nullptr};
bool is_register_token(lexer_token_t *token) {
for (size_t i = 0; registers[i] != nullptr; ++i)
if (strcmp(token->value, registers[i]) == 0)
@ -91,7 +81,4 @@ bool is_section_token(lexer_token_t *token) {
return strcmp(token->value, "section") == 0;
}
parse_result_t parse_section(tokenlist_entry_t *current) {
return parse_token(current, TOKEN_IDENTIFIER, NODE_SECTION,
is_section_token);
}
parse_result_t parse_section(tokenlist_entry_t *current) {}

View File

@ -1,7 +1,4 @@
.section text
_start:
mov eax, ebx
mov eax, 555 ; move 555 into eax
push 0o777
xor eax, 0xDEADBEEF