diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-01 17:18:54 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-01 17:18:54 +0000 |
commit | 9e761324895d098a87f0ba66b7eb1794cd3ed6b4 (patch) | |
tree | b46b0eb0eb91f6784d586acb8611495de81b92e4 /c_parser/include | |
parent | 2e5cacc6633a6973f8e96adc6bafa633487fc2a1 (diff) | |
download | Compiler-9e761324895d098a87f0ba66b7eb1794cd3ed6b4.tar.gz Compiler-9e761324895d098a87f0ba66b7eb1794cd3ed6b4.zip |
Finished parser
Diffstat (limited to 'c_parser/include')
-rw-r--r-- | c_parser/include/ast_base.hpp | 6 | ||||
-rw-r--r-- | c_parser/include/ast_declaration.hpp | 16 | ||||
-rw-r--r-- | c_parser/include/ast_expression.hpp | 6 | ||||
-rw-r--r-- | c_parser/include/ast_function.hpp | 20 | ||||
-rw-r--r-- | c_parser/include/ast_primitives.hpp | 12 | ||||
-rw-r--r-- | c_parser/include/ast_statement.hpp | 123 | ||||
-rw-r--r-- | c_parser/include/ast_top.hpp | 10 |
7 files changed, 76 insertions, 117 deletions
diff --git a/c_parser/include/ast_base.hpp b/c_parser/include/ast_base.hpp index b793a9b..9451609 100644 --- a/c_parser/include/ast_base.hpp +++ b/c_parser/include/ast_base.hpp @@ -5,12 +5,12 @@ #include <iostream> #include <vector> -class ast_Base { +class Base { public: - virtual ~ast_Base() {} + virtual ~Base() {} virtual void print() const = 0; - virtual void push(const ast_Base* _var) const = 0; + virtual void push(const Base* _var) const = 0; }; #endif diff --git a/c_parser/include/ast_declaration.hpp b/c_parser/include/ast_declaration.hpp index 3778939..bfd3070 100644 --- a/c_parser/include/ast_declaration.hpp +++ b/c_parser/include/ast_declaration.hpp @@ -7,12 +7,12 @@ // Declaration that holds a list of declarations -class ast_DeclarationList : public ast_Base { +class DeclarationList : public Base { private: - mutable std::vector<const ast_Base*> dec_list; + mutable std::vector<const Base*> dec_list; public: - ast_DeclarationList(const ast_Base* _dec) { + DeclarationList(const Base* _dec) { dec_list.push_back(_dec); } @@ -22,17 +22,17 @@ public: } } - virtual void push(const ast_Base* _dec) const { + virtual void push(const Base* _dec) const { dec_list.push_back(_dec); } }; -class ast_VariableDeclaration : public ast_Base { +class VariableDeclaration : public Base { private: - mutable std::vector<const ast_Base*> var_list; + mutable std::vector<const Base*> var_list; public: - ast_VariableDeclaration(const ast_Base* _var) { + VariableDeclaration(const Base* _var) { var_list.push_back(_var); } @@ -42,7 +42,7 @@ public: } } - virtual void push(const ast_Base* _var) const { + virtual void push(const Base* _var) const { var_list.push_back(_var); } }; diff --git a/c_parser/include/ast_expression.hpp b/c_parser/include/ast_expression.hpp index 87db997..f67d2d7 100644 --- a/c_parser/include/ast_expression.hpp +++ b/c_parser/include/ast_expression.hpp @@ -6,16 +6,16 @@ #include <string> #include <iostream> -class ast_Expression : public ast_Base { +class Expression : public Base { private: public: - ast_Expression() {} + Expression() {} virtual void print() const { } - virtual void push(const ast_Base* _base) const { + virtual void push(const Base* _base) const { std::cerr << "Can't call this function for this type" << std::endl; (void)_base; } diff --git a/c_parser/include/ast_function.hpp b/c_parser/include/ast_function.hpp index 085957c..6fbcdee 100644 --- a/c_parser/include/ast_function.hpp +++ b/c_parser/include/ast_function.hpp @@ -6,13 +6,13 @@ #include <string> #include <iostream> -class ast_Function : public ast_Base { +class Function : public Base { private: std::string id; - const ast_Base* param; - const ast_Base* comp_statement; + const Base* param; + const Base* comp_statement; public: - ast_Function(const std::string& _id, const ast_Base* _param, const ast_Base* _comp_statement) : + Function(const std::string& _id, const Base* _param, const Base* _comp_statement) : id(_id), param(_param), comp_statement(_comp_statement) {} virtual void print() const { @@ -22,20 +22,20 @@ public: std::cout << "</Function>" << std::endl; } - virtual void push(const ast_Base* var) const { + virtual void push(const Base* var) const { std::cerr << "Error: Can't call this function on this class" << std::endl; (void)var; } }; -class ast_ParamList : public ast_Base { +class ParamList : public Base { private: - mutable std::vector<const ast_Base*> param_list; + mutable std::vector<const Base*> param_list; public: - ast_ParamList() {} + ParamList() {} - ast_ParamList(const ast_Base* param) { + ParamList(const Base* param) { param_list.push_back(param); } @@ -45,7 +45,7 @@ public: } } - virtual void push(const ast_Base* _var) const { + virtual void push(const Base* _var) const { param_list.push_back(_var); } }; diff --git a/c_parser/include/ast_primitives.hpp b/c_parser/include/ast_primitives.hpp index 5ae6d12..2eeaa19 100644 --- a/c_parser/include/ast_primitives.hpp +++ b/c_parser/include/ast_primitives.hpp @@ -5,33 +5,33 @@ #include <string> -class ast_Variable : public ast_Base { +class Variable : public Base { private: std::string id; public: - ast_Variable(const std::string& _id) : id(_id) {} + Variable(const std::string& _id) : id(_id) {} virtual void print() const { std::cout << "<Variable id=\"" << id << "\" />" << std::endl; } - virtual void push(const ast_Base* var) const { + virtual void push(const Base* var) const { std::cerr << "Error: Can't call this function on this class" << std::endl; (void)var; } }; -class ast_Parameter : public ast_Base { +class Parameter : public Base { private: std::string id; public: - ast_Parameter(const std::string& _id) : id(_id) {} + Parameter(const std::string& _id) : id(_id) {} virtual void print() const { std::cout << "<Parameter id=\"" << id << "\" />" << std::endl; } - virtual void push(const ast_Base* var) const { + virtual void push(const Base* var) const { std::cerr << "Error: Can't call this function on this class" << std::endl; (void)var; } diff --git a/c_parser/include/ast_statement.hpp b/c_parser/include/ast_statement.hpp index 224a809..4761efb 100644 --- a/c_parser/include/ast_statement.hpp +++ b/c_parser/include/ast_statement.hpp @@ -1,122 +1,81 @@ #ifndef AST_STATEMENT_HPP #define AST_STATEMENT_HPP -class ast_StatementList : public ast_Base { -protected: - mutable std::vector<const ast_Base*> statement_list; - -public: - ast_StatementList(const ast_Base* _statement) { - statement_list.push_back(_statement); - } - - virtual void print() const { - for(size_t i = 0; i < statement_list.size(); ++i) { - statement_list[i]->print(); - } - } +#include "ast.hpp" - virtual void push(const ast_Base* _statement) const { - statement_list.push_back(_statement); - } -}; - -class ast_Statement : public ast_Base { +class Statement : public Base { protected: - mutable std::vector<const ast_Base*> ast_list; + mutable std::vector<const Base*> list; public: - ast_Statement() {} + Statement() {} - ast_Statement(const ast_Base* _el) { - ast_list.push_back(_el); + Statement(const Base* _el) { + list.push_back(_el); } - ast_Statement(const ast_Base* _dec, const ast_Base* _statement) { - ast_list.push_back(_dec); - ast_list.push_back(_statement); + Statement(const Base* _dec, const Base* _statement) { + list.push_back(_dec); + list.push_back(_statement); } virtual void print() const { - for(size_t i = 0; i < ast_list.size(); ++i) { - ast_list[i]->print(); + for(size_t i = 0; i < list.size(); ++i) { + list[i]->print(); } } - virtual void push(const ast_Base* _var) const { - ast_list.push_back(_var); + virtual void push(const Base* _var) const { + list.push_back(_var); } }; -class ast_CompoundStatement : public ast_Statement { +class StatementList : public Statement { public: - ast_CompoundStatement() : ast_Statement() {} - ast_CompoundStatement(const ast_Base* _el) : ast_Statement(_el) {} - ast_CompoundStatement(const ast_Base* _dec, const ast_Base* _statement) : - ast_Statement(_dec, _statement) {} + StatementList(const Base* _statement) : Statement(_statement) {} +}; + +class CompoundStatement : public Statement { +public: + CompoundStatement() : Statement() {} + CompoundStatement(const Base* _el) : Statement(_el) {} + CompoundStatement(const Base* _dec, const Base* _statement) : + Statement(_dec, _statement) {} virtual void print() const override { std::cout << "<Scope>" << std::endl; - for(size_t i = 0; i < ast_list.size(); ++i) { - ast_list[i]->print(); + for(size_t i = 0; i < list.size(); ++i) { + list[i]->print(); } std::cout << "</Scope>" << std::endl; } }; -class ast_SelectionStatement : public ast_Statement { +class SelectionStatement : public Statement { public: - ast_SelectionStatement() : ast_Statement() {} - ast_SelectionStatement(const ast_Base* _el) : ast_Statement(_el) {} - ast_SelectionStatement(const ast_Base* _if, const ast_Base* _else) : - ast_Statement(_if, _else) {} - - virtual void print() const override { - for(size_t i = 0; i < ast_list.size(); ++i) { - ast_list[i]->print(); - } - } + SelectionStatement() : Statement() {} + SelectionStatement(const Base* _el) : Statement(_el) {} + SelectionStatement(const Base* _if, const Base* _else) : + Statement(_if, _else) {} }; -class ast_ExpressionStatement : public ast_Statement { +class ExpressionStatement : public Statement { public: - ast_ExpressionStatement() : ast_Statement() {} - ast_ExpressionStatement(const ast_Base* _el) : ast_Statement(_el) {} - ast_ExpressionStatement(const ast_Base* _if, const ast_Base* _else) : - ast_Statement(_if, _else) {} - - virtual void print() const override { - for(size_t i = 0; i < ast_list.size(); ++i) { - ast_list[i]->print(); - } - } + ExpressionStatement() : Statement() {} + ExpressionStatement(const Base* _el) : Statement(_el) {} }; -class ast_JumpStatement : public ast_Statement { +class JumpStatement : public Statement { public: - ast_JumpStatement() : ast_Statement() {} - ast_JumpStatement(const ast_Base* _el) : ast_Statement(_el) {} - ast_JumpStatement(const ast_Base* _if, const ast_Base* _else) : - ast_Statement(_if, _else) {} - - virtual void print() const override { - for(size_t i = 0; i < ast_list.size(); ++i) { - ast_list[i]->print(); - } - } + JumpStatement() : Statement() {} + JumpStatement(const Base* _el) : Statement(_el) {} }; -class ast_IterationStatement : public ast_Statement { +class IterationStatement : public Statement { public: - ast_IterationStatement() : ast_Statement() {} - ast_IterationStatement(const ast_Base* _el) : ast_Statement(_el) {} - ast_IterationStatement(const ast_Base* _if, const ast_Base* _else) : - ast_Statement(_if, _else) {} - - virtual void print() const override { - for(size_t i = 0; i < ast_list.size(); ++i) { - ast_list[i]->print(); - } - } + IterationStatement() : Statement() {} + IterationStatement(const Base* _el) : Statement(_el) {} + IterationStatement(const Base* _if, const Base* _else) : + Statement(_if, _else) {} }; #endif diff --git a/c_parser/include/ast_top.hpp b/c_parser/include/ast_top.hpp index 142dfb8..737ff58 100644 --- a/c_parser/include/ast_top.hpp +++ b/c_parser/include/ast_top.hpp @@ -8,17 +8,17 @@ class ast_Top { public: void print() { - for(size_t i = 0; i < ast_vec.size(); ++i) { - ast_vec[i]->print(); + for(size_t i = 0; i < vec.size(); ++i) { + vec[i]->print(); } } - void push(const ast_Base *stmnt) { - ast_vec.push_back(stmnt); + void push(const Base *stmnt) { + vec.push_back(stmnt); } private: - std::vector<const ast_Base *> ast_vec; + std::vector<const Base *> vec; }; #endif |