diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-02-17 14:44:53 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-02-17 14:44:53 +0000 |
commit | 6c4106967613cfebfe8582c84eacbf5b4110729f (patch) | |
tree | 5d42bc0d0eea785035f79f880b41c866b7924f19 /c_parser/include | |
parent | a60337264c2551fffc2b5aeea12f40a06b7cb0e9 (diff) | |
download | Compiler-6c4106967613cfebfe8582c84eacbf5b4110729f.tar.gz Compiler-6c4106967613cfebfe8582c84eacbf5b4110729f.zip |
Making functions work
Diffstat (limited to 'c_parser/include')
-rw-r--r-- | c_parser/include/ast.hpp | 1 | ||||
-rw-r--r-- | c_parser/include/ast_function.hpp | 31 | ||||
-rw-r--r-- | c_parser/include/ast_primitives.hpp | 13 |
3 files changed, 45 insertions, 0 deletions
diff --git a/c_parser/include/ast.hpp b/c_parser/include/ast.hpp index e17ab49..7292af2 100644 --- a/c_parser/include/ast.hpp +++ b/c_parser/include/ast.hpp @@ -2,6 +2,7 @@ #define AST_HPP #include "ast_base.hpp" +#include "ast_function.hpp" #include "ast_declaration.hpp" #include "ast_primitives.hpp" #include "ast_top.hpp" diff --git a/c_parser/include/ast_function.hpp b/c_parser/include/ast_function.hpp new file mode 100644 index 0000000..60a1670 --- /dev/null +++ b/c_parser/include/ast_function.hpp @@ -0,0 +1,31 @@ +#ifndef AST_FUNCTION_HPP +#define AST_FUNCTION_HPP + +#include "ast.hpp" + +#include <string> +#include <iostream> + +class ast_Function : public ast_Base { +private: + std::string name; + mutable std::vector<const ast_Base*> param_list; +public: + ast_Function(const std::string& _name) : name(_name) {} + ast_Function(const ast_Base* param) { + param_list.push_back(param); + } + + virtual void print() const { + std::cout << "<Function id=\"" << name << "\">" << std::endl; + for(size_t i = 0; i < param_list.size(); ++i) { + param_list[i]->print(); + } + } + + virtual void push(const ast_Base* var) const { + param_list.push_back(var); + } +}; + +#endif diff --git a/c_parser/include/ast_primitives.hpp b/c_parser/include/ast_primitives.hpp index 21629e7..d878780 100644 --- a/c_parser/include/ast_primitives.hpp +++ b/c_parser/include/ast_primitives.hpp @@ -18,4 +18,17 @@ public: virtual void push(const ast_Base* var) const {} }; +class ast_Parameter : public ast_Base { +private: + std::string id; +public: + ast_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 {} +}; + #endif |