Monday, October 19, 2009

 

Simple Grammar for Arithmetic over English

Technorati Tags: ,

 

These days writing a  parser has become very easy, there are MANY free compiler-compiler available … and all of them does pretty decent job of code generation. Gold Parser is one such compiler-compiler. The good thing about Gold parser is that it generates C# parser code for your Grammar, combined with the Calitha Engine you get a pretty robust infrastructure to write your own language parser.

Sometime back, I wrote a simple grammar for basic arithmetic over English. The idea is simple, use English phrases as equivalent to mathematical operators. Example: the grammar allows you to say “sum of x and y” instead of “x + y”. As with mathematical operators, you can “pump” the output of one operator into another, example “subtract 10 from sum of 200 and 50”.

Here’s the Grammar:

ArithEnglish-Grammar

Another aspect of this parser library is that it also allows “variables”. The object model as seen by the calling code is shown below:

ArithEnglish-Model 

 

The complete code along with a sample client and a demo recording is shared at  my Aha World!  .

Note:

1.  The code to handle the interest rate rules is not yet done :(.
2,  The video works with Windows media player, didn’t work with VLC :(. … may be some missing driver issue.


This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]