News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Expression Evaluator 0.110

Started by zooba, February 13, 2006, 11:51:41 PM

Previous topic - Next topic

zooba

Hi everyone.

This is version 0.010 of my expression evaluator :bg

At the moment, it handles the following operations:

Arithmetic: + (addition), - (subtraction), * (multiplication), ** (power), / (round-nearest division), \ (truncate division)
Bitwise-logical: & (and), | (or), ^ (xor)
Boolean-logical (converts non-zero values to -1): && (and), || (or), ^^ (xor)
Comparison: = or == (equal),  <> or >< (not-equal), < (less), <= or =< (less-equal), > (greater),  >= or => (greater-equal), and any of these may be preceeded by ! to negate (ie. !== is not-equal, !> is not-greater (ie. less-equal))

Documentation is inside Expression.inc.
Expression.asm is not required to link into your project, only Expression.lib and Expression.inc

Download: Expression.zip
License: AsmLL.txt

Any feedback would be appreciated :U

Cheers,

Zooba

Edit: Sorry. Forgot to mention that this version will INT 3 on an error. The next version won't, or you can remove the INT 3 instructions and re-compile if you like

zooba

Ha! And before anybody's noticed I've fixed some things :bg

Two new unary operators: ! and ~ (boolean and bitwise not, respectively)

Three new flags: EVAL_NO_COMPARISON (to disable comparison operations) and EVAL_IGNORE_FORWARD_REFERENCE/EVAL_IGNORE_POSITIVE_FORWARD_REFERENCE

The symbol callback function (yeah, you've gotta do your own symbol conversion :wink) can now return a specific value (EVAL_SYMBOL_FORWARD_REFERENCE) in EDX to indicate that the value is not yet known, rather than being invalid. The two flags above can be used to either trigger an error (default behaviour), treat the value as a zero, or treat the value as a zero IF the value can simply be added to the result later (return an error otherwise).

Download is at the same place :U

Cheers,

Zooba

ninjarider

zooba,

thnx much and its appreciated. do u mind me cutting and coping code out of it. i dont think im going to use the same amount of integer math concepts as u have. and its really wierd that u were going to post your code and found my post. ur code is also more well thought out than mine.

zooba

ninjarider,

You're welcome to use part or all of it (I'd appreciate a mention :wink) but keep in mind that it isn't perfect code (yet :U) and using the library is the easiest way to update to the newest.

This is about the third time I've written it from scratch, so it is reasonably well thought out :bg

Cheers,

Zooba

zooba

#4
Hey everyone

New version, 0.100. Now it can do floating point stuff and there's a text-file of documentation.

For people who want to build their own version, there's a set of compile flags at the top of the .ASM file which can adjust which parts of the code are included. The best way is to either build a new version of the library (which is getting bigger... up to 4.17kb :wink) (but remember, you can't redistribute it :bg) or link Expression.asm into your project. I don't recommend copy-pasting the code into your project, as this will make it very very hard to include updates :U

Same link above will work, or lazy people can use this one to avoid scrolling up :toothy

Cheers,

Zooba

Edit: Forgot to mention, there's a sample program in there too. It will require ASM Runtime to build, but the exe is included :U

ninjarider

as a side note to this. and as a programmer. do u think there would be ny beniefit to an os loading the file system off the harddrive and all file info related with it to memory and then saving file changes as files are changed. also if u want whnever i get done with this fucking os if u want u can have a copy.

zooba

That's an extremely unrelated side-note, and I'm not certain I understand exactly what you mean.

I don't believe there would be any advantage to having an OS behave in this way, since RAM generally doesn't exceed 1-2GB whereas file-systems are commonly upwards of 40-80GB.

If you only mean metadata (MFT, etc) then again, I don't believe there would be any advantage and memory consumption would be so great chances are it would page out anyway (if your OS isn't supporting paging, you would definitely not want to waste RAM on FS stuff)

zooba

#7
New update. Added modulus operator and integer math now uses 64-bit integers. AFAICT all my algorithms are right, but if anyone spots something let me know :wink

Expression Evaluator 0.110 (link is the same as above)

Cheers,

Zooba :U

zooba

Just updated links here as well since I've changed webspace.

Expression Evaluator 0.110
Asm Library License

Cheers,

Zooba

stanhebben

Maybe you could also add in the ability to check the input expression?

This library could come in handy later on.

The expression evaluator could also be extended to evaluate expressions with parameters, and store the result in a variable. For example, I have an application with the following values: width=300, height=50, x=0, y=10. Then I evaluate 'height=width*2/3', and height is set to 200.

The application that I have in mind is one where you can, for example, enter 'width*2/3' in the height input box, process the input width 'height=(%s)' and let the expression evaluator do it's job.

Stan

zooba

At the moment, it can check the input expression by trying to evaluate it. If it doesn't work... :wink

As for parameters, it has support for you to provide your own symbol function (see lpSymbolCallback). Using this, when 'width' is passed you can substitute the actual value. I feel that this allows for more customisability. On the downside, you'll also have to interpret numbers yourself, though it may be possible to call the default callback directly - check the source for DefaultSymbolCallbackInteger - it's not in the include file by default.

Cheers,

Zooba :U

stanhebben

Quote from: zooba on June 08, 2006, 09:44:50 AM
At the moment, it can check the input expression by trying to evaluate it. If it doesn't work... :wink

But you can also enter invalid expressions which work. For example, '5*(3/'. It gets evaluated to 5/3.

zooba

Okay. I'll see what I can come up with. Feel free to do your own function to check it (ie. counting brackets, etc.), I have no problem including someone elses function.

Cheers,

Zooba :U