Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Alexander Hirsch
703602-Compiler-Construction
Commits
9d2386b3
Commit
9d2386b3
authored
Apr 16, 2021
by
Alexander Hirsch
Browse files
Add symbol table lab notes
parent
26c6f726
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
0 deletions
+71
-0
lab/.clang-format
lab/.clang-format
+13
-0
lab/symbol_table.c
lab/symbol_table.c
+58
-0
No files found.
lab/.clang-format
0 → 100644
View file @
9d2386b3
---
BasedOnStyle: LLVM
ColumnLimit: 120
IndentWidth: 8
UseTab: ForIndentation
BreakBeforeBraces: Linux
AlignEscapedNewlines: DontAlign
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
BinPackParameters: false
IndentCaseLabels: false
...
lab/symbol_table.c
0 → 100644
View file @
9d2386b3
#include <stdlib.h>
// ------------------------------------------------------------------- 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment