Click here to Skip to main content
13,254,366 members (61,801 online)
Click here to Skip to main content


42 bookmarked
Posted 10 Oct 2004

Implementing Semantic Actions in the Boost Spirit Parser Framework

, 10 Oct 2004
Using composites to implement a modular arithmetic calculator with the Boost Spirit parser framework.
#pragma once

#include <string>

namespace Calculator
	struct Syntax;
	class CTreeRoot;
	class CParser
		virtual ~CParser();

		// Accept input from the command line until the user
		// requests exit
		void RunCommandLineParser();

		// Callback for when the user requests exit
		void SetProcessingFinished();

		// Get the root of the expression tree
		CTreeRoot *GetRoot();

		// Get the grammar
		Syntax *GetGrammar();

		// Access the modular arithmetic base
		void SetModular( unsigned int modular );
		unsigned int GetModular() const;

		// Parse a single line of input
		bool ParseString( const std::string &line );

		// Clear the expression tree
		void ClearRoot();

		Syntax *m_parser;
		CTreeRoot *m_root;
		unsigned int m_modular;
		bool m_processingFinished;

}	// namespace Calculator

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Dave Handley
Web Developer
United Kingdom United Kingdom
I started programming on 8 bit machines as a teenager, writing my first compiled programming language before I was 16. I went on to study Engineering and Computer Science at Oxford University, getting a first and the University Prize for the best results in Computer Science. Since then I have worked in a variety of roles, involving systems management and development management on a wide variety of platforms. Now I manage a software development company producing CAD software for Windows using C++.

My 3 favourite reference books are: Design Patterns, Gamma et al; The C++ Standard Library, Josuttis; and Computer Graphics, Foley et al.

Outside computers, I am also the drummer in a band, The Unbelievers and we have just released our first album. I am a pretty good juggler and close up magician, and in my more insane past, I have cycled from Spain to Eastern Turkey, and cycled across the Namib desert.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 10 Oct 2004
Article Copyright 2004 by Dave Handley
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid