Fixed operator parsing to return trees instead of flat representations. Fixed evaluator to not loop over equations.
This commit is contained in:
parent
f47ec0d522
commit
6c18c197c6
@ -281,19 +281,19 @@ namespace chaiscript
|
||||
|
||||
|
||||
if (this->children.size() > 1) {
|
||||
for (int i = static_cast<int>(this->children.size())-3; i >= 0; i -= 2) {
|
||||
Boxed_Value lhs = this->children[i]->eval(t_ss);
|
||||
Boxed_Value lhs = this->children[0]->eval(t_ss);
|
||||
|
||||
Operators::Opers oper = Operators::to_operator(this->children[i+1]->text);
|
||||
Operators::Opers oper = Operators::to_operator(this->children[1]->text);
|
||||
|
||||
if (oper != Operators::invalid && lhs.get_type_info().is_arithmetic() && retval.get_type_info().is_arithmetic())
|
||||
if (oper != Operators::invalid && lhs.get_type_info().is_arithmetic() &&
|
||||
retval.get_type_info().is_arithmetic())
|
||||
{
|
||||
try {
|
||||
retval = Boxed_Numeric::do_oper(oper, lhs, retval);
|
||||
} catch (const std::exception &) {
|
||||
throw exception::eval_error("Error with unsupported arithmetic assignment operation");
|
||||
}
|
||||
} else if (this->children[i+1]->text == "=") {
|
||||
} else if (this->children[1]->text == "=") {
|
||||
try {
|
||||
if (lhs.is_undef()) {
|
||||
retval = t_ss.call_function("clone", retval);
|
||||
@ -301,7 +301,7 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
try {
|
||||
retval = t_ss.call_function(this->children[i+1]->text, lhs, retval);
|
||||
retval = t_ss.call_function(this->children[1]->text, lhs, retval);
|
||||
}
|
||||
catch(const exception::dispatch_error &){
|
||||
throw exception::eval_error(std::string("Mismatched types in equation") + (lhs.is_const()?", lhs is const.":"."));
|
||||
@ -311,7 +311,7 @@ namespace chaiscript
|
||||
throw exception::eval_error("Can not clone right hand side of equation");
|
||||
}
|
||||
}
|
||||
else if (this->children[i+1]->text == ":=") {
|
||||
else if (this->children[1]->text == ":=") {
|
||||
if (lhs.is_undef() || type_match(lhs, retval)) {
|
||||
lhs.assign(retval);
|
||||
} else {
|
||||
@ -320,16 +320,14 @@ namespace chaiscript
|
||||
}
|
||||
else {
|
||||
try {
|
||||
retval = t_ss.call_function(this->children[i+1]->text, lhs, retval);
|
||||
retval = t_ss.call_function(this->children[1]->text, lhs, retval);
|
||||
} catch(const exception::dispatch_error &){
|
||||
throw exception::eval_error("Can not find appropriate '" + this->children[i+1]->text + "'");
|
||||
}
|
||||
throw exception::eval_error("Can not find appropriate '" + this->children[1]->text + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct Var_Decl_AST_Node : public AST_Node {
|
||||
|
@ -352,7 +352,7 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a floating point value from input, without skipping initial whitespace
|
||||
* Reads a hex value from input, without skipping initial whitespace
|
||||
*/
|
||||
bool Hex_() {
|
||||
bool retval = false;
|
||||
@ -385,7 +385,7 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a floating point value from input, without skipping initial whitespace
|
||||
* Reads a binary value from input, without skipping initial whitespace
|
||||
*/
|
||||
bool Binary_() {
|
||||
bool retval = false;
|
||||
@ -1716,7 +1716,6 @@ namespace chaiscript
|
||||
+ std::string(ast_node_type_to_string(m_operators[t_precedence])) + " expression",
|
||||
File_Position(m_line, m_col), *m_filename);
|
||||
}
|
||||
} while (Operator_Helper(t_precedence));
|
||||
|
||||
switch (m_operators[t_precedence]) {
|
||||
case(AST_Node_Type::Comparison) :
|
||||
@ -1755,6 +1754,7 @@ namespace chaiscript
|
||||
default:
|
||||
throw exception::eval_error("Internal error: unhandled ast_node", File_Position(m_line, m_col), *m_filename);
|
||||
}
|
||||
} while (Operator_Helper(t_precedence));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user