added "if" parser rule and IfNode class, "if_more" still in progress... changed ForNode::evaluate() and IfNode::evaluate() to use Node::evaluateChildren()
git-svn-id: svn://anubis/fart/trunk@352 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
fc33024b28
commit
9712dab456
@ -134,30 +134,7 @@ NodeRef ForNode::evaluate()
|
|||||||
|
|
||||||
while (m_nodes[1]->evaluate()->getInteger() != 0)
|
while (m_nodes[1]->evaluate()->getInteger() != 0)
|
||||||
{
|
{
|
||||||
for (vector<NodeRef>::iterator it = m_children.begin();
|
evaluateChildren(eval);
|
||||||
it != m_children.end();
|
|
||||||
it++)
|
|
||||||
{
|
|
||||||
NodeRef n = (*it)->evaluate();
|
|
||||||
if ( ! n.isNull() )
|
|
||||||
{
|
|
||||||
if (typeid(*n) == typeid(EvaluatePropagateNode))
|
|
||||||
{
|
|
||||||
for (vector<NodeRef>::iterator it2
|
|
||||||
= n->getChildren().begin();
|
|
||||||
it2 != n->getChildren().end();
|
|
||||||
it2++)
|
|
||||||
{
|
|
||||||
eval->addChild(*it2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(*it)->evaluateChildren(n);
|
|
||||||
eval->addChild(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_nodes[2].isNull())
|
if (!m_nodes[2].isNull())
|
||||||
{
|
{
|
||||||
@ -168,3 +145,16 @@ NodeRef ForNode::evaluate()
|
|||||||
return eval;
|
return eval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NodeRef IfNode::evaluate()
|
||||||
|
{
|
||||||
|
NodeRef eval = new EvaluatePropagateNode();
|
||||||
|
|
||||||
|
int if_val = m_test_expr->evaluate()->getInteger();
|
||||||
|
|
||||||
|
if (if_val != 0)
|
||||||
|
{
|
||||||
|
evaluateChildren(eval);
|
||||||
|
}
|
||||||
|
|
||||||
|
return eval;
|
||||||
|
}
|
||||||
|
@ -731,6 +731,19 @@ class ForNode : public Node
|
|||||||
NodeRef m_nodes[3];
|
NodeRef m_nodes[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class IfNode : public Node
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IfNode(NodeRef test_expr, NodeRef elses)
|
||||||
|
{
|
||||||
|
m_test_expr = test_expr;
|
||||||
|
m_elses = elses;
|
||||||
|
}
|
||||||
|
virtual NodeRef evaluate();
|
||||||
|
protected:
|
||||||
|
NodeRef m_test_expr, m_elses;
|
||||||
|
};
|
||||||
|
|
||||||
/* this class is only used to hold a set of items coming out of a class's
|
/* this class is only used to hold a set of items coming out of a class's
|
||||||
* evaluate() from above. the evaluateChildren() top-level method will
|
* evaluate() from above. the evaluateChildren() top-level method will
|
||||||
* propagate children of this class up to the level of their parent */
|
* propagate children of this class up to the level of their parent */
|
||||||
|
@ -246,6 +246,7 @@ general_item: transform_block { $$ = $1; }
|
|||||||
| shape_definition { $$ = $1; }
|
| shape_definition { $$ = $1; }
|
||||||
| shape { $$ = $1; }
|
| shape { $$ = $1; }
|
||||||
| for { $$ = $1; }
|
| for { $$ = $1; }
|
||||||
|
| if { $$ = $1; }
|
||||||
| stmt_expression { $$ = $1; }
|
| stmt_expression { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -657,6 +658,18 @@ for: FOR LPAREN maybe_expression SEMICOLON bool_expression SEMICOLON maybe_expre
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
if: IF LPAREN bool_expression RPAREN LCURLY general_items RCURLY if_more {
|
||||||
|
$$ = new IfNode($3, $8);
|
||||||
|
$$->addChildren($6);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
if_more: /* empty */
|
||||||
|
| ELSIF LPAREN bool_expression RPAREN LCURLY general_items RCURLY if_more {
|
||||||
|
}
|
||||||
|
| ELSE LCURLY general_items RCURLY {
|
||||||
|
}
|
||||||
|
;
|
||||||
%%
|
%%
|
||||||
|
|
||||||
refptr<Node> parse(const char * fileName, refptr<Scope> scope)
|
refptr<Node> parse(const char * fileName, refptr<Scope> scope)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user