[dev] Lexers and parsers 2

From: Maurí­cio CA <mauricio.antunes_AT_gmail.com>
Date: Thu, 12 Aug 2010 00:10:46 -0300

Hi, all,

Some time ago, I asked your sugestions on what should be a parser
we could use for shell scripting:

   http://lists.suckless.org/dev/0908/0822.html

Now I would like to show you this tool I wrote. It does exactly
what was discussed in those messages, i.e., it's something like
yacc that can be used for shell scripting. I call it 'noam':

   http://bitbucket.org/mauricio/noam
   http://bitbucket.org/mauricio/noam/downloads

noam reads a grammar with rules associated to actions defined as
shell commands. As an example, this script (taken from current
documentation) implements a "plus only" calculator:

   #!/usr/bin/noam
   layout : /[[:space:]]+/ * ;
   number : /[0-9]+/ ;
   plus : /\+/ layout number {echo $3 > $OUTPUT} ;
   plus : plus layout number {echo $1 + $3 | bc > $OUTPUT} ;
   number : /\(/ layout plus layout /\)/ {echo $3 > $OUTPUT} ;
   main : layout number layout {echo Result: $2} ;

If you name it 'calc.noam' and type:

   echo '(+ 1 2 (+ 3 4) (+ 5 6) 7)' | calc.noam

you'll get:

   Result: 28

I've had a lot of fun with this, and hope it's useful to you.

Best,

Maurício
Received on Thu Aug 12 2010 - 05:10:46 CEST

This archive was generated by hypermail 2.2.0 : Thu Aug 12 2010 - 05:12:03 CEST