Nick Mudge

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. It also handles nested parentheses correctly.

I hooked it up to the web interface.

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

Comments

Mike G
20 July 2008 at 12am

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 at 12am

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

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 at 12am

It was easier for implementing on PHP than in C?

Thanks for sharing this code!
..
15 October 2009 at 2pm

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

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

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

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 at 6pm

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 at 4am

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 at 9pm

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 at 3pm

Great, would you be willing to share your code?
Name: (required)
Email: (required)
Website:
 
 


My Sites
Links
Archive
Past Blogs