summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Parser.cpp
diff options
context:
space:
mode:
authorJustyna Att Ilczuk <justyna.ilczuk@gmail.com>2012-12-09 17:42:13 +0100
committerJustyna Att Ilczuk <justyna.ilczuk@gmail.com>2012-12-09 17:42:13 +0100
commitfc7f656bc27ea146f2d28f721a4cb4a9aac6e266 (patch)
tree1cf2bf527e2f70994036200b1f06fe86d0dcad05 /Sencha-lang/Parser.cpp
parentc86374997f0a678d21199a0999fabbecc3e09c23 (diff)
downloadsencha-lang-fc7f656bc27ea146f2d28f721a4cb4a9aac6e266.tar.gz
sencha-lang-fc7f656bc27ea146f2d28f721a4cb4a9aac6e266.tar.bz2
sencha-lang-fc7f656bc27ea146f2d28f721a4cb4a9aac6e266.tar.xz
sencha-lang-fc7f656bc27ea146f2d28f721a4cb4a9aac6e266.zip
If statements and postfix expressions like function calls, yeah!
Diffstat (limited to 'Sencha-lang/Parser.cpp')
-rw-r--r--Sencha-lang/Parser.cpp99
1 files changed, 64 insertions, 35 deletions
diff --git a/Sencha-lang/Parser.cpp b/Sencha-lang/Parser.cpp
index d7ab86f..3f4b03c 100644
--- a/Sencha-lang/Parser.cpp
+++ b/Sencha-lang/Parser.cpp
@@ -128,6 +128,18 @@ bool Parser::is_type()
return false;
}
}
+
+bool Parser::is_function_name()
+{
+ if(tok_value == "print")
+ {
+ //check in registered functions
+ read_next();
+ return true;
+ }
+ else
+ return false;
+}
ASTStatement * Parser::statement(ASTNode * parent)
{
@@ -197,10 +209,17 @@ ASTStatement * Parser::statement(ASTNode * parent)
}
else if(accept("if"))
- {
- //stuff
- //TODO implement that
- return stat;
+ {
+ IfNode * ifStatement = new IfNode(parent);
+ ifStatement->add_condition(expr(ifStatement));
+ ifStatement->add_body(statement(parent));
+ if(accept("else"))
+ {
+ ifStatement->add_else_block(statement(parent));
+ }
+
+ delete stat;
+ return ifStatement;
}
else if(accept("while"))
{
@@ -244,12 +263,26 @@ ASTExpression * Parser::prim_expr(ASTNode * expression)
read_next();
}
else if(current_token.get_type() == t_literal)
- {
-
+ {
report("Character literal: " + tok_value + "\n");
ce = new ConstantExpression(expression, tok_value);
read_next();
}
+ else if(current_token.get_type() == t_keyword)
+ {
+ 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();
+ }
+ }
else if(current_token.get_type() == t_symbol)
{
report("variable: " + tok_value + "\n");
@@ -284,41 +317,37 @@ ASTExpression * Parser::prim_expr(ASTNode * expression)
ASTExpression * Parser::postfix_expr(ASTNode * expression)
{
//TODO implement postfix expression ASAP
- BasicExpression * be = new BasicExpression(expression);
- prim_expr(be);
- if(accept("["))
- {
- expr(be);
- expect("]");
- report(" [] ");
-
- }
- else if(accept("("))
- {
- if(!accept(")"))
- {
- expr(be);
- report("function argument\n");
- while(accept(","))
- {
- expr(be);
- report("function argument\n");
- }
-
- expect(")");
- }
- report("FUNC_CALL\n");
- }
-
- //TODO implement postfix_expression
- return be;
+ auto name = tok_value;
+ if(is_function_name())
+ {
+ PostfixExpression * function_call = new PostfixExpression(expression);
+ function_call->set_name(name);
+ if(accept("("))
+ {
+ if(!accept(")"))
+ {
+
+ 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;
+ }
+ }
+ return prim_expr(expression);
}
ASTExpression * Parser::mul_expr(ASTNode * expression)
{
BasicExpression * be = new BasicExpression(expression);
- be->set_left_operand(prim_expr(be));
+ be->set_left_operand(postfix_expr(be));
if(peek("*") || peek("/"))
{
if(accept("*"))