Sunday, November 8, 2009

Another interpreter with source code

There are a lot of Delphi interpreters out there, if you know some that worth mentioning and I didn't post them please comment on this post or e-mail me.
TArtFormula is a nice interpreter both mathematical and automation, I'm not so good at writing or advertising so I just copy-paste the info from Artem Parlyuk's(author) web site

ArtFormula package contains two nonvisual Delphi componenst for symbolic expression parsing and evaluation. Provides runtime scripting engine for automating your programs.

7 arithmetic operations
10 logical operations
6 bitwise operations
string concatenation
22 arithmetic functions
10 statistical functions
2 logical functions
16 string functions
13 date functions
14 programming functions
User defined constant
Up to 255 user defined variables
Up to 255 user defined functions (modules)
Symbolical differentiation of functions with basic simplification of resulting derivatives

Arithmetic operation:
x + y, x - y, x * y, x / y, x % y (Mod), x ^ y (power), x\ y (Div)

Logical operation (true=1, false=0):
x > y, x < y, x >= y, x <= y, x = y, x <> y, ! x (not), x & y (and), x | y (or), x xor y

Bitwise operations:
x && y (band), x || y (bor), !!x (bnot), x bxor y, x >> y (shr), x << y (shl) Predefined constants:
Pi = 3.1415926535897932385
True = 1
False = 0

sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, asinh, acosh, atanh, sqrt, exp, log, lg (log base 10), int (integer part of a number), frac (fractional part of a number), abs, sign, rnd, randomize
max(x,y...), min(x,y,...), count(x,y,...), sum(x,y,...), sumofsquares(x,y,...), avg(x,y,...), variance(x,y,...), variancep(x,y,...), stddev(x,y,...), stddevp(x,y,...)
iff(cond,x,y) (if cond = true then result = x else result = y),
chr(x), length(s), trim(s), trimleft(s), trimright(s) lowercase(s), uppercase(s), midstr(s,x,y), leftstr(s,x), rightstr(s,x), pos(s,t), code(s), format(s,x), formatf(s,x), stringofchar(c,n), concat(s1,s2,...)
date(s), now, formatdate(s,d), year(d), month(d), day(d), hour(d), minute(d), second(d), millisecond(d), isleapyear(n), dayofweek(d), encodedate(y,m,d)


TArtFormula provides two styles of programming: formula style and scripting style. The first style assumes that all statements have the form of function call. The second style imply that you use common program language notation.

For example:

block(defines('i','n'), set('n',1),
series(set('i',1), val('i')<=5, inc('i'), set('n',val('n')*val('i'))), msg('5! = '+val('n'),'result',0)) Is equal to: begin var 'i', 'n' end; $n:=1; for $i:=1; $i<=5; $i++ do $n := $n*$i; next; msg('5! = '+val('n'),'result',0); end You can mix two styles in one program. TArtFormula programming language supports: Variables definitions Assigmnent statement Increment and Decrement operations Return function Compound statement (BEGIN... END) IF statement WHILE loop UNTIL loop FOR loop Interface functions: msg('text','caption',props), input('caption', 'text', defvalue) Spreadsheet applicatiuon:

TArtFormula can be used in spreadsheet application. E.g. using GetVarsCount and GetVarValue event handlers one can implement calculation of sum(a1:b4), avg(c1:c99) and similar function calls, where a1:b4 and c1:c99 are range of sheet cells.

No comments:

Post a Comment

Blogroll(General programming and Delphi feeds)