Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP as interpreter

Status
Not open for further replies.

zyzjacky

Programmer
Jan 19, 2006
76
MT
I don't know if anyone is familiar with stock application. there are certain formulas that you can input to analyze based on data. e.g.

input:LONG(26,20,100,1),SHORT(12,5,40,1),M(9,2,60,1);
DIFF : EMA(CLOSE,SHORT) - EMA(CLOSE,LONG);
DEA : EMA(DIFF,M);
MACD: 2*(DIFF-DEA), COLORSTICK;

what i am going to do here is, user will be able to input these formulas and my php server side will be able to understand/interpreter these formulas.

the challenge here is the user inputs are various and may lead to some very complex stuff, e.g. expression(expression1(expression2(1,2)/3)*2) etc.

What is the best way(think about performance, security, flexibilities) to accomplish such kind of goals?
Of course, i am not asking for the actual solutions, but some guide/direction.

My current idea is to use RPN(reverse polish notation) and regular expression to replace/filter input, and use eval() to get results.

someone also suggest to use LEX&YACC and write PHP extension. but it's really not the open source.

Any good ideas?

thanks!
 
zyzjacky,

Well if you plan to use one class module to eval on your expressions you need to make sure you declare and use "instance" pointers/counters as you are nesting your expressions and your processing will get lost, when you re-call your module, it you do not iterate the instance counter.

Just a thought!

YMR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top