News:

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

Parsing an input string

Started by jinckz, March 06, 2012, 08:28:49 PM

Previous topic - Next topic

jinckz

Well, I am working on my second assembly program.

I am trying to parse the input 1/4+7/32

The goal is to accept an input as fractions, and perform the math operation between the fractions.

After some searching I believe the easiest way would be to modify the buffer termination to a /, get the numerator, then modify the buffer termination to a  ( +, \ , -, * ), get the denominator...etc?

KeepingRealBusy

You might want to google "RPN".

baltoro

Is this is a console application ?
Are you just trying to write the simplest working example ?
If it was me, I'd write several routines,...as a sort of trial and error approach,...just to learn the best technique.
Do you want to validate the entry ? By that I mean, test the entry string to see if it has the proper format and the appropriate characters ?
My first routine would simply scan the input string, testing for length of the input string, the presence of the essential operation characters (+,=,/), and then testing to make sure all the other characters are numbers or line terminators.
Assembly programming is actually kind of fun,...you can write all kinds of simple routines to check values and identify errors.
I'm thinking that the actual mathmatical operations would be fairly straighforward and trivial.
Baltoro

SteveAsm

Quote from: jinckz on March 06, 2012, 08:28:49 PM
I am trying to parse the input 1/4+7/32
The goal is to accept an input as fractions, and perform the math operation between the fractions.

Seems pretty straight forward, in that the / symbol will no longer represent a division operation.
You just choose another symbol to represent division.

Have you read up on math parsers ?
Have you chosen a parser design you want to implement ?

If not, look up "recursive descent parsers".

dedndave

if you use the standard "order of operations" as a guide, it will be easier

http://www.mathgoodies.com/lessons/vol7/order_operations.html