views:

130

answers:

2

Possible Duplicate:
Best algorithm for evaluating a mathematical expression?

I mean like when you enter this in Delphi:

var i : integer;
begin
  i=5 + 5 + (2 * (3 + 2)) + (1 * 4 + (1 - 3))
end;

But I want a command that works in this way:

var i : integer; s:string;
begin
  s:='5 + 5 + (2 * (3 + 2)) + (1 * 4 + (1 - 3))';
  i:=ParseInt(s);
end;

Thanks in advance

+2  A: 

If you want to implement this yourself, have a look at recursive descent parses and the shunting yard algorithm.

IVlad
+1  A: 

There are a number of free or inexpensive Math Parser components available for Delphi:

Foreval is open source, available as a DLL or delphi component.

TbcParser is $19.95 with source code.

lkessler