summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Parser.cpp
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2012-12-22 11:18:47 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2012-12-22 11:18:47 +0100
commitf0bc0e235ba712809cd72559527c194f480a62bc (patch)
tree7455597d611c68088da1fc1ff8a1fd4977bc5594 /Sencha-lang/Parser.cpp
parent4d7205920055139596a07e8a74f7c6e4f79f698f (diff)
downloadsencha-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/Parser.cpp')
-rw-r--r--Sencha-lang/Parser.cpp69
1 files changed, 22 insertions, 47 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;
}