Nick Mudge Ignition Software Consulting & Development

I wrote a second parser that parses arithmetic expressions. It implements a pushdown automaton using the C function call stack as the stack. In other words it uses recursive functions. It's 45 percent less code than my last parser and is much more elegant.

I hooked it up to the web interface.

The C code:
parser.h
scanner.c
parser.c

Comments

Mike G
20 July 2008

Hi, I think there might be an error somewhere. I typed in this (random) expression:

55689*449+332-6522/859*(789-854/235*(6-4*2/3))

and my Es-Calc and Excel both give the value:

24998794.450622900000000000

your web interface is giving:

Answer: 24999254

Good luck fixing it, rather you than me ;-)


Mike G
20 July 2008

Might it be the use of atoi() rather than atof() ?
Nick Mudge
20 July 2008

Thanks.

The program only handles integers and so ignores fractional parts. For instance, 5/2 returns 2 and not 2.5
Ismael Ramirez
12 August 2008

It was easier for implementing on PHP than in C?

Thanks for sharing this code!
..
15 October 2009

check this ... 5-(10+100) ... wrong output
Nick Mudge
15 October 2009

Oh, thanks, I guess I have more work to do.
..
15 October 2009

any ideas on when you might fix it?
Nick Mudge
15 October 2009

I plan on fixing it tonight. Thanks for your interest. Curious, are you planning on using it for something? If so, that's great.
..
15 October 2009

well - i'm using it for something - but had to change a couple of things. I came up with a work around for this issue - but would like to have the tree in the right order though - so if you are fixing it tonight i'll wait
Nick Mudge
16 October 2009

Cool. It's going to take me a little longer. I'm a little rusty. But I plan to have it fixed soon.
..
16 October 2009

in any case - thanks a lot - i've fixed it already and implemented power of too.
or and by the way -(10+100) doesn't work neither
Nick Mudge
17 October 2009

Great, would you be willing to share your code?
Dayan
12 July 2011

I agree that this is important to remember that recursive writing is more effective than linear.


Pink Realty
www.pinkrealty.com.
20 September 2011

Great plans and strategies. The ideas are great.
Name: (required)
Email: (required)
Website:
What has four legs, rhymes with bat and says, "Meow?" (One word answer.)
Spam Filter: