λanguage Parser

I did my Master’s degree from a lab that focused on compilers and virtual machines. Surely enough, we were sometimes expected to write a compiler for unfamiliar languages in cooperative projects.

Tedious but unavoidable work in writing compiler is making a parser, and I really hated using ‘lex’ and ‘yacc’ for the job; I always found LALR parser generators distasteful, and it was immoderate to write prototypes in C.

So when I had to write a kind of an interpreter for a project with Samsung, I used Ometa-JS, a JavaScript parser generator based on PEG(parsing expression generator), and the result was incredible: It took only 3 days to write the entire interpreter, while my colleague was not able to finish his work with lex&yacc that started months ago.

I attribute the following for this success: 1) PEG is much intuitive than CFG; 2) dynamic language wins in prototyping; 3) plain lists & dictionaries are useful than structured data; 4) JS comes with some meta-programming facilities.

 

Because of the confidentialiy issue, I cannot disclose the code I wrote; instead, I am enclosing another parser I wrote in Ometa-JS.

This is a spin-off version of λanguage tutorial(http://lisperator.net/pltut/). The tutorial defines a new language and names it λanguage. It walks you down how to write recursive descent parser, interpreter, and CPS transformer in JavaScript. It’s a great fun and I adapted the parser part with Ometa-JS

 

For more information,

 

Leave a Reply