143 for (
int pc = 0; pc <
m_codes.count(); pc++) {
146 index = opcode.
index;
147 switch (opcode.
type) {
159 bool success =
false;
160 qreal
value = stack.pop().toDouble(&success);
164 stack.push(QVariant(
value));
171 qreal val2 = stack.pop().toDouble();
172 qreal val1 = stack.pop().toDouble();
173 stack.push(QVariant(val1 + val2));
178 qreal val2 = stack.pop().toDouble();
179 qreal val1 = stack.pop().toDouble();
180 stack.push(QVariant(val1 - val2));
185 qreal val2 = stack.pop().toDouble();
186 qreal val1 = stack.pop().toDouble();
187 stack.push(QVariant(val1 * val2));
192 qreal val2 = stack.pop().toDouble();
193 qreal val1 = stack.pop().toDouble();
194 stack.push(QVariant(val1 / val2));
205 stack.push(function);
214 if (stack.count() < index) {
215 qWarning() <<
"not enough arguments for function " <<
m_text;
222 for (; index; index--) {
223 qreal
value = stack.pop().toDouble();
224 args.push_front(
value);
228 int function = stack.pop().toInt();
239 if (stack.count() != 1) {
244 return stack.pop().toDouble();
251 return fabs(arguments[0]);
254 return sqrt(arguments[0]);
257 return sin(arguments[0]);
260 return cos(arguments[0]);
263 return tan(arguments[0]);
266 return atan(arguments[0]);
270 return atan2(arguments[0], arguments[1]);
273 return qMin(arguments[0], arguments[1]);
276 return qMax(arguments[0], arguments[1]);
279 if (arguments[0] > 0.0) {
313 QString expr = formula + QChar();
316 while ((state != Bad) && (state != Finish) && (i < expr.length())) {
326 }
else if (ch.isDigit()) {
332 state = InIdentifier;
333 }
else if (ch ==
'.') {
334 tokenText.append(expr[i++]);
336 }
else if (ch == QChar::Null) {
339 QString opString(ch);
354 tokenText.append(expr[i++]);
355 }
else if (ch ==
'(') {
370 tokenText.append(expr[i++]);
371 }
else if (ch ==
'.') {
372 tokenText.append(
'.');
375 }
else if (ch.toUpper() ==
'E') {
376 tokenText.append(
'E');
378 state = InExpIndicator;
388 tokenText.append(expr[i++]);
389 }
else if (ch.toUpper() ==
'E') {
390 tokenText.append(
'E');
392 state = InExpIndicator;
401 if ((ch ==
'+') || (ch ==
'-')) {
402 tokenText.append(expr[i++]);
403 }
else if (ch.isDigit()) {
412 tokenText.append(expr[i++]);
429 if (tokens.count() == 0) {
435 unsigned argCount = 1;
437 for (
int i = 0; i <= tokens.count(); i++) {
450 syntaxStack.
push(token);
457 syntaxStack.
push(token);
470 argStack.push(argCount);
478 bool ruleFound =
false;
495 if (
id.isFunction()) {
513 if (
id.isFunction()) {
519 syntaxStack.
push(arg);
521 argCount = argStack.empty() ? 0 : argStack.pop();
626 syntaxStack.
push(token);
643 qWarning() <<
"compiling of " <<
m_text <<
" failed";
655 : m_type(type), m_text(text), m_position(position)
661 if (
this != &token) {
700 if (text.length() != 1) {
704 const char c = text[0].toLatin1();
720 return (ch.unicode() ==
'?') || (ch.unicode() ==
'$') || (ch.isLetter());
736 default: prec = -1;
break;
746 if (text ==
"sqrt") {
758 if (text ==
"atan") {
761 if (text ==
"atan2") {
820 for (
int i = 0; i < tokens.count(); i++) {
821 qDebug() << tokens[i].text();
842 default: ctext =
"Unknown";
break;
float value(const T *src, size_t ch)
qreal evaluateReference(const QString &reference)
Opcode(unsigned t, unsigned i)