Evaluating Expressions – Part 2: Parse the Expression

In my previous post I have provided some background theory for evaluating expressions with abstract syntax trees. As I was mentioning, the first step towards this goal is to parse the expression, make sure it is correct syntactically. This is what I’ll show you in this post. Having the grammar defined, we’ll make one function … Read more

Evaluating Expressions – Part 1: The Approaches

I was discussing a few days ago about evaluating expressions and I decided to explain how you can build an evaluator. I will do this in a series of posts, getting one step more in each post. I will use C++, but the approaches are the same regardless the language. Let’s consider this expression: 1+2*3. … Read more

Writing UTF-8 files in C++

Let’s say you need to write an XML file with this content: < ?xml version=”1.0″ encoding=”UTF-8″? > < root description=”this is a naïve example” > < /root > How do we write that in C++? At a first glance, you could be tempted to write it like this: #include < fstream > int main() { … Read more

Output Formatting with std::copy

I had to do some output formatting in C++ for showing the content of a buffer. Take for instance this buffer: unsigned char buffer [] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; I wanted the output to be like this: 0x00, 0x01, 0x02, … Read more

MFC Feature Pack

At the beginning of January, Microsoft released a beta version of MFC Feature Pack, an exstension to the MFC shipped with Visual Studio 2008. This feature pack allows developers to create applications with the look and feel of Office, Visual Studio and Internet Explorer. MFC application can now support: Office Ribbon Office 2003, XP and … Read more

Forward Declaration for a Class from a Namespace

Suppose you have a class declare in a namespace, like this: #pragma once namespace Test { class foo { public: foo(void); ~foo(void); }; }; #include “foo.h” namespace Test { foo::foo(void) { } foo::~foo(void) { } }; And you want to use that foo class in a another class, with a forward declaration: #pragma once class … Read more