Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / April 2005

Tip: Looking for answers? Try searching our database.

More clueless n00b questions...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lizard - 28 Apr 2005 20:15 GMT
OK. Here's my current assignment -- I need to write a formula parser
which is *fast*, as the formulas will need to be interpreted (acting
on new variables each pass) roughly a few zillion times during
operation. The formulas must be able to include some custom-designed
functions (such as 'the average of the last 10 values in a
user-specified field of a table') as well as standard math functions.
Further, the formulas must be able to reference other formulas, i.e.

Formula 1=a*b+c, named "FirstValue"
Formula 2=FirstValue+5

The program will then feed a,b,and c into the formula many, many,
times, so you see the advantage of turning the formula into something
like:

MyCustomRoutine (float a, float b, float c)
(
    return (a*b+c)+5;
}

(Ignore my crappy pseudocode, please)

There will be many of these, called at different times and for
different reasons. It is imperative the formula parser be powerful and
flexible.

My idea was to have the formula parser actually emit Intermediate
Language code and compile the results into a DLL. Then, the main
program would simply call the dynamically-created formulas to apply to
the data, so that the formulas do not need to be parsed each and every
time. Since the formulas will only need minor editing once written by
the user, there's an advantage to parse and compile, as opposed to
creating the IL code each time the program is run.

So here's question one: Where do I find massive quantities of info on
IL? I've made some initial progress using "Expert .Net Programming" by
Simon Robinson, but that's just a beginning. I need to learn a lot,
fast. Websites, other books, lost papyrus scrolls...

Question two, and, my GOD, is this a stupid question -- how do I (or
CAN I?) do a #using when writing dynamically generated code? For
example, if I have a class that includes the more complex functions,
such as moving average, I want to be able to have my
dynamically-generated code call the Moving Average function in my main
program code. You may laugh at the silliness of this now, but none of
the simple examples of dynamically generated code seem to include this
functionality.

Question three, the transcendentally stupid question -- is there a
reason not to use basic string functions to write my routined as
standard C# source code text files, then pass that text file to the
appropriate CodeDOM routines, instead of learning IL and messing with
ILConstructor.Emit()? I have looked at the various CodeDom functions
to emit code, but if my code is relatively simple, can I eliminate the
middleman and just spit out the ready-to-compile source file via
normal string manipulation?

Thanks for your patience with these questions.
*----------------------------------------------------*
Evolution doesn't take prisoners:Lizard
"I've heard of this thing men call 'empathy', but I've never
once been afflicted with it, thanks the Gods." Bruno The Bandit
http://www.mrlizard.com
Stefan Simek - 29 Apr 2005 10:16 GMT
If your formulas aren't going to change too much, I'd suggest using the
third alternative - using the C# compiler. This way, you can avoid all
most of the parsing stuff. Or, alternatively, look at JavaScript.NET
eval function. To use it from any other .NET language, all you have to
do is compile the following:

class Evaluator
{
    static function Evaluate(data : String) : Object
    {
        return eval(data);
    }
}

using
jsc /t:library eval.js

and you get a 4KB eval.dll for use from any .net language

there might be some problem with referencing other formulas though - but
I guess it's still worth looking at.

HTH,
Stefan

> OK. Here's my current assignment -- I need to write a formula parser
> which is *fast*, as the formulas will need to be interpreted (acting
[quoted text clipped - 59 lines]
> once been afflicted with it, thanks the Gods." Bruno The Bandit
> http://www.mrlizard.com
Lizard - 30 Apr 2005 19:49 GMT
On Fri, 29 Apr 2005 11:16:01 +0200, Stefan Simek
<nospam@nospam.nospam> wrotC:DRIVE_E

>If your formulas aren't going to change too much, I'd suggest using the
>third alternative - using the C# compiler. This way, you can avoid all
[quoted text clipped - 17 lines]
>there might be some problem with referencing other formulas though - but
>I guess it's still worth looking at.

The formulas are user-defined and can vary greatly. We need to give
the user the capacity to enter formulas dynamically in several areas
of the program. The program is a simulation engine where the user can
define the 'rules' of the simulation in a highly freeform manner.
Hence, the need for dynamic code creation.

*----------------------------------------------------*
Evolution doesn't take prisoners:Lizard
"I've heard of this thing men call 'empathy', but I've never
once been afflicted with it, thanks the Gods." Bruno The Bandit
http://www.mrlizard.com

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.