aboutsummaryrefslogtreecommitdiffstats
path: root/c_parser
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-02-13 14:42:11 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-02-13 14:42:11 +0000
commit494894c2072494f199214acc5855155baae6d174 (patch)
treeb9d38c7e078f2d25177d4758faf246314df00183 /c_parser
parentda008507b6e0409b7a06984194a5eb9b149caac9 (diff)
downloadCompiler-494894c2072494f199214acc5855155baae6d174.tar.gz
Compiler-494894c2072494f199214acc5855155baae6d174.zip
Working kind of
Diffstat (limited to 'c_parser')
-rw-r--r--c_parser/include/ast.hpp4
-rw-r--r--c_parser/include/ast_base.hpp (renamed from c_parser/include/ast_expression.hpp)4
-rw-r--r--c_parser/include/ast_base.hpp~ (renamed from c_parser/include/ast_expression.hpp~)7
-rw-r--r--c_parser/include/ast_declaration.hpp4
-rw-r--r--c_parser/include/ast_declaration.hpp~11
-rw-r--r--c_parser/src/#parser_main.cpp#13
-rw-r--r--c_parser/src/c_parser.y10
-rw-r--r--c_parser/src/parser_main.cpp2
8 files changed, 17 insertions, 38 deletions
diff --git a/c_parser/include/ast.hpp b/c_parser/include/ast.hpp
index 834ad44..91c0796 100644
--- a/c_parser/include/ast.hpp
+++ b/c_parser/include/ast.hpp
@@ -1,9 +1,9 @@
#ifndef AST_HPP
#define AST_HPP
-#include "ast_expression.hpp"
+#include "ast_base.hpp"
#include "ast_declaration.hpp"
-extern const Expression *parseAST();
+extern const ast_Base *parseAST();
#endif
diff --git a/c_parser/include/ast_expression.hpp b/c_parser/include/ast_base.hpp
index 493781e..7f8d56e 100644
--- a/c_parser/include/ast_expression.hpp
+++ b/c_parser/include/ast_base.hpp
@@ -4,9 +4,9 @@
#include <string>
#include <iostream>
-class Expression {
+class ast_Base {
public:
- virtual ~Expression() {}
+ virtual ~ast_Base() {}
virtual void print() const = 0;
};
diff --git a/c_parser/include/ast_expression.hpp~ b/c_parser/include/ast_base.hpp~
index 7bd9814..ef0368a 100644
--- a/c_parser/include/ast_expression.hpp~
+++ b/c_parser/include/ast_base.hpp~
@@ -1,9 +1,12 @@
#ifndef AST_EXPRESSION_HPP
#define AST_EXPRESSION_HPP
-class Expression {
+#include <string>
+#include <iostream>
+
+class ast_base {
public:
- virtual ~Expression() {}
+ virtual ~ast_base() {}
virtual void print() const = 0;
};
diff --git a/c_parser/include/ast_declaration.hpp b/c_parser/include/ast_declaration.hpp
index cce68b6..2eed3a2 100644
--- a/c_parser/include/ast_declaration.hpp
+++ b/c_parser/include/ast_declaration.hpp
@@ -3,11 +3,11 @@
#include "ast.hpp"
-class Declaration : public Expression {
+class ast_Declaration : public ast_Base {
private:
const std::string id;
public:
- Declaration(const std::string& _id) : id(_id) {}
+ ast_Declaration(const std::string& _id) : id(_id) {}
virtual void print() const override {
std::cout << id;
diff --git a/c_parser/include/ast_declaration.hpp~ b/c_parser/include/ast_declaration.hpp~
deleted file mode 100644
index ba786fc..0000000
--- a/c_parser/include/ast_declaration.hpp~
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef AST_DECLARATION_HPP
-#define AST_DECLARATION_HPP
-
-#include "ast.hpp"
-
-class Declaration : public Expression {
-private:
- const
-};
-
-#endif
diff --git a/c_parser/src/#parser_main.cpp# b/c_parser/src/#parser_main.cpp#
deleted file mode 100644
index 3dff644..0000000
--- a/c_parser/src/#parser_main.cpp#
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "ast.hpp"
-
-#include <iostream>
-
-int main(int argc, char *argv[]) {
-
- const Expression *ast = parseAST();
- ast->print();
-
- std::cout << std::endl;
-
- return 0;
-}
diff --git a/c_parser/src/c_parser.y b/c_parser/src/c_parser.y
index 7d36fc6..351cbf2 100644
--- a/c_parser/src/c_parser.y
+++ b/c_parser/src/c_parser.y
@@ -1,7 +1,7 @@
%code requires{
#include "ast.hpp"
-extern const Expression *g_root; // A way of getting the AST out
+extern const ast_Base *g_root; // A way of getting the AST out
//! This is to fix problems when generating C++
// We are declaring the functions provided by Flex, so
@@ -14,7 +14,7 @@ void yyerror(const char *);
// Represents the value associated with any kind of
// AST node.
%union{
- const Expression *expr;
+ const ast_Base *expr;
// double number;
std::string *string;
}
@@ -36,13 +36,13 @@ STMNT_LIST : STMNT { $$ = $1; }
STMNT : DCLRTN { $$ = $1; }
-DCLRTN : T_KEYWORD T_IDENTIFIER T_SC { $$ = new Declaration(*$2); }
+DCLRTN : T_KEYWORD T_IDENTIFIER T_SC { $$ = new ast_Declaration(*$2); }
%%
-const Expression *g_root; // Definition of variable (to match declaration earlier)
+const ast_Base *g_root; // Definition of variable (to match declaration earlier)
-const Expression *parseAST() {
+const ast_Base *parseAST() {
g_root = 0;
yyparse();
return g_root;
diff --git a/c_parser/src/parser_main.cpp b/c_parser/src/parser_main.cpp
index 3dff644..4dd25eb 100644
--- a/c_parser/src/parser_main.cpp
+++ b/c_parser/src/parser_main.cpp
@@ -4,7 +4,7 @@
int main(int argc, char *argv[]) {
- const Expression *ast = parseAST();
+ const ast_Base *ast = parseAST();
ast->print();
std::cout << std::endl;