Click here to Skip to main content
15,860,972 members
Articles / Desktop Programming / ATL

Visual Calc v3.0 - A new dimension for the desktop calculator

Rate me:
Please Sign up or sign in to vote.
3.62/5 (113 votes)
28 Apr 2006CPOL22 min read 346.4K   6.8K   104  
How to start programming a parser.
/**
 * @file VCalcParserTypes.h
 * @brief VisualCalc Parser Types.
 *
 * Defines some types used by the VisualCalc Parser.
 */

#if !defined(__AFX_VCALCPARSERTYPES_H_INCLUDED__)
#define		 __AFX_VCALCPARSERTYPES_H_INCLUDED__

#if _MSC_VER > 1000
#pragma once
#endif


#include "VCalcParserException.h"


/**
 * @typedef VALUES_TYPE
 * @brief Type of the results.
 *
 * Type defined to handle operands and results.
 */
typedef	long double VALUES_TYPE;


/**
 * @enum TokenValue
 * @brief Type of the Tokens.
 *
 * Type defined for recognized separation tokens on the input stream.
 */
typedef enum {
	TV_NUMBER,			/**< If a number is read (integer of floating point)		*/
	TV_IDENTIFIER,		/**< If an identifier is read (variable or function)		*/
	TV_END,				/**< If the end of the expression was reached				*/
	TV_SEQ		= ',',	/**< If a '<B>,</B>' is read (function parameters list)		*/
	TV_PLUS		= '+',	/**< If a '<B>+</B>' is read (Addition or unary plus)		*/
	TV_MINUS	= '-',	/**< If a '<B>-</B>' is read (Subtraction or unary minus)	*/
	TV_MUL		= '*',	/**< If a '<B>*</B>' is read (multiplication)				*/
	TV_DIV		= '/',	/**< If a '<B>/</B>' is read (Division)						*/
	TV_POW		= '^',	/**< If a '<B>^</B>' is read (Power)						*/
	TV_MOD		= '%',	/**< If a '<B>%</B>' is read (Modulus)						*/
	TV_FACT		= '!',	/**< If a '<B>!</B>' is read (Factorial)					*/
	TV_DEG		= '�',	/**< If a '<B>�</B>' is read (degrees to radians)			*/
	TV_LP		= '(',	/**< If a '<B>(</B>' is read (opening parenthesis)			*/
	TV_RP		= ')',	/**< If a '<B>)</B>' is read (closing parenthesis)			*/
	TV_ASSIGN	= '='	/**< If a '<B>=</B>' is read (Assignation)					*/
} TokenValue;


/**
 * @struct AnswerItem
 * @brief Type for an entry in the answers history.
 *
 * Type defined to store a formula typed by the user (which resulted in a valid answer)
 *   and its relating value.<br>
 * An invalid formula (which by definition throws an error) isn't stored until the user
 *   corrects his mistake.
 */
typedef struct {
	std::string	m_strFormula;
	VALUES_TYPE	m_valResult;
} AnswerItem;


#endif // !defined(__AFX_VCALCPARSERTYPES_H_INCLUDED__)

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Accenture Technology Solutions
France France

Toxcct is an electronics guy who felt in love with programming at the age of 10 when he discovered C to play with Texas-Instruments calculators.

Few years later, he discovered "The C++ Language" from Bjarne Stroustrup ; a true transformation in his life.

Now, toxcct is experiencing the Web by developing Siebel CRM Applications for a living. He also respects very much the Web Standards (YES, a HTML/CSS code MUST validate !), and plays around with HTML/CSS/Javascript/Ajax/PHP and such.

_____

After four years of services as a Codeproject MVP, toxcct is now taking some distance as he doesn't like how things are going on the forums. he particularly doesn't accept how some totally ignorant people got the MVP Reward by only being arrogant and insulting while replying on the technical forums.



Comments and Discussions