diff --git a/boxedcpp/bootstrap.hpp b/boxedcpp/bootstrap.hpp index 0074d66..83b1c0c 100644 --- a/boxedcpp/bootstrap.hpp +++ b/boxedcpp/bootstrap.hpp @@ -231,6 +231,19 @@ P1 &prefixdecrement(P1 &p1) return (--p1); } +template +P1 &prefixnegate(P1 &p1) +{ + return (p1); +} + +template +P1 &prefixnot(P1 &p1) +{ + return (p1); +} + + //Add canonical forms of operators template void add_oper_equals(BoxedCPP_System &s) @@ -368,6 +381,8 @@ void add_opers_arithmetic_overload(BoxedCPP_System &s) register_function(s, &addsequal, "+="); register_function(s, &prefixincrement, "++"); register_function(s, &prefixdecrement, "--"); + register_function(s, &prefixnegate, "-"); + register_function(s, &prefixnot, "!"); } template diff --git a/wesley/wesley.hpp b/wesley/wesley.hpp index acc9849..f3c4f8a 100644 --- a/wesley/wesley.hpp +++ b/wesley/wesley.hpp @@ -14,14 +14,14 @@ class TokenType { public: enum Type { File, Whitespace, Identifier, Integer, Operator, Parens_Open, Parens_Close, Square_Open, Square_Close, Curly_Open, Curly_Close, Comma, Quoted_String, Single_Quoted_String, Carriage_Return, Semicolon, - Function_Def, Lambda_Def, Scoped_Block, Statement, Equation, Return, Expression, Term, Factor, Negate, Comment, + Function_Def, Lambda_Def, Scoped_Block, Statement, Equation, Return, Expression, Term, Factor, Negate, Not, Comment, Value, Fun_Call, Method_Call, Comparison, If_Block, While_Block, Boolean, Real_Number, Array_Call, Variable_Decl, Array_Init, For_Block, Prefix, Break }; }; const char *tokentype_to_string(int tokentype) { const char *token_types[] = {"File", "Whitespace", "Identifier", "Integer", "Operator", "Parens_Open", "Parens_Close", "Square_Open", "Square_Close", "Curly_Open", "Curly_Close", "Comma", "Quoted_String", "Single_Quoted_String", "Carriage_Return", "Semicolon", - "Function_Def", "Lambda_Def", "Scoped_Block", "Statement", "Equation", "Return", "Expression", "Term", "Factor", "Negate", "Comment", + "Function_Def", "Lambda_Def", "Scoped_Block", "Statement", "Equation", "Return", "Expression", "Term", "Factor", "Negate", "Not", "Comment", "Value", "Fun_Call", "Method_Call", "Comparison", "If_Block", "While_Block", "Boolean", "Real Number", "Array_Call", "Variable_Decl", "Array_Init", "For_Block", "Prefix", "Break" }; diff --git a/wesley/wesley_engine.hpp b/wesley/wesley_engine.hpp index 4171746..2418d40 100644 --- a/wesley/wesley_engine.hpp +++ b/wesley/wesley_engine.hpp @@ -111,6 +111,7 @@ public: Rule term(TokenType::Term); Rule factor(TokenType::Factor); Rule negate(TokenType::Negate); + Rule boolean_not(TokenType::Not); Rule prefix(TokenType::Prefix); Rule funcall(TokenType::Fun_Call); @@ -160,14 +161,15 @@ public: (Str("<=") >> expression) |(Str(">") >> expression) | (Str(">=") >> expression)); expression = term >> *((Str("+") >> term) | (Str("-") >> term)); term = factor >> *((Str("*") >> factor) | (Str("/") >> factor)); - factor = methodcall | arraycall | value | negate | prefix | (Ign(Str("+")) >> value); + factor = methodcall | arraycall | value | negate | boolean_not | prefix | (Ign(Str("+")) >> value); value = vardecl | arrayinit | block | paren_block | lambda_def | return_statement | break_statement | funcall | Id(TokenType::Identifier) | Id(TokenType::Real_Number) | Id(TokenType::Integer) | Id(TokenType::Quoted_String) | Id(TokenType::Single_Quoted_String) ; funcall = Id(TokenType::Identifier) >> Ign(Id(TokenType::Parens_Open)) >> ~(boolean >> *(Ign(Str("," )) >> boolean)) >> Ign(Id(TokenType::Parens_Close)); methodcall = value >> +(Ign(Str(".")) >> funcall); - negate = Ign(Str("-")) >> boolean; + negate = (Str("-") >> (boolean | arraycall)); + boolean_not = (Str("!") >> (boolean | arraycall)); prefix = (Str("++") >> (boolean | arraycall)) | (Str("--") >> (boolean | arraycall)); arraycall = value >> +((Ign(Id(TokenType::Square_Open)) >> boolean >> Ign(Id(TokenType::Square_Close)))); diff --git a/wesley/wesley_eval.hpp b/wesley/wesley_eval.hpp index d7ca4af..9849970 100644 --- a/wesley/wesley_eval.hpp +++ b/wesley/wesley_eval.hpp @@ -140,20 +140,8 @@ Boxed_Value eval_token(Eval_System &ss, TokenPtr node) { } } break; - case (TokenType::Negate) : { - retval = eval_token(ss, node->children[0]); - Param_List_Builder plb; - plb << retval; - //plb << Boxed_Value(-1); - - try { - retval = dispatch(ss.get_function("-"), plb); - } - catch(std::exception &e){ - throw EvalError("Can not find appropriate negation", node->children[0]); - } - } - break; + case (TokenType::Negate) : + case (TokenType::Not) : case (TokenType::Prefix) : { retval = eval_token(ss, node->children[1]); Param_List_Builder plb;