Saturday, November 08, 2008

Common Lisp: arithmetic calculator exercise

Following a post on the Atari ST forum I tried a little exercise to write an arithmetic expression parser for expressions like "24 - 3*9 + 9/3". I was surprised to find it a little difficult, taking about an hour even with the concessions I made (accepting input as a list rather than a string, and not checking for well-formedness of expressions). My code is on paste.lisp.org and I'd love to see any improvements or tips. Embarrassingly, I took two semesters of the final year compiler construction course in DCU and did quite well at it; parsing of programs was a central topic on the course! I guess it's easy to take for granted your skills at 'abstract' coding and notice they need a bit of exercising.

No comments:

Post a Comment