The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: jinckz on March 06, 2012, 08:28:49 PM

Title: Parsing an input string
Post by: jinckz on March 06, 2012, 08:28:49 PM
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?
Title: Re: Parsing an input string
Post by: KeepingRealBusy on March 06, 2012, 08:57:00 PM
You might want to google "RPN".
Title: Re: Parsing an input string
Post by: baltoro on March 06, 2012, 08:59:23 PM
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.
Title: Re: Parsing an input string
Post by: SteveAsm on March 06, 2012, 10:33:57 PM
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".
Title: Re: Parsing an input string
Post by: dedndave on March 06, 2012, 10:35:38 PM
if you use the standard "order of operations" as a guide, it will be easier

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