aboutsummaryrefslogtreecommitdiffstats
path: root/c_compiler/include/function.hpp
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-03-01 17:18:54 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-03-01 17:18:54 +0000
commit9e761324895d098a87f0ba66b7eb1794cd3ed6b4 (patch)
treeb46b0eb0eb91f6784d586acb8611495de81b92e4 /c_compiler/include/function.hpp
parent2e5cacc6633a6973f8e96adc6bafa633487fc2a1 (diff)
downloadCompiler-9e761324895d098a87f0ba66b7eb1794cd3ed6b4.tar.gz
Compiler-9e761324895d098a87f0ba66b7eb1794cd3ed6b4.zip
Finished parser
Diffstat (limited to 'c_compiler/include/function.hpp')
-rw-r--r--c_compiler/include/function.hpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/c_compiler/include/function.hpp b/c_compiler/include/function.hpp
new file mode 100644
index 0000000..6fbcdee
--- /dev/null
+++ b/c_compiler/include/function.hpp
@@ -0,0 +1,53 @@
+#ifndef AST_FUNCTION_HPP
+#define AST_FUNCTION_HPP
+
+#include "ast.hpp"
+
+#include <string>
+#include <iostream>
+
+class Function : public Base {
+private:
+ std::string id;
+ const Base* param;
+ const Base* comp_statement;
+public:
+ Function(const std::string& _id, const Base* _param, const Base* _comp_statement) :
+ id(_id), param(_param), comp_statement(_comp_statement) {}
+
+ virtual void print() const {
+ std::cout << "<Function id=\"" << id << "\">" << std::endl;
+ param->print();
+ comp_statement->print();
+ std::cout << "</Function>" << std::endl;
+ }
+
+ virtual void push(const Base* var) const {
+ std::cerr << "Error: Can't call this function on this class" << std::endl;
+ (void)var;
+ }
+};
+
+class ParamList : public Base {
+private:
+ mutable std::vector<const Base*> param_list;
+
+public:
+ ParamList() {}
+
+ ParamList(const Base* param) {
+ param_list.push_back(param);
+ }
+
+ virtual void print() const {
+ for(size_t i = 0; i < param_list.size(); ++i) {
+ param_list[i]->print();
+ }
+ }
+
+ virtual void push(const Base* _var) const {
+ param_list.push_back(_var);
+ }
+};
+
+#endif