Thursday, May 4, 2017

Parsers

Somehow, I find writing parsers and interpreters one of the most satisfying computer programming activities I've done. I've done this a couple of times in my life, sometimes from scratch and sometimes using a tool like bison. Maybe it's because the resulting linguistic adeptness that the computer shows--even in the case of a very simple language--is somehow impressive. It's fun, for instance, to write a parser that translates a formula like "x^3*y-y^3*x" into a LISP-like representation ["-",["*",["^","x",3],"y"],["*",["^","y",3],"x"]], and that can then interpret the representation given values for x and y. Most recently, I had the fun of doing this in the OpenSCAD 3D design language, to enable passing formulas to functions/modules. This was kind of challenging for me as I'm not very comfortable with functional languages.

No comments: