« Oakland A's 2008 Rebuilding Season | Main | How Time Flies »

April 06, 2008

The Parser

I've finished the recursive descent parser I was working on. It works really well and I also wrote a variant class that is used to pass and transform all sorts of different data types around in the parser. The parser is written in C++ and handles simple expressions. It does a left to right evaluation so it does a little look ahead to expand expressions and collect terms. It took me about 3 weeks to code from the ground up and I have to admit I was pretty rusty so I don't thing the first week could really count as coding. It was more like stumbling or groping.

I've learned a couple important things in this exercise. One of the most important things was that I can still write pretty complex C++ code. I thought that part of my life was over. I also learned that Microsoft has not been standing still while I was away and I have a lot to learn Although my current position is not coding, I do need to learn more about 64 bit development and Vista UAC.

So my coding contribution to the Master Installer is complete and I can go back to managing the schedule and get the thing delivered.

Here are the details for the language:
The parser handles simple expressions in real using a language similar to C.

x = ((1+func(arg1,arg3)+3)*2)%5

and return the value for x

The expression parser performs left to right evaluation and handles scoping. It also has two levels of operator precedence, but you can alter this using parenthesis.

1 - ! ( )
2 - * / % ^ [L2_TOK]
3 - + - < <= > >= == != && || & | [L1_TOK]

The Language is defined as:
<xpression> --> <term> ( (L1_TOK) <term> )*
<term> --> <factor> ( (L2_TOK) <factor> )*
<factor> --> ID | CONST | '(' <expression> ')' | <function> | '!' <expression>
<function> --> ID '(' <paramlist> ')'
<paramlist> --> (<expression> (','<expression>)*)*

Posted by Hefe at April 6, 2008 06:10 PM

Comments

Post a comment




Remember Me?