// Expression stack for %, %% and %%%
static void push(const ex &e);
static ex exstack[3];
+// Assigned symbols
+static exmap assigned_symbol_table;
// Start and end time for the time() function
#ifdef HAVE_RUSAGE
;
exp : T_NUMBER {$$ = $1;}
- | T_SYMBOL {$$ = $1.eval();}
+ | T_SYMBOL {
+ exmap::const_iterator i = assigned_symbol_table.find($1);
+ if (i == assigned_symbol_table.end())
+ $$ = $1;
+ else
+ $$ = i->second.eval();
+ }
| '\'' T_SYMBOL '\'' {$$ = $2;}
| T_LITERAL {$$ = $1;}
| T_DIGITS {$$ = $1;}
}
}
| T_DIGITS '=' T_NUMBER {$$ = $3; Digits = ex_to<numeric>($3).to_int();}
- | T_SYMBOL '=' exp {$$ = $3; const_cast<symbol&>(ex_to<symbol>($1)).assign($3);}
+ | T_SYMBOL '=' exp {$$ = $3; assigned_symbol_table[$1] = $3; }
| exp T_EQUAL exp {$$ = $1 == $3;}
| exp T_NOTEQ exp {$$ = $1 != $3;}
| exp '<' exp {$$ = $1 < $3;}
static ex f_evalm(const exprseq &e) {return e[0].evalm();}
static ex f_eval_integ(const exprseq &e) {return e[0].eval_integ();}
static ex f_expand(const exprseq &e) {return e[0].expand();}
+static ex f_factor(const exprseq &e) {return factor(e[0]);}
static ex f_gcd(const exprseq &e) {return gcd(e[0], e[1]);}
static ex f_has(const exprseq &e) {return e[0].has(e[1]) ? ex(1) : ex(0);}
static ex f_lcm(const exprseq &e) {return lcm(e[0], e[1]);}
static ex f_unassign(const exprseq &e)
{
CHECK_ARG(0, symbol, unassign);
- const_cast<symbol&>(ex_to<symbol>(e[0])).unassign();
+ exmap::iterator i = assigned_symbol_table.find(e[0]);
+ if (i != assigned_symbol_table.end())
+ assigned_symbol_table.erase(i);
return e[0];
}
{"evalm", f_evalm, 1},
{"eval_integ", f_eval_integ, 1},
{"expand", f_expand, 1},
+ {"factor", f_factor, 1},
{"find", f_find, 2},
{"fsolve", f_fsolve, 4},
{"gcd", f_gcd, 2},
// Print banner in interactive mode
if (isatty(0))
greeting();
+ assigned_symbol_table = exmap();
// Init function table
insert_fcns(builtin_fcns);