Home Resources Recursive Descent Parser in C

Recursive Descent Parser in C

The recursive descent parser is the core module of the calculator application found on the COMA, the XMultiKit and the Xmegalab. It is based on the Visual Basic program Math Expression Evaluator by Michael Combs.

I ported the code to standard C so it can be used on any platform.

To use this module you only need to add parse.c to your project and #include "parse.h" in your code.

Two global variables are used:

extern uint8_t m_error; // different than zero if an error occurred
extern double ans;      // answer

The only function you need to call is

void evaluate(char expression[]); // the expression must end with a space

The function will modify the global variables m_error and ans.


evaluate("1+1 "); // The expresion must and with a space

ans will equal 2, m_error will equal 0.


Download the files here:

cfile Recursive Descent Parser

Here is a calculator demo using the recursive descent parser:


avatar yonghui

thanks very much for the fixed link.

avatar Borrisholt


Will make the parser break down.

JEns Borrisholt
avatar ganzziani
Hi Jens, did you add the space after the expression?
Please login to post comments or replies.
Last Updated on Monday, 11 April 2011 11:42  




Shopping Cart

Your Cart is currently empty.

Featured Products

XMEGA Xprotolab
XMEGA Xprotolab


Xprotolab: Excellent transaction all around. Amazing product and functionality. sts95

Official PayPal Seal