diff options
author | Justyna Ilczuk <justyna.ilczuk@gmail.com> | 2012-12-22 11:18:47 +0100 |
---|---|---|
committer | Justyna Ilczuk <justyna.ilczuk@gmail.com> | 2012-12-22 11:18:47 +0100 |
commit | f0bc0e235ba712809cd72559527c194f480a62bc (patch) | |
tree | 7455597d611c68088da1fc1ff8a1fd4977bc5594 /Sencha-lang | |
parent | 4d7205920055139596a07e8a74f7c6e4f79f698f (diff) | |
download | sencha-lang-f0bc0e235ba712809cd72559527c194f480a62bc.tar.gz sencha-lang-f0bc0e235ba712809cd72559527c194f480a62bc.tar.bz2 sencha-lang-f0bc0e235ba712809cd72559527c194f480a62bc.tar.xz sencha-lang-f0bc0e235ba712809cd72559527c194f480a62bc.zip |
Ready to merge visit branch with master!
Diffstat (limited to 'Sencha-lang')
-rw-r--r-- | Sencha-lang/Parser.cpp | 69 | ||||
-rw-r--r-- | Sencha-lang/Parser.h | 3 | ||||
-rw-r--r-- | Sencha-lang/Tests/tests.h | 2 | ||||
-rw-r--r-- | Sencha-lang/main.cpp | 3 |
4 files changed, 24 insertions, 53 deletions
diff --git a/Sencha-lang/Parser.cpp b/Sencha-lang/Parser.cpp index d4a25b8..36a3c82 100644 --- a/Sencha-lang/Parser.cpp +++ b/Sencha-lang/Parser.cpp @@ -5,7 +5,6 @@ Parser::Parser(Context * context) {
this->context = context; error_message = "***ERRORS DURING PARSING***\n"; - report_message = "***PARSER REPORT***\n"; position_in_stream = 0;
in_statement = false;
program = static_cast<ProgramNode *>(tree.root);
@@ -22,7 +21,7 @@ void Parser::erase_all() tree.delete_all_children();
tree.root = new ProgramNode();
error_message = "***ERRORS DURING PARSING***\n";
- report_message = "***PARSER REPORT***\n";
+
position_in_stream = 0;
in_statement = false;
program = static_cast<ProgramNode *>(tree.root);
@@ -47,10 +46,6 @@ void Parser::add_tokens(vector<Token> tokens) }
}
-void Parser::report(string s) -{ - report_message += s ; -} void Parser::error(string s) { @@ -131,18 +126,13 @@ bool Parser::is_type() bool Parser::is_function_name()
{
- //check in registered functions
- //cout << tok_value << " is it registered?" << endl;
-
if(context->registered_functions.count(tok_value) == 1)
{
- //cout << "Yes" << endl;
read_next();
return true;
}
else
{
- //cout << "No" << endl;
return false;
}
@@ -165,7 +155,7 @@ ASTStatement * Parser::statement(ASTNode * parent) {
DeclarationStatement * declaration = new DeclarationStatement(parent, context); std::string identifier = tok_value;
- report("Identifier: " + identifier + "\n");
+
read_next();
declaration->add_name(identifier);
@@ -174,15 +164,9 @@ ASTStatement * Parser::statement(ASTNode * parent) {
ASTExpression * ae = expr(stat);
declaration->add_right_value(ae);
-
- report(" := \n");
accept(";");
}
- if(accept(";"))
- {
- report("Variable declaration\n");
- }
if(expect("("))
{
@@ -191,7 +175,7 @@ ASTStatement * Parser::statement(ASTNode * parent) {
argc++;
is_type();
- report("function argument: " + tok_value + "\n");
+
declaration->add_argument(tok_value);
read_next();
if(peek(")"))
@@ -204,9 +188,9 @@ ASTStatement * Parser::statement(ASTNode * parent) if(!accept(";"))
{
- report("function body:\n");
+
declaration->add_body(statement(stat));
- report("function definition\n");
+
}
}
@@ -255,7 +239,7 @@ ASTStatement * Parser::statement(ASTNode * parent) stat->add_expression(expr(stat)); } expect(";"); - report("RETURN\n");
+
return stat; } @@ -273,13 +257,9 @@ ASTStatement * Parser::statement(ASTNode * parent) ASTExpression * Parser::prim_expr(ASTNode * expression) {
-
-
if(current_token.get_type() == t_integer) - { - report("Number: " + tok_value + "\n");
-
+ {
ConstantExpression * ce;
ce = new ConstantExpression(expression, std::atoi(tok_value.c_str()));
read_next();
@@ -287,15 +267,13 @@ ASTExpression * Parser::prim_expr(ASTNode * expression) }
else if(current_token.get_type() == t_float)
{
- report("Number: " + tok_value + "\n");
ConstantExpression * ce;
ce = new ConstantExpression(expression, std::atof(tok_value.c_str()));
read_next();
return ce;
} else if(current_token.get_type() == t_literal) - { - report("Character literal: " + tok_value + "\n");
+ {
ConstantExpression * ce;
ce = new ConstantExpression(expression, tok_value);
read_next();
@@ -306,13 +284,13 @@ ASTExpression * Parser::prim_expr(ASTNode * expression) ConstantExpression * ce;
if(tok_value == "true")
{
- report("Boolean: " + tok_value + "\n");
+
ce = new ConstantExpression(expression, SenchaObject(true));
read_next();
}
else if (tok_value == "false")
{
- report("Boolean: " + tok_value + "\n");
+
ce = new ConstantExpression(expression, SenchaObject(false));
read_next();
}
@@ -320,7 +298,6 @@ ASTExpression * Parser::prim_expr(ASTNode * expression) }
else if(current_token.get_type() == t_symbol)
{
- report("variable: " + tok_value + "\n");
string name = current_token.value;
VariableExpression * ve;
@@ -330,10 +307,9 @@ ASTExpression * Parser::prim_expr(ASTNode * expression) } else if(accept("(")) {
- report("( ");
BasicExpression * be; be = static_cast<BasicExpression *>(expr(expression));
- report(" ) "); + expect(")");
return be; } @@ -360,15 +336,14 @@ ASTExpression * Parser::postfix_expr(ASTNode * expression) {
function_call->add_argument(expr(function_call));
- report("function argument\n");
while(accept(","))
{
function_call->add_argument(expr(function_call));
- report("function argument\n");
+
}
expect(")");
}
- report("FUNC_CALL\n");
+
return function_call;
}
}
@@ -384,11 +359,11 @@ ASTExpression * Parser::mul_expr(ASTNode * expression) if(accept("*"))
{
be->set_operator("*");
- report(" *\n");
+
} else if(accept("/"))
{
be->set_operator("/");
- report(" /\n");
+
}
be->set_right_operand(mul_expr(be));
}
@@ -413,12 +388,12 @@ ASTExpression * Parser::add_expr(ASTNode * expression) { if(accept("+")) { - report(" +\n");
+
be->set_operator("+"); }
else if(accept("-")) { - report(" -\n");
+
be->set_operator("-"); }
be->set_right_operand(add_expr(be)); @@ -445,12 +420,12 @@ ASTExpression * Parser::rel_expr(ASTNode * expression) if(accept("<"))
{
be->set_operator("<");
- report(" <\n");
+
}
else if (accept(">"))
{
be->set_operator(">");
- report(" >\n");
+
} be->set_right_operand(rel_expr(be)); }
@@ -477,12 +452,12 @@ ASTExpression * Parser::eq_expr(ASTNode * expression) if(accept("==")) { be->set_operator("=="); - report("==\n"); + } else if(accept("!=")) { be->set_operator("!="); - report("!=\n"); + }
be->set_right_operand(eq_expr(be)); }
@@ -512,7 +487,7 @@ ASTExpression * Parser::expr(ASTNode * expression) assignment->add_lvalue(left);
assignment->add_rvalue(right);
assignment->set_name(name); - report(" :=\n");
+
return assignment; }
diff --git a/Sencha-lang/Parser.h b/Sencha-lang/Parser.h index b3389dd..824b7a8 100644 --- a/Sencha-lang/Parser.h +++ b/Sencha-lang/Parser.h @@ -18,7 +18,6 @@ class Parser virtual ~Parser(); void interpret(); - string report_message; string error_message; void add_tokens(vector<Token> tokens); string show_tokens();
@@ -43,7 +42,7 @@ class Parser bool is_type(); void error(string s); - void report(string s); + ASTStatement * statement(ASTNode * node); diff --git a/Sencha-lang/Tests/tests.h b/Sencha-lang/Tests/tests.h index 6282788..160799f 100644 --- a/Sencha-lang/Tests/tests.h +++ b/Sencha-lang/Tests/tests.h @@ -54,7 +54,7 @@ void test_parser() cout << "<<<Parsing number: " << i << " >>>" << endl; cout << "Instructions: " << endl ; cout << lines[i] << endl << endl; - cout << parser.report_message; + //cout << parser.report_message; cout << parser.error_message << endl; } diff --git a/Sencha-lang/main.cpp b/Sencha-lang/main.cpp index 8ae6c0d..df30ff6 100644 --- a/Sencha-lang/main.cpp +++ b/Sencha-lang/main.cpp @@ -153,11 +153,8 @@ void interactive() if(level_of_depth == 0) { parser.interpret(); parser.program->execute_last(); - //cout << parser.report_message << endl; //cout << parser.error_message << endl; //cout << parser.show_tokens() << endl; - //cout << "My tree:\n"; - //cout << parser.program->debug(); inspector.visit(parser.program); //cout << parser.context->debug(); |