diff options
author | kugwa <kugwa2000@gmail.com> | 2015-12-09 18:40:17 +0800 |
---|---|---|
committer | kugwa <kugwa2000@gmail.com> | 2015-12-09 18:40:17 +0800 |
commit | c36891c71e9eee530fd84e516b12ac0b12dded5f (patch) | |
tree | 01f6441a3e2a8f7cb0451c8992808760094cbe9a | |
parent | 78b5848db27fda1d7a8bfc1b1c5afb99d87ebfa1 (diff) | |
download | compiler2015-c36891c71e9eee530fd84e516b12ac0b12dded5f.tar compiler2015-c36891c71e9eee530fd84e516b12ac0b12dded5f.tar.gz compiler2015-c36891c71e9eee530fd84e516b12ac0b12dded5f.tar.bz2 compiler2015-c36891c71e9eee530fd84e516b12ac0b12dded5f.tar.lz compiler2015-c36891c71e9eee530fd84e516b12ac0b12dded5f.tar.xz compiler2015-c36891c71e9eee530fd84e516b12ac0b12dded5f.tar.zst compiler2015-c36891c71e9eee530fd84e516b12ac0b12dded5f.zip |
process_{relop_expr, var_ref} -> check_{relop_expr, var_ref}
-rw-r--r-- | src/ast.h | 4 | ||||
-rw-r--r-- | src/semantic-analysis.c | 46 |
2 files changed, 44 insertions, 6 deletions
@@ -113,10 +113,6 @@ typedef struct CcmmcValueId_struct { // struct SymbolTableEntry *symbolTableEntry; } CcmmcValueId; -typedef struct CcmmcValueType_struct { - char *name; -} CcmmcValueType; - typedef struct CcmmcValueConst_struct { CcmmcKindConst kind; union { diff --git a/src/semantic-analysis.c b/src/semantic-analysis.c index bdaa090..798c26a 100644 --- a/src/semantic-analysis.c +++ b/src/semantic-analysis.c @@ -337,6 +337,21 @@ static bool decl_typedef(CcmmcAst *type_decl, CcmmcSymbolTable *table) return any_error; } +static bool check_var_ref(CcmmcAst *ref, CcmmcSymbolTable *table) +{ + bool any_error = false; + + if (ccmmc_symbol_table_retrieve(table, ref->value_id.name) == NULL) { + fprintf(stderr, ERROR("ID `%s' undeclared."), + ref->line_number, ref->value_id.name); + return true; + } + if (ref->value_id.kind == CCMMC_KIND_ID_ARRAY) { + + } + return any_error; +} + static bool check_relop_expr(CcmmcAst *expr, CcmmcSymbolTable *table) { bool any_error = false; @@ -472,14 +487,41 @@ static bool decl_variable( return any_error; } +static bool process_block(CcmmcAst*, CcmmcSymbolTable*); static bool process_statement(CcmmcAst *stmt, CcmmcSymbolTable *table) { bool any_error = false; if (stmt->type_node == CCMMC_AST_NODE_NUL) - return any_error; + return false; + if (stmt->type_node == CCMMC_AST_NODE_BLOCK) + return process_block(stmt, table) || any_error; assert(stmt->type_node == CCMMC_AST_NODE_STMT); + switch(stmt->value_stmt.kind) { + case CCMMC_KIND_STMT_WHILE: + any_error = check_relop_expr(stmt->child, table) || any_error; + any_error = process_statement(stmt->child->right_sibling, table) || any_error; + break; + case CCMMC_KIND_STMT_FOR: + case CCMMC_KIND_STMT_ASSIGN: + any_error = check_var_ref(stmt->child, table) || any_error; + any_error = check_relop_expr(stmt->child->right_sibling, table) || any_error; + break; + case CCMMC_KIND_STMT_IF: + any_error = check_relop_expr(stmt->child, table) || any_error; + any_error = process_statement(stmt->child->right_sibling, table) || any_error; + break; + case CCMMC_KIND_STMT_FUNCTION_CALL: + break; + case CCMMC_KIND_STMT_RETURN: + if (stmt->child != NULL) + any_error = check_relop_expr(stmt->child, table) || any_error; + break; + default: + assert(false); + } + return any_error; } @@ -530,7 +572,7 @@ static bool process_block(CcmmcAst *block, CcmmcSymbolTable *table) // Process the list of statements if (child != NULL && child->type_node == CCMMC_AST_NODE_STMT_LIST) { for (CcmmcAst *stmt = child->child; stmt != NULL; stmt = stmt->right_sibling) - any_error = process_statement(stmt, table) | any_error; + any_error = process_statement(stmt, table) || any_error; } // Pop this scope |