Link to home
Start Free TrialLog in
Avatar of victor_christov
victor_christov

asked on

Code Block

Hi experts,
I am trying to write a 'CodeBlock' function (or procedure) in Delphi 3.0, like one in CA-Clipper 5.2 / 5.3. That means I want to bo able to assign to a string variable a value like :

    s := 'Writeln(a); writeln(2*a);'

and later to execute it in the same way as in Clipper :

    eval(<parameter>,s)

where <parameter> are data, over which is evaluated the 'Code Block').

Is this possible in Delphi 3.0 and how can I achieve it ?
Avatar of kotik
kotik

Hi, Viktor
I don't think that it's possible in Delphi.

No, this is not possible in Delphi, although there are some simple language interpreters that can be used in Delphi (take a look at Delphi Super Page http://sunsite.icm.edu.pl/delphi) - this has a couple of these engines on it.

One way you can approximate this is by using DLLs. If you would like more information on this let me know...

Cheers,

Raymond.

Delphi is compiled.  After your program is compiled, it has no clue what Pascal syntax means, or even what Pascal is, because the Pascal is no longer there.
Avatar of simonet
What you're looking is called a "parser" under Pascal.

There are plenty of them in DSP: http://metalab.unc.edu/delphi
or
http://sunsite.unc.edu.pl/delphi

Alex
What you are looking for is lex and yacc,
where lex (lexical analyse) takes a string as input,
and you will get a lot of tookens back, depending on
what rules you have set up.....
And then you put these tookens into the yacc (yet another compiler compiler), wich also have a lot of rules on how the tookens are put together, and then yacc parse and makes up your source code for you....

This is a very huge task, you have to make your own compiler.....

you can find a lex/yacc program wich is called tply for delphi in www.torry.ru

I hope you this help... But good luck......

Smilly:

lex and yacc will be about as useful to him as tits on a bull!

Even if he used them and wrote his compiler, he still can't insert the compiled code inline like he wants to do...

Cheers,

Raymond.

Hi Raymond,
Sure he can, but it is a big task.
He can make a internal function rule EVAL and tell it to take [pascal] as
parameters.......It is not a big thing, the big thing is to make the compiler.
If it first works then its no big deal to force it to interprete the parameters inside
EVAL(.....).

And as I see it, it is the only way he can do this task.......

ASKER CERTIFIED SOLUTION
Avatar of kjteng
kjteng

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Vitor, any comment/question?