From 063c40584ae78a396b558a5e2a08e3d871450c0b Mon Sep 17 00:00:00 2001 From: Quinn Stephens Date: Sun, 3 Nov 2024 19:12:47 -0500 Subject: [compiler] Parse and print procedure declarations Signed-off-by: Quinn Stephens --- include/lexer/token.h | 1 + include/parser/proc.h | 34 ++++++++++++++++++++++++++++++++++ include/parser/var.h | 24 ++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 include/parser/proc.h create mode 100644 include/parser/var.h (limited to 'include') diff --git a/include/lexer/token.h b/include/lexer/token.h index e0a9ea3..2ba5408 100644 --- a/include/lexer/token.h +++ b/include/lexer/token.h @@ -21,6 +21,7 @@ typedef enum { TK_CHARACTER, /* Keywords */ + TK_PROC, TK_TYPE, TK_ENUM, TK_STRUCT, diff --git a/include/parser/proc.h b/include/parser/proc.h new file mode 100644 index 0000000..0cc8471 --- /dev/null +++ b/include/parser/proc.h @@ -0,0 +1,34 @@ +/* + * Procedure parser. + * Copyright (c) 2023-2024, Quinn Stephens and the OSMORA team. + * Provided under the BSD 3-Clause license. + */ + +#ifndef _PARSER_PROC_H +#define _PARSER_PROC_H + +#include "list.h" +#include "hashmap.h" +#include "parser/var.h" + +struct parameter { + struct variable var; + struct list_entry list_entry; +}; + +struct procedure { + struct hashmap_entry hashmap_entry; + + char *name; + size_t name_len; + + struct hashmap vars; + struct list params; + + struct type *ret_typ; + int ret_n_ptrs; +}; + +void parse_proc(struct parser *ctx); + +#endif /* !_PARSER_PROC_H */ diff --git a/include/parser/var.h b/include/parser/var.h new file mode 100644 index 0000000..dd981f5 --- /dev/null +++ b/include/parser/var.h @@ -0,0 +1,24 @@ +/* + * Variable definitions. + * Copyright (c) 2023-2024, Quinn Stephens and the OSMORA team. + * Provided under the BSD 3-Clause license. + */ + +#ifndef _PARSER_VAR_H +#define _PARSER_VAR_H + +#include +#include "hashmap.h" +#include "parser/type.h" + +struct variable { + struct hashmap_entry hashmap_entry; + + char *name; + size_t name_len; + + struct type *typ; + int n_ptrs; +}; + +#endif /* !_PARSER_VAR_H */ -- cgit v1.2.3