Move completely over to new operators
This commit is contained in:
parent
f4a680a582
commit
e14931f389
@ -22,9 +22,9 @@ namespace chaiscript
|
||||
* Types of AST nodes available to the parser and eval
|
||||
*/
|
||||
class Token_Type { public: enum Type { Error, Int, Float, Id, Char, Str, Eol, Fun_Call, Inplace_Fun_Call, Arg_List, Variable, Equation, Var_Decl,
|
||||
Comparison, Additive, Multiplicative, Unary_Minus, Unary_Plus, Not, Array_Call, Dot_Access, Quoted_String, Single_Quoted_String,
|
||||
Comparison, Additive, Multiplicative, Array_Call, Dot_Access, Quoted_String, Single_Quoted_String,
|
||||
Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File, Prefix, Break, Map_Pair, Value_Range,
|
||||
Inline_Range, Annotation, Try, Catch, Finally, Method, Attr_Decl, Shift, Equality, Bitwise_And, Bitwise_Xor, Bitwise_Or, Bitwise_Not,
|
||||
Inline_Range, Annotation, Try, Catch, Finally, Method, Attr_Decl, Shift, Equality, Bitwise_And, Bitwise_Xor, Bitwise_Or,
|
||||
Logical_And, Logical_Or}; };
|
||||
|
||||
namespace
|
||||
@ -34,9 +34,9 @@ namespace chaiscript
|
||||
*/
|
||||
const char *token_type_to_string(int tokentype) {
|
||||
const char *token_types[] = { "Internal Parser Error", "Int", "Float", "Id", "Char", "Str", "Eol", "Fun_Call", "Inplace_Fun_Call", "Arg_List", "Variable", "Equation", "Var_Decl",
|
||||
"Comparison", "Additive", "Multiplicative", "Unary_Minus", "Unary_Plus", "Not", "Array_Call", "Dot_Access", "Quoted_String", "Single_Quoted_String",
|
||||
"Comparison", "Additive", "Multiplicative", "Array_Call", "Dot_Access", "Quoted_String", "Single_Quoted_String",
|
||||
"Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Map_Pair", "Value_Range",
|
||||
"Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or", "Bitwise_Not",
|
||||
"Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or",
|
||||
"Logical_And", "Logical_Or"};
|
||||
|
||||
return token_types[tokentype];
|
||||
|
@ -334,78 +334,6 @@ namespace chaiscript
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates a unary negation
|
||||
*/
|
||||
template <typename Eval_System>
|
||||
Boxed_Value eval_unary_minus(Eval_System &ss, const TokenPtr &node) {
|
||||
Boxed_Value retval = eval_token(ss, node->children[0]);
|
||||
Param_List_Builder plb;
|
||||
plb << retval;
|
||||
plb << Boxed_Value(-1.0);
|
||||
|
||||
try {
|
||||
return ss.call_function("*", plb);
|
||||
}
|
||||
catch(std::exception &){
|
||||
throw Eval_Error("Can not find appropriate unary minus", node->children[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Should be unary minus
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates a unary negation
|
||||
*/
|
||||
template <typename Eval_System>
|
||||
Boxed_Value eval_unary_plus(Eval_System &ss, const TokenPtr &node) {
|
||||
Boxed_Value retval = eval_token(ss, node->children[0]);
|
||||
Param_List_Builder plb;
|
||||
plb << retval;
|
||||
|
||||
try {
|
||||
return ss.call_function("+", plb);
|
||||
}
|
||||
catch(std::exception &){
|
||||
throw Eval_Error("Can not find appropriate unary plus", node->children[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates a unary boolean not
|
||||
*/
|
||||
template <typename Eval_System>
|
||||
Boxed_Value eval_not(Eval_System &ss, const TokenPtr &node) {
|
||||
try {
|
||||
return Boxed_Value(!boxed_cast<bool>(eval_token(ss, node->children[0])));
|
||||
}
|
||||
catch (const bad_boxed_cast &) {
|
||||
throw Eval_Error("Boolean not('!') condition not boolean", node->children[0]);
|
||||
}
|
||||
/*
|
||||
* Should be like above, but use !
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates a unary boolean not
|
||||
*/
|
||||
template <typename Eval_System>
|
||||
Boxed_Value eval_bitwise_not(Eval_System &ss, const TokenPtr &node) {
|
||||
try {
|
||||
return Boxed_Value(~boxed_cast<int>(eval_token(ss, node->children[0])));
|
||||
}
|
||||
catch (const bad_boxed_cast &) {
|
||||
throw Eval_Error("Bitwise not condition not integer", node->children[0]);
|
||||
}
|
||||
/*
|
||||
* Should be like above, but use ~
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates any unary prefix
|
||||
*/
|
||||
@ -418,7 +346,7 @@ namespace chaiscript
|
||||
return ss.call_function(node->children[0]->text, plb);
|
||||
}
|
||||
catch(std::exception &){
|
||||
throw Eval_Error("Can not find appropriate prefix", node->children[0]);
|
||||
throw Eval_Error("Can not find appropriate unary '" + node->children[0]->text + "'", node->children[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1154,22 +1082,6 @@ namespace chaiscript
|
||||
return eval_array_call(ss, node);
|
||||
break;
|
||||
|
||||
case (Token_Type::Unary_Minus) :
|
||||
return eval_unary_minus(ss, node);
|
||||
break;
|
||||
|
||||
case (Token_Type::Unary_Plus) :
|
||||
return eval_unary_plus(ss, node);
|
||||
break;
|
||||
|
||||
case (Token_Type::Not) :
|
||||
return eval_not(ss, node);
|
||||
break;
|
||||
|
||||
case (Token_Type::Bitwise_Not) :
|
||||
return eval_bitwise_not(ss, node);
|
||||
break;
|
||||
|
||||
case (Token_Type::Prefix) :
|
||||
return eval_prefix(ss, node);
|
||||
break;
|
||||
|
@ -864,7 +864,7 @@ namespace chaiscript
|
||||
if (retval) {
|
||||
//todo: fix this. Hacky workaround for preventing substring matches
|
||||
if ((input_pos != input_end) && (disallow_prevention == false) && ((*input_pos == '+') || (*input_pos == '-') || (*input_pos == '*') || (*input_pos == '/')
|
||||
|| (*input_pos == '|') || (*input_pos == '&') || (*input_pos == '^') || (*input_pos == '=') || (*input_pos == '.'))) {
|
||||
|| (*input_pos == '|') || (*input_pos == '&') || (*input_pos == '^') || (*input_pos == '=') || (*input_pos == '.') || (*input_pos == '<') || (*input_pos == '>'))) {
|
||||
input_pos = start;
|
||||
col = prev_col;
|
||||
line = prev_line;
|
||||
@ -883,7 +883,7 @@ namespace chaiscript
|
||||
if (Symbol_(s)) {
|
||||
//todo: fix this. Hacky workaround for preventing substring matches
|
||||
if ((input_pos != input_end) && (disallow_prevention == false) && ((*input_pos == '+') || (*input_pos == '-') || (*input_pos == '*') || (*input_pos == '/')
|
||||
|| (*input_pos == '|') || (*input_pos == '&') || (*input_pos == '^') || (*input_pos == '=') || (*input_pos == '.'))) {
|
||||
|| (*input_pos == '|') || (*input_pos == '&') || (*input_pos == '^') || (*input_pos == '=') || (*input_pos == '.') || (*input_pos == '<') || (*input_pos == '>'))) {
|
||||
input_pos = start;
|
||||
col = prev_col;
|
||||
line = prev_line;
|
||||
@ -1511,41 +1511,41 @@ namespace chaiscript
|
||||
|
||||
build_match(Token_Type::Prefix, prev_stack_top);
|
||||
}
|
||||
else if (Char('-')) {
|
||||
else if (Char('-', true)) {
|
||||
retval = true;
|
||||
|
||||
if (!Operator(operators.size()-1)) {
|
||||
throw Eval_Error("Incomplete unary - expression", File_Position(line, col), filename);
|
||||
throw Eval_Error("Incomplete unary '-' expression", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
build_match(Token_Type::Unary_Minus, prev_stack_top);
|
||||
build_match(Token_Type::Prefix, prev_stack_top);
|
||||
}
|
||||
else if (Char('+')) {
|
||||
else if (Char('+', true)) {
|
||||
retval = true;
|
||||
|
||||
if (!Operator(operators.size()-1)) {
|
||||
throw Eval_Error("Incomplete unary + expression", File_Position(line, col), filename);
|
||||
throw Eval_Error("Incomplete unary '+' expression", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
build_match(Token_Type::Unary_Plus, prev_stack_top);
|
||||
build_match(Token_Type::Prefix, prev_stack_top);
|
||||
}
|
||||
else if (Char('!')) {
|
||||
else if (Char('!', true)) {
|
||||
retval = true;
|
||||
|
||||
if (!Operator(operators.size()-1)) {
|
||||
throw Eval_Error("Incomplete '!' expression", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
build_match(Token_Type::Not, prev_stack_top);
|
||||
build_match(Token_Type::Prefix, prev_stack_top);
|
||||
}
|
||||
else if (Char('~')) {
|
||||
else if (Char('~', true)) {
|
||||
retval = true;
|
||||
|
||||
if (!Operator(operators.size()-1)) {
|
||||
throw Eval_Error("Incomplete '~' expression", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
build_match(Token_Type::Bitwise_Not, prev_stack_top);
|
||||
build_match(Token_Type::Prefix, prev_stack_top);
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
Loading…
x
Reference in New Issue
Block a user