summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2015-12-06 03:28:30 +0800
committerTing-Wei Lan <lantw44@gmail.com>2015-12-06 03:28:30 +0800
commita208a61d4bb3f73460e9a3a8cb3027bf972d22fe (patch)
tree46c10523c40ad95d7ccfd58815fe77c309efa226
parent1e1bfad8ec07ab2e928cb152c492f24f9fa4e2b3 (diff)
downloadcompiler2015-a208a61d4bb3f73460e9a3a8cb3027bf972d22fe.tar.gz
compiler2015-a208a61d4bb3f73460e9a3a8cb3027bf972d22fe.tar.zst
compiler2015-a208a61d4bb3f73460e9a3a8cb3027bf972d22fe.zip
We are going to do semantic analysis
-rw-r--r--Makefile.am2
-rw-r--r--src/main.c9
-rw-r--r--src/semantic-analysis.c15
-rw-r--r--src/semantic-analysis.h13
-rw-r--r--src/state.c4
-rw-r--r--src/state.h1
6 files changed, 44 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 7ffa745..ba04ef6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,6 +17,8 @@ parser_SOURCES = \
src/ast.c \
src/draw.h \
src/draw.c \
+ src/semantic-analysis.h \
+ src/semantic-analysis.c \
src/state.h \
src/state.c \
src/symbol-table.h \
diff --git a/src/main.c b/src/main.c
index 01ea19e..6af6c5e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -7,6 +7,7 @@ typedef void* yyscan_t;
#include "ast.h"
#include "common.h"
#include "draw.h"
+#include "semantic-analysis.h"
#include "state.h"
#include "libparser_a-parser.h"
@@ -67,6 +68,14 @@ int main (int argc, char **argv)
if (dump_ast != NULL && *dump_ast != '\0')
ccmmc_draw_ast(stdout, source_name, state->ast);
+ CcmmcSymbolTable table_struct;
+ state->table = &table_struct;
+ ccmmc_symbol_table_init(state->table);
+ if (ccmmc_semantic_check(state->ast, state->table))
+ puts("Parsing completed. No errors found.");
+ else
+ exit(1);
+
ccmmc_state_fini(state);
fclose(source_handle);
return 0;
diff --git a/src/semantic-analysis.c b/src/semantic-analysis.c
new file mode 100644
index 0000000..f7c1f9c
--- /dev/null
+++ b/src/semantic-analysis.c
@@ -0,0 +1,15 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "semantic-analysis.h"
+
+#include <stdbool.h>
+
+
+bool ccmmc_semantic_check (CcmmcAst *root, CcmmcSymbolTable *table)
+{
+ return true;
+}
+
+// vim: set sw=4 ts=4 sts=4 et:
diff --git a/src/semantic-analysis.h b/src/semantic-analysis.h
new file mode 100644
index 0000000..5e2264e
--- /dev/null
+++ b/src/semantic-analysis.h
@@ -0,0 +1,13 @@
+#ifndef CCMMC_HEADER_SEMANTIC_ANALYSIS_H
+#define CCMMC_HEADER_SEMANTIC_ANALYSIS_H
+
+#include "ast.h"
+#include "symbol-table.h"
+
+#include <stdbool.h>
+
+bool ccmmc_semantic_check (CcmmcAst *root,
+ CcmmcSymbolTable *table);
+
+#endif
+// vim: set sw=4 ts=4 sts=4 et:
diff --git a/src/state.c b/src/state.c
index cf41d56..8d1a2f3 100644
--- a/src/state.c
+++ b/src/state.c
@@ -8,6 +8,7 @@
void ccmmc_state_init (CcmmcState *state)
{
state->ast = NULL;
+ state->table = NULL;
state->line_number = 1;
state->any_error = false;
}
@@ -17,6 +18,9 @@ void ccmmc_state_fini (CcmmcState *state)
if (state->ast != NULL) {
// TODO: Free the AST
}
+ if (state->table != NULL) {
+ // TODO: Free the symbol table
+ }
}
// vim: set sw=4 ts=4 sts=4 et:
diff --git a/src/state.h b/src/state.h
index 5a88980..8e268d3 100644
--- a/src/state.h
+++ b/src/state.h
@@ -10,6 +10,7 @@
// All states of the compiler instance
typedef struct CcmmcState_struct {
CcmmcAst *ast;
+ CcmmcSymbolTable *table;
size_t line_number;
bool any_error;
} CcmmcState;