First, unsuccessful, stab at not and negate
This commit is contained in:
@@ -231,6 +231,19 @@ P1 &prefixdecrement(P1 &p1)
|
||||
return (--p1);
|
||||
}
|
||||
|
||||
template<typename P1>
|
||||
P1 &prefixnegate(P1 &p1)
|
||||
{
|
||||
return (p1);
|
||||
}
|
||||
|
||||
template<typename P1>
|
||||
P1 &prefixnot(P1 &p1)
|
||||
{
|
||||
return (p1);
|
||||
}
|
||||
|
||||
|
||||
//Add canonical forms of operators
|
||||
template<typename T>
|
||||
void add_oper_equals(BoxedCPP_System &s)
|
||||
@@ -368,6 +381,8 @@ void add_opers_arithmetic_overload(BoxedCPP_System &s)
|
||||
register_function(s, &addsequal<T, R>, "+=");
|
||||
register_function(s, &prefixincrement<T>, "++");
|
||||
register_function(s, &prefixdecrement<T>, "--");
|
||||
register_function(s, &prefixnegate<T>, "-");
|
||||
register_function(s, &prefixnot<T>, "!");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -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" };
|
||||
|
||||
|
||||
@@ -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))));
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user