summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Sencha-lang/Parser.cpp')
-rw-r--r--Sencha-lang/Parser.cpp33
1 files changed, 12 insertions, 21 deletions
diff --git a/Sencha-lang/Parser.cpp b/Sencha-lang/Parser.cpp
index 7f124eb..d7ab86f 100644
--- a/Sencha-lang/Parser.cpp
+++ b/Sencha-lang/Parser.cpp
@@ -143,34 +143,26 @@ ASTStatement * Parser::statement(ASTNode * parent)
else if(is_type())
- {
+ {
+ DeclarationStatement * declaration = new DeclarationStatement(parent, context);
std::string identifier = tok_value;
report("Identifier: " + identifier + "\n");
read_next();
+ declaration->add_name(identifier);
+
if(accept("="))
{
ASTExpression * ae = expr(stat);
-
- context->add(identifier, ae->evaluate());
-
- stat->add_expression(ae);
+ declaration->add_right_value(ae);
report(" := \n");
- if(accept(";"))
- {
- report("Variable definition\n");
- return stat;
- }
+ accept(";");
}
-
if(accept(";"))
{
- context->add(identifier, SenchaObject());
- report("Variable definition\n");
- stat->add_expression(new ConstantExpression(stat, SenchaObject(), identifier));
- return stat;
+ report("Variable declaration\n");
}
if(expect("("))
@@ -181,6 +173,7 @@ ASTStatement * Parser::statement(ASTNode * parent)
argc++;
is_type();
report("function argument: " + tok_value + "\n");
+ declaration->add_argument(tok_value);
read_next();
if(peek(")"))
{
@@ -193,17 +186,14 @@ ASTStatement * Parser::statement(ASTNode * parent)
if(!accept(";"))
{
report("function body:\n");
- statement(stat);
+ declaration->add_body(statement(stat));
report("function definition\n");
}
- else
- {
- expect(";");
- report("function declaration\n");
- }
}
+ delete stat;
+ return declaration;
}
else if(accept("if"))
@@ -266,6 +256,7 @@ ASTExpression * Parser::prim_expr(ASTNode * expression)
SenchaObject variable;
//TODO is it right?
string name = current_token.value;
+
variable = context->get(name);
variable.name = name;
ce = new ConstantExpression(expression, variable, name);