diff --git a/lab/.clang-format b/lab/.clang-format new file mode 100644 index 0000000..6784402 --- /dev/null +++ b/lab/.clang-format @@ -0,0 +1,13 @@ +--- +BasedOnStyle: LLVM +ColumnLimit: 120 +IndentWidth: 8 +UseTab: ForIndentation +BreakBeforeBraces: Linux + +AlignEscapedNewlines: DontAlign +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +BinPackParameters: false +IndentCaseLabels: false +... diff --git a/lab/symbol_table.c b/lab/symbol_table.c new file mode 100644 index 0000000..48275ca --- /dev/null +++ b/lab/symbol_table.c @@ -0,0 +1,58 @@ +#include + +// ------------------------------------------------------------------- Type + +enum mcc_type_kind { + MCC_TYPE_BOOL, + MCC_TYPE_INT, + MCC_TYPE_FLOAT, + MCC_TYPE_STRING, + MCC_TYPE_BOOL_ARRAY, + MCC_TYPE_INT_ARRAY, + MCC_TYPE_FLOAT_ARRAY, + MCC_TYPE_STRING_ARRAY, +}; + +struct mcc_type { + enum mcc_type_kind kind; + size_t array_size; +}; + +// ------------------------------------------------------------------- AST Declaration + +enum mcc_ast_statement_type { + MCC_AST_STATEMENT_TYPE_DECLARATION, +}; + +struct mcc_ast_statement { + enum mcc_ast_statement_type type; + union { + // MCC_AST_STATEMENT_TYPE_DECLARATION + struct { + const char *identifier; + struct mcc_type identifier_type; + }; + + // ... + }; +}; + +// ------------------------------------------------------------------- Symbol Table + +struct mcc_symbol_table_entry { + const char *identifier; + struct mcc_ast_statement *declaration; +}; + +struct mcc_symbol_table { + struct mcc_symbol_table_entry *entries; + size_t entries_count; + size_t entries_capacity; +}; + +// Creation: Traverse the AST using the visitor pattern, looking for +// declarations. Each decleration yields a new entry in our symbol table. + +// Supporting scopes: +// - Add scope enter/exit visitor callbacks +// - Add parent pointer to symbol table