Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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

, 28 Apr 2006 CPOL
How to start programming a parser.
visualcalc224_bin_20060206.zip
Visual Calc.exe
visualcalc224_lib_20060206.zip
mfc42.dll
msvcrt.dll
msvcp60.dll
visualcalc224_src_20060206.zip
res
About.ico
AboutFrame.bmp
CodeProject.ico
Doxygen.ico
function.ico
Help.ico
ico00001.ico
operator.ico
switch.ico
Visual Calc.ico
visualst.ico
WinXP.ico
Visual Calc.dsw
Visual Calc.dsp
visualcalc300_bin_20060418.zip
VisualCalc.exe
VCalcParser.dll
visualcalc300_lib_20060418.zip
msvcrt.dll
msvcp71.dll
msvcr71.dll
MFC71.dll
visualcalc300_parser-doc_20060418.zip
html
class_c_answer_requested_not_found_exception.png
class_c_closing_parenthesis_expected_exception.png
class_c_constant_assignation_exception.png
class_c_division_by_zero_exception.png
class_c_domain_exception.png
class_c_dom_parameters_must_be_integers_exception.png
class_c_dom_parameters_must_be_positive_exception.png
class_c_dom_parameter_must_be_an_integer_exception.png
class_c_dom_parameter_must_be_positive_exception.png
class_c_factorial_def_for_positive_ints_exception.png
class_c_function_exception.png
class_c_function_not_supported_exception.png
class_c_illegal_use_of_fonction_name_exception.png
class_c_implicit_multiplication_exception.png
class_c_literal_assignation_exception.png
class_c_mathematic_exception.png
class_c_mathematic_expression_expected_exception.png
class_c_math_parameter_must_be_an_integer_exception.png
class_c_math_parameter_must_be_positive_exception.png
class_c_n_must_be_positive_exception.png
class_c_parameter_exception.png
class_c_parameter_out_of_range_exception.png
class_c_parser_exception.png
class_c_period_unexpected_exception.png
class_c_p_must_be_positive_exception.png
class_c_p_must_be_smaller_than_n_exception.png
class_c_syntax_exception.png
class_c_too_few_parameters_exception.png
class_c_too_many_parameters_exception.png
class_c_undefined_variable_exception.png
class_c_unexpected_character_exception.png
class_c_unknown_exception.png
class_c_unknown_function_called_exception.png
class_c_variable_exception.png
class_c_v_calc_parser_exception.png
Copie de form_0.png
Copie de form_1.png
Copie de form_10.png
Copie de form_11.png
Copie de form_12.png
Copie de form_2.png
Copie de form_6.png
Copie de form_7.png
Copie de form_8.png
Copie de form_9.png
doxygen.png
form_0.png
form_1.png
form_10.png
form_11.png
form_12.png
form_2.png
form_3.png
form_4.png
form_5.png
form_6.png
form_7.png
form_8.png
form_9.png
tab_b.gif
tab_l.gif
tab_r.gif
_formulas.tex
visualcalc300_parser-src_20060418.zip
VCalcParser.lib
visualcalc300_src_20060418.zip
bin
lib
VCalcParser
doc
Doxygen.cfg
VisualCalc
res
About.ico
AboutFrame.bmp
CodeProject.ico
Doxygen.ico
errcodes.ico
function.ico
Help.ico
operator.ico
switch.ico
VisualCalc.ico
VisualCalc.manifest
visualst.ico
WinXP.ico
VCalcParser.lib
visualcalcparser250_doc_20060206.zip
doc
Doxygen.cfg
html
class_c_answer_requested_not_found_exception.png
class_c_closing_parenthesis_expected_exception.png
class_c_constant_assignation_exception.png
class_c_division_by_zero_exception.png
class_c_domain_exception.png
class_c_dom_parameters_must_be_integers_exception.png
class_c_dom_parameters_must_be_positive_exception.png
class_c_dom_parameter_must_be_an_integer_exception.png
class_c_dom_parameter_must_be_positive_exception.png
class_c_factorial_def_for_positive_ints_exception.png
class_c_function_exception.png
class_c_function_not_supported_exception.png
class_c_illegal_use_of_fonction_name_exception.png
class_c_implicit_multiplication_exception.png
class_c_literal_assignation_exception.png
class_c_mathematic_exception.png
class_c_mathematic_expression_expected_exception.png
class_c_math_parameter_must_be_an_integer_exception.png
class_c_math_parameter_must_be_positive_exception.png
class_c_n_must_be_positive_exception.png
class_c_parameter_exception.png
class_c_parameter_out_of_range_exception.png
class_c_parser_exception.png
class_c_period_unexpected_exception.png
class_c_p_must_be_positive_exception.png
class_c_p_must_be_smaller_than_n_exception.png
class_c_syntax_exception.png
class_c_too_few_parameters_exception.png
class_c_too_many_parameters_exception.png
class_c_undefined_variable_exception.png
class_c_unexpected_character_exception.png
class_c_unknown_exception.png
class_c_unknown_function_called_exception.png
class_c_variable_exception.png
class_c_v_calc_parser_exception.png
Copie de form_0.png
Copie de form_1.png
Copie de form_10.png
Copie de form_11.png
Copie de form_12.png
Copie de form_2.png
Copie de form_6.png
Copie de form_7.png
Copie de form_8.png
Copie de form_9.png
doxygen.png
form_0.png
form_1.png
form_10.png
form_11.png
form_12.png
form_2.png
form_3.png
form_4.png
form_5.png
form_6.png
form_7.png
form_8.png
form_9.png
tab_b.gif
tab_l.gif
tab_r.gif
_formulas.tex
visualcalcparser250_src_20060206.zip
visualcalc_demo.zip
Visual Calc.exe
visualcalc_libs.zip
msvcp60.dll
mfc42.dll
msvcrt.dll
visualcalc_parser.zip
visualcalc_src.zip
About.ico
AboutFrame.bmp
CodeProject.ico
function.ico
Help.ico
ico00001.ico
operator.ico
switch.ico
Visual Calc.ico
visualst.ico
WinXP.ico
Visual Calc.dsp
Visual Calc.dsw
// VCalcParser.h: interface for the CVCalcParser class.
//

#if !defined(__AFX_VCALCPARSER_H_INCLUDED__)
#define		 __AFX_VCALCPARSER_H_INCLUDED__

#if _MSC_VER > 1000
#pragma once
#endif

#pragma warning (disable: 4786)	//identifier was truncated to '255' characters in the debug information

#include <ALGORITHM>// std::find()
#include <STRING>	// std::string
#include <LIST>		// std::list<>
#include <MAP>		// std::map<>
#include <DEQUE>	// std::deque<>
#include <CMATH>	// ::abs(), ::acos(), ::asin(), ::atan(), ::cos(),   ::cosh()
					// ::exp(), ::fabs(), ::floor() ::log(),  ::log10(), ::fmod()
					// ::pow(), ::sin(),  ::sinh(), ::sqrt(), ::tan(),   ::tanh()
#include "VCalcParserTypes.h"


////////////////////////////////////////////////////////////////
// VisualCalc 2.20 Parser...
class CVCalcParser {
private:
	// Mathematic constants
	const VALUES_TYPE	m_PI;	// 3.1415926535897932384626433832795
	const VALUES_TYPE	m_E;	// 2.7182818284590452353602874713527

	// Members for parsing treatment
	TokenValue					m_tokCurrentToken;		// Current token extracted from the input stream
	std::string					m_strSource;			// Reference to the input stream
	std::string					m_strIdentifierValue;	// Identifier extracted as an IDENTIFIER token
	std::string					m_strWarningMsg;		// To describe the warning
	VALUES_TYPE					m_valNumberValue;		// Number extracted as a NUMBER token
	bool						m_bWarningFlag;			// Non-interrupting low level message
	bool						m_bEndEncountered;		// The end of the input stream is reached
	int							m_iCurrentIndex;		// Index in the input stream
	std::list<std::string>		m_lstFunctions;			// Supported functions
	std::map<std::string, VALUES_TYPE>
								m_mapVariables;			// User defined variables table mapping the identifier with a value
	std::deque<AnswerItem>		m_dqeAnswersHistory;	// Answers History mapping a formula with a result
	std::string					m_strParserVersion;		// Version of the Parser

	// Locally defined/redefined mathematic functions
	VALUES_TYPE	ffactor	(VALUES_TYPE);
	VALUES_TYPE	nCp		(VALUES_TYPE, VALUES_TYPE);
	VALUES_TYPE	nAp		(VALUES_TYPE, VALUES_TYPE);
	AnswerItem	Ans		(VALUES_TYPE valIndex);

	VALUES_TYPE abs		(VALUES_TYPE);
	VALUES_TYPE cos		(VALUES_TYPE);
	VALUES_TYPE sin		(VALUES_TYPE);
	VALUES_TYPE tan		(VALUES_TYPE);
	VALUES_TYPE cosh	(VALUES_TYPE);
	VALUES_TYPE sinh	(VALUES_TYPE);
	VALUES_TYPE tanh	(VALUES_TYPE);
	VALUES_TYPE Acos	(VALUES_TYPE);
	VALUES_TYPE Asin	(VALUES_TYPE);
	VALUES_TYPE Atan	(VALUES_TYPE);
	VALUES_TYPE deg		(VALUES_TYPE);
	VALUES_TYPE rad		(VALUES_TYPE);
	VALUES_TYPE exp		(VALUES_TYPE);
	VALUES_TYPE ln		(VALUES_TYPE);
	VALUES_TYPE log		(VALUES_TYPE);
	VALUES_TYPE logn	(VALUES_TYPE, VALUES_TYPE);
	VALUES_TYPE sqrt	(VALUES_TYPE);
	VALUES_TYPE pow		(VALUES_TYPE, VALUES_TYPE);
	VALUES_TYPE mod		(VALUES_TYPE, VALUES_TYPE);
	VALUES_TYPE sum		(std::string expr, std::string var, VALUES_TYPE low, VALUES_TYPE high);
	VALUES_TYPE product	(std::string expr, std::string var, VALUES_TYPE low, VALUES_TYPE high);

public:
	CVCalcParser();
	virtual ~CVCalcParser();
	void ResetParserMembers(const std::string);
	void ResetFunctions();
	void ResetVariables();
	void ResetAnswersHistory();
	const std::list<std::string>&				GetFunctions();
	const std::map<std::string, VALUES_TYPE>&	GetVariables();
	const std::deque<AnswerItem>&				GetAnswersHistory();
	bool HasWarning();
	std::string GetWarningMsg();
	std::string GetVersion();

	//Parsing functions following (in the recursive-descending order)...
	VALUES_TYPE Evaluate(const std::string& Source);

private:
	VALUES_TYPE	Level_1	(void);		// + , -
	VALUES_TYPE	Level_2	(void);		// * , /
	VALUES_TYPE	Level_3	(void);		// ^
	VALUES_TYPE	Level_4	(void);		// %
	VALUES_TYPE	Level_5	(void);		// ! , �
	VALUES_TYPE	Primary	(void);		// ( ) , Unary + , Unary -
	TokenValue	GetToken(void);
};


#endif // !defined(__AFX_VCALCPARSER_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)

Share

About the Author

toxcct
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.
 


| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141216.1 | Last Updated 28 Apr 2006
Article Copyright 2004 by toxcct
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid