void NumericComplexImaginaryOperator::apply(LiteralsStack &stack) const { if (stack.size() < 1) { throw InvalidSyntaxException("Imaginary part operator requires 1 operand"); } LiteralPointer first = stack.top(); NumericLiteralPointer firstNumeric = dynamic_pointer_cast<NumericLiteral>(first); if (!firstNumeric) { throw InvalidOperandException(first->toString()); } if (firstNumeric->toString().find("$") == std::string::npos) { throw InvalidOperandException(first->toString()); } stack.pop(); stack.pushAndNotify(LiteralPointer(new NumericLiteral( firstNumeric->getImaginaryNumerator(), firstNumeric->getImaginaryDenominator() ))); stack.save(); }
void StoOperator::apply(LiteralsStack &stack) const { if (stack.size() < 2) { throw InvalidSyntaxException("STO operator requires 2 operands"); } LiteralPointer first = stack.top(); stack.pop(); LiteralPointer second = stack.top(); stack.pop(); ExpressionLiteralPointer firstExpression = dynamic_pointer_cast<ExpressionLiteral>(first); if (!firstExpression) { throw InvalidOperandException(first->toString()); } string expectedAtom = first->toString(); expectedAtom.erase(remove(expectedAtom.begin(),expectedAtom.end(), '\''),expectedAtom.end()); AtomLiteralDefinition definition; if(dynamic_pointer_cast<AtomLiteral>(definition.createInstance(expectedAtom)) == nullptr) { throw InvalidOperandException(firstExpression->toString()); } ProgramLiteralPointer secondProgram = dynamic_pointer_cast<ProgramLiteral>(second); if(!secondProgram) { variableMap.setAndNotify(expectedAtom, second); } else{ try { LiteralVector secondProgramVector = lexer.tokenize(second->toString()); programMap.setAndNotify(expectedAtom,secondProgramVector); } catch (string except) { cout << " problem is : " << except << endl; } } stack.notify(); }
ObjectData *Variant::getArrayAccess() const { assert(is(KindOfObject)); ObjectData *obj = getObjectData(); assert(obj); if (!obj->instanceof(SystemLib::s_ArrayAccessClass)) { throw InvalidOperandException("not ArrayAccess objects"); } return obj; }
void throw_bad_type_exception(const char *fmt, ...) { va_list ap; va_start(ap, fmt); string msg; string_vsnprintf(msg, fmt, ap); va_end(ap); if (RuntimeOption::ThrowBadTypeExceptions) { throw InvalidOperandException(msg.c_str()); } raise_warning("Invalid operand type was used: %s", msg.c_str()); }