Compare commits

..

8 Commits

Author SHA1 Message Date
dabd3fd86f Slightly change the valid test input file
All checks were successful
Validate the build / validate-build (push) Successful in 27s
2025-04-02 13:00:06 +02:00
ccf8f52b6e add functionality to main to parse and print the ast 2025-04-02 13:00:01 +02:00
35c471f8d4 Partial parser implementation 2025-04-02 12:59:55 +02:00
44fab4c678 Fix incorrect size comparison in lexer_consume_n
The buffer length len and the requested number of tokens n are mixed up
in an invalid comparison. This causes all valid requests for n < len
tokens to be denied and all invalid requests for n > len tokens to be
accepted. This may cause a buffer overflow if the caller requests more
characters than they provide space for.
2025-04-02 12:59:55 +02:00
bcc1569b39 Add a parser combinator to parse a delimited list 2025-04-02 12:59:55 +02:00
5746ef1c5a Add basic parser combinators 2025-04-02 12:59:51 +02:00
2cab530eed Add "primitive" parsers for all the non-trivia tokens in the lexer grammar 2025-04-02 12:59:47 +02:00
7ac4eac37f Add basic parser utilities 2025-04-02 12:59:41 +02:00
10 changed files with 37 additions and 34 deletions

View File

@ -1,6 +1,6 @@
#include "error.h"
#include "lexer.h"
#include "parser.h"
#include "parser/parser.h"
#include "tokenlist.h"
#include <limits.h>

View File

@ -1,11 +0,0 @@
#ifndef INCLUDE_SRC_PARSER_H_
#define INCLUDE_SRC_PARSER_H_
#include "ast.h"
#include "error.h"
#include "parser_util.h"
#include "tokenlist.h"
parse_result_t parse(tokenlist_entry_t *current);
#endif // INCLUDE_SRC_PARSER_H_

View File

@ -1,4 +1,4 @@
#include "parser_combinators.h"
#include "combinators.h"
// Parse a list of the given parser delimited by the given token id. Does not
// store the delimiters in the parent node

View File

@ -1,4 +1,7 @@
#include "parser_util.h"
#ifndef INCLUDE_PARSER_COMBINATORS_H_
#define INCLUDE_PARSER_COMBINATORS_H_
#include "util.h"
typedef parse_result_t (*parser_t)(tokenlist_entry_t *);
@ -18,3 +21,5 @@ parse_result_t parse_list(tokenlist_entry_t *current, node_id_t id,
// wraps the parsed nodes in a new parent node.
parse_result_t parse_consecutive(tokenlist_entry_t *current, node_id_t id,
parser_t parsers[]);
#endif // INCLUDE_PARSER_COMBINATORS_H_

View File

@ -1,10 +1,10 @@
#include "parser.h"
#include "ast.h"
#include "lexer.h"
#include "parser_combinators.h"
#include "parser_primitives.h"
#include "parser_util.h"
#include "tokenlist.h"
#include "../ast.h"
#include "../lexer.h"
#include "../tokenlist.h"
#include "combinators.h"
#include "primitives.h"
#include "util.h"
parse_result_t parse_number(tokenlist_entry_t *current) {
parser_t parsers[] = {parse_octal, parse_decimal, parse_hexadecimal,

9
src/parser/parser.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef INCLUDE_PARSER_PARSER_H_
#define INCLUDE_PARSER_PARSER_H_
#include "../tokenlist.h"
#include "util.h"
parse_result_t parse(tokenlist_entry_t *current);
#endif // INCLUDE_PARSER_PARSER_H_

View File

@ -1,5 +1,5 @@
#include "parser_primitives.h"
#include "ast.h"
#include "primitives.h"
#include "../ast.h"
#include <string.h>
parse_result_t parse_identifier(tokenlist_entry_t *current) {

View File

@ -1,7 +1,7 @@
#ifndef INCLUDE_SRC_PARSER_PRIMITIVES_H_
#define INCLUDE_SRC_PARSER_PRIMITIVES_H_
#ifndef INCLUDE_PARSER_PRIMITIVES_H_
#define INCLUDE_PARSER_PRIMITIVES_H_
#include "parser_util.h"
#include "util.h"
parse_result_t parse_identifier(tokenlist_entry_t *current);
parse_result_t parse_decimal(tokenlist_entry_t *current);
@ -26,4 +26,4 @@ parse_result_t parse_dot(tokenlist_entry_t *current);
parse_result_t parse_register(tokenlist_entry_t *current);
parse_result_t parse_section(tokenlist_entry_t *current);
#endif // INCLUDE_SRC_PARSER_PRIMITIVES_H_
#endif // INCLUDE_PARSER_PRIMITIVES_H_

View File

@ -1,5 +1,5 @@
#include "parser_util.h"
#include "tokenlist.h"
#include "util.h"
#include "../tokenlist.h"
error_t *err_parse_no_match =
&(error_t){.message = "parsing failed to find the correct token sequence"};

View File

@ -1,9 +1,9 @@
#ifndef INCLUDE_SRC_PARSER_UTIL_H_
#define INCLUDE_SRC_PARSER_UTIL_H_
#ifndef INCLUDE_PARSER_UTIL_H_
#define INCLUDE_PARSER_UTIL_H_
#include "ast.h"
#include "error.h"
#include "tokenlist.h"
#include "../ast.h"
#include "../error.h"
#include "../tokenlist.h"
typedef struct parse_result {
error_t *err;
@ -24,4 +24,4 @@ tokenlist_entry_t *skip_insignificant(tokenlist_entry_t *);
extern error_t *err_parse_no_match;
#endif // INCLUDE_SRC_PARSER_UTIL_H_
#endif // INCLUDE_PARSER_UTIL_H_