summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2012-12-22 09:07:13 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2012-12-22 09:07:13 +0100
commit509a416bf9d74cc0bc679dcd9956bc438d142362 (patch)
tree60fc36172e9d73efde1837313b9b6ed93a45b2a0
parent88ccccc4fe1afdaf287327376c72d66db949255b (diff)
downloadsencha-lang-509a416bf9d74cc0bc679dcd9956bc438d142362.tar.gz
sencha-lang-509a416bf9d74cc0bc679dcd9956bc438d142362.tar.bz2
sencha-lang-509a416bf9d74cc0bc679dcd9956bc438d142362.tar.xz
sencha-lang-509a416bf9d74cc0bc679dcd9956bc438d142362.zip
More visiting methods. Gonna catch them all!
-rw-r--r--Sencha-lang/AST/BasicExpression.h1
-rw-r--r--Sencha-lang/ASTInspector.cpp60
-rw-r--r--Sencha-lang/ASTInspector.h11
-rw-r--r--Sencha-lang/Parser.cpp10
-rw-r--r--Sencha-lang/main.cpp9
5 files changed, 70 insertions, 21 deletions
diff --git a/Sencha-lang/AST/BasicExpression.h b/Sencha-lang/AST/BasicExpression.h
index 505b045..e946ae9 100644
--- a/Sencha-lang/AST/BasicExpression.h
+++ b/Sencha-lang/AST/BasicExpression.h
@@ -19,7 +19,6 @@ public:
virtual void execute();
virtual void execute_quietly();
std::string get_operator() { return oper; }
-
std::string debug() ;
virtual void accept(Visitor * visitor);
diff --git a/Sencha-lang/ASTInspector.cpp b/Sencha-lang/ASTInspector.cpp
index 2040007..b4ab03a 100644
--- a/Sencha-lang/ASTInspector.cpp
+++ b/Sencha-lang/ASTInspector.cpp
@@ -40,13 +40,14 @@ void ASTInspector::visit(Visitable * node)
}
}
-void ASTInspector::visit(ConstantExpression * constant_expression)
+void ASTInspector::visit(ConstantExpression & constant_expression)
{
this->occurences["ConstantExpression"]++;
depth_level++;
std::string visit_notes = "";
visit_notes += "Constant expression of value:\n";
- visit_notes += constant_expression->value.repr() + "\n";
+ visit_notes += constant_expression.value.repr() + "\n";
+
write_report(visit_notes);
depth_level--;
}
@@ -59,30 +60,58 @@ void ASTInspector::forget_everything()
number_of_visits = 0;
}
-void ASTInspector::visit(BasicExpression * basic_expression)
+void ASTInspector::visit(BasicExpression & basic_expression)
{
this->occurences["BasicExpression"]++;
depth_level++;
std::string visit_notes = "";
visit_notes += "Basic expression:\n";
- visit_notes += "Executing " + basic_expression->oper + " on:\n";
+ visit_notes += "Executing " + basic_expression.get_operator() + " on:\n";
write_report(visit_notes);
- basic_expression->children[0]->accept(this);
- basic_expression->children[1]->accept(this);
+ basic_expression.children[0]->accept(this);
+ basic_expression.children[1]->accept(this);
write_report("End of basic expression\n");
depth_level--;
}
-void ASTInspector::visit(PostfixExpression * node)
+void ASTInspector::visit(PostfixExpression & postfix_expression)
{
+ this->occurences["PostfixExpression"]++;
+ depth_level++;
+ std::string visit_notes = "";
+ visit_notes += "Postfix expression:\n";
+
+ visit_notes += postfix_expression.name;
+ visit_notes += " operating on arguments:\n";
+
+ for(auto argument : postfix_expression.arguments)
+ {
+ argument->accept(this);
+ }
+
+ write_report("End of postfix expression\n");
+ depth_level--;
}
-void ASTInspector::visit(WhileNode * node)
+
+void ASTInspector::visit(WhileNode & while_node)
{
+ this->occurences["WhileNode"]++;
+ depth_level++;
+ std::string visit_notes = "";
+ visit_notes += "WhileNode:\n";
+
+ for(auto child: while_node.children)
+ {
+ child->accept(this);
+ }
+
+ write_report("End of while node\n");
+ depth_level--;
}
void ASTInspector::write_report(std::string visit_notes)
@@ -97,6 +126,21 @@ void ASTInspector::write_report(std::string visit_notes)
}
+void ASTInspector::visit(ProgramNode & program)
+{
+
+}
+
+void ASTInspector::visit(BasicStatement & basic_statement)
+{
+
+}
+
+void ASTInspector::visit(DeclarationStatement & declaration_statement)
+{
+
+}
+
std::string ASTInspector::compute_indent()
{
std::string indentation = "";
diff --git a/Sencha-lang/ASTInspector.h b/Sencha-lang/ASTInspector.h
index 92052fd..c69d234 100644
--- a/Sencha-lang/ASTInspector.h
+++ b/Sencha-lang/ASTInspector.h
@@ -30,10 +30,13 @@ private:
unsigned int depth_level;
std::string compute_indent();
void write_report(std::string visit_notes);
- void visit(ConstantExpression * node);
- void visit(BasicExpression * node);
- void visit(PostfixExpression * node);
- void visit(WhileNode * node);
+ void visit(ConstantExpression & node);
+ void visit(BasicExpression & node);
+ void visit(PostfixExpression & node);
+ void visit(WhileNode & node);
+ void visit(ProgramNode & node);
+ void visit(BasicStatement & node);
+ void visit(DeclarationStatement & node);
};
diff --git a/Sencha-lang/Parser.cpp b/Sencha-lang/Parser.cpp
index e30e337..d4a25b8 100644
--- a/Sencha-lang/Parser.cpp
+++ b/Sencha-lang/Parser.cpp
@@ -349,8 +349,6 @@ ASTExpression * Parser::prim_expr(ASTNode * expression)
ASTExpression * Parser::postfix_expr(ASTNode * expression)
{
- //TODO implement postfix expression ASAP
-
auto name = tok_value;
if(is_function_name())
{
@@ -395,7 +393,7 @@ ASTExpression * Parser::mul_expr(ASTNode * expression)
be->set_right_operand(mul_expr(be));
}
- if(be->oper == "")
+ if(be->get_operator() == "")
{
ASTExpression * ae;
ae = static_cast<ASTExpression *>(be->children[0]);
@@ -426,7 +424,7 @@ ASTExpression * Parser::add_expr(ASTNode * expression)
be->set_right_operand(add_expr(be));
}
- if(be->oper == "")
+ if(be->get_operator() == "")
{
ASTExpression * ae;
ae = static_cast<ASTExpression *>(be->children[0]);
@@ -457,7 +455,7 @@ ASTExpression * Parser::rel_expr(ASTNode * expression)
be->set_right_operand(rel_expr(be));
}
- if(be->oper == "")
+ if(be->get_operator() == "")
{
ASTExpression * ae;
ae = static_cast<ASTExpression *>(be->children[0]);
@@ -489,7 +487,7 @@ ASTExpression * Parser::eq_expr(ASTNode * expression)
be->set_right_operand(eq_expr(be));
}
- if(be->oper == "")
+ if(be->get_operator() == "")
{
ASTExpression * ae;
ae = static_cast<ASTExpression *>(be->children[0]);
diff --git a/Sencha-lang/main.cpp b/Sencha-lang/main.cpp
index 64e0de5..d91ece4 100644
--- a/Sencha-lang/main.cpp
+++ b/Sencha-lang/main.cpp
@@ -7,6 +7,7 @@
#include "Parser.h"
#include "Tests/TestLexer.h"
#include "Context.h"
+#include "ASTInspector.h"
#include "Tests/tests.h"
using namespace std;
@@ -131,7 +132,7 @@ void interactive()
context.register_function("tan", s_tan);
Parser parser(&context);
-
+ ASTInspector inspector;
vector<Token> tokens;
string input;
@@ -157,7 +158,10 @@ void interactive()
//cout << parser.show_tokens() << endl;
//cout << "My tree:\n";
//cout << parser.program->debug();
- cout << parser.context->debug();
+ inspector.visit(parser.program);
+ //cout << parser.context->debug();
+ cout << inspector.get_report();
+ inspector.forget_everything();
}
}
@@ -188,6 +192,7 @@ int main(int argc, char *argv[])
context.register_function("tan", s_tan);
Parser parser(&context);
+
vector<Token> tokens;
string line;
ifstream input_file (name);