Unit calc

Classes

TCalculator -

Functions

Calculate -
DefCalcProc - Default calculator callback proc
DegreeToStr - Degree convertation functions
fmod - some math functions
power -
StrCalculate - Calculate functions
StrToDegree -

Types

PNamedVar
TCalcCBProc
TCalcCBType
TNamedVar
TToken

Constants

SFunctionError
SInvalidDegree
SSyntaxError

Variables


Functions


function Calculate(const Formula: String; var R: Double; Proc: TCalcCBProc): Boolean;


function DefCalcProc(ctype: TCalcCBType; const S: String; var V: Double): Boolean;

Default calculator callback proc

function DegreeToStr(Angle: Extended): String;

Degree convertation functions

function fmod(x, y: extended): extended;

some math functions

function power(x, y: Double): Double;


function StrCalculate(Buff: PChar; var R: Double; Proc: TCalcCBProc): Boolean;

Calculate functions

function StrToDegree(const S: String): Extended;


Types


PNamedVar = ^TNamedVar

TCalcCBProc =
    function(ctype: TCalcCBType; const S: String; var Value: Double): Boolean

TCalcCBType = (ctGetValue, ctSetValue, ctFunction);

TNamedVar = record
Value : Double;
Name : array[0..0] of Char;
end;

TToken = (
    { } tkEOF, tkERROR, tkASSIGN,
    {7} tkLBRACE, tkRBRACE, tkNUMBER, tkIDENT, tkSEMICOLON,
    {6} tkPOW,
    {5} tkINV, tkNOT,
    {4} tkMUL, tkDIV, tkMOD, tkPER,
    {3} tkADD, tkSUB,
    {2} tkLT, tkLE, tkEQ, tkNE, tkGE, tkGT,
    {1} tkOR, tkXOR, tkAND
  );
//.TITLE Calculator //.DESC Simple calculator for standard expressions //.AUTOR Ivlev M.Dmitry // Email: Dimon@Diogen.nstu.nsk.su //.PATCHED Sergey Pedora // Email: Sergey@mail.fact400.ru // Syntax: 0xABCD, 0ABCDh, $ABCD - Hex number 0b0101, 01010b, - Binary number 90`15`2 - Degree Operators by priorities: { 7} () (BRACES) { 6} ** (POWER), { 5} ~ (INVERSE), ! (NOT), { 4} * (MUL), / (DIV), % (MOD), %% (PERSENT), { 3} + (ADD), - (SUB), { 2} < (LT), <= (LE), == (EQ), <> != (NE), >= (GE), > (GT), { 1} | (OR), ^ (XOR), & (AND),

Constants

SFunctionError = 'Unknown function or variable'

SInvalidDegree = 'Invalid degree %s'

SSyntaxError = 'Syntax error.'


Variables