12,635,662 members (28,057 online)

260.8K views
105 bookmarked
Posted

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

, 28 Apr 2006 CPOL
How to start programming a parser.
 Visual Calc.exe mfc42.dll msvcrt.dll msvcp60.dll 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 VisualCalc.exe VCalcParser.dll msvcrt.dll msvcp71.dll msvcr71.dll MFC71.dll 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 VCalcParser.lib 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 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 Visual Calc.exe msvcp60.dll mfc42.dll msvcrt.dll 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  VisualCalc Parser: CVCalcParser Class Reference

CVCalcParser Class Reference

#include <VCalcParser.h>

List of all members.

Detailed Description

VisualCalc Parser.

This is the VisualCalc Parser class which take a formula as input, and returns either the floating point result or an error describing what is wrong in the string to parse.

The VisualCalc Parser is able to make the following actions, because of its data members :

• know what is the current Token during the parsing process,
• know depending on the case either the Function/Variable/Constant name, the number value or the current operator,
• raise a warning flag (non-blocking error during parsing),
• store the mathematic functions defined to be used in the formula to be parsed,
• store each variable name associated to its stored value,
• store each formula correctly parsed and the related result.

There is a public interface compound of :

• the constructor/Desctructor,
• the Functions/Variables/Answers lists handling member functions,
• the Warnings handling member functions.
• the Evaluate() member function, which launches the parsing process.

All the other member functions are private :

• the mathematic functions presented as the functions that can be used in the formula to be parsed,
• the 5 level functions and the 2 low level functions that actually make the parsing process.

Definition at line 113 of file VCalcParser.h.

Public Member Functions

CVCalcParser ()
VisualCalc Parser Constructor.
virtual ~CVCalcParser ()
VisualCalc Parser Destructor.
void ResetParserMembers (const std::string)
Resets the parser members state to default.
void ResetFunctions ()
Resets the functions list to its default state.
void ResetVariables ()
Resets the variables list to its default state.
Resets the answers history list to its default state.
const std::list< std::string > & GetFunctions ()
Returns the functions list.
const std::map< std::string,
VALUES_TYPE > &
GetVariables ()
Returns the variables map.
bool HasWarning ()
Tells if the parsing throws a warning.
std::string GetWarningMsg ()
Returns the warning message.
std::string GetVersion ()
Returns the version of the Parser.
VALUES_TYPE Evaluate (const std::string &Source) throw (CVCalcParserException)
Returns the result of the parsed formula.

Private Member Functions

VALUES_TYPE ffactor (VALUES_TYPE)
Returns the factorial of the operand.
VALUES_TYPE nCp (VALUES_TYPE, VALUES_TYPE)
Returns the p combinations on n.
VALUES_TYPE nAp (VALUES_TYPE, VALUES_TYPE)
Returns the p arrangements on n.
Returns the required Answer in the history.
VALUES_TYPE abs (VALUES_TYPE)
Returns the absolute value of the operand.
VALUES_TYPE cos (VALUES_TYPE)
Returns the cosine of the operand.
VALUES_TYPE sin (VALUES_TYPE)
Returns the sine of the operand.
VALUES_TYPE tan (VALUES_TYPE)
Returns the tangent of the operand.
VALUES_TYPE cosh (VALUES_TYPE)
Returns the hyperbolic cosine of the operand.
VALUES_TYPE sinh (VALUES_TYPE)
Returns the hyperbolic sine of the operand.
VALUES_TYPE tanh (VALUES_TYPE)
Returns the hyperbolic tangent of the operand.
VALUES_TYPE Acos (VALUES_TYPE)
Returns the arccosine of the operand.
VALUES_TYPE Asin (VALUES_TYPE)
Returns the arcsine of the operand.
VALUES_TYPE Atan (VALUES_TYPE)
Returns the arctangent of the operand.
VALUES_TYPE deg (VALUES_TYPE)
Returns a radian angle converted into degrees.
Returns a degrees angle converted into radians.
VALUES_TYPE exp (VALUES_TYPE)
Returns the exponential of the operand.
VALUES_TYPE ln (VALUES_TYPE)
Returns the natural logarithm of the operand.
VALUES_TYPE log (VALUES_TYPE)
Returns the decimal logarithm of the operand.
VALUES_TYPE logn (VALUES_TYPE, VALUES_TYPE)
Returns the base-n logarithm of the operand.
VALUES_TYPE sqrt (VALUES_TYPE)
Returns the square root of the operand.
VALUES_TYPE sqrtn (VALUES_TYPE, VALUES_TYPE)
Returns the n-order root of the operand.
VALUES_TYPE pow (VALUES_TYPE, VALUES_TYPE)
Returns the left operand raised to the power of the right operand.
VALUES_TYPE mod (VALUES_TYPE, VALUES_TYPE)
Returns the reminder of the first operand out of the second operand.
VALUES_TYPE sum (std::string expr, std::string var, VALUES_TYPE low, VALUES_TYPE high)
Returns the incremental sum of the expression.
VALUES_TYPE product (std::string expr, std::string var, VALUES_TYPE low, VALUES_TYPE high)
Returns the incremental product of the expression.
VALUES_TYPE Level_1 (void)
Computes the 'addition' and 'subtraction' operators.
VALUES_TYPE Level_2 (void)
Computes the 'multiplication' and 'division' operators.
VALUES_TYPE Level_3 (void)
Computes the 'power' operator.
VALUES_TYPE Level_4 (void)
Computes the 'modulus' operator.
VALUES_TYPE Level_5 (void)
Computes the 'factorial' and the "degree to radians" operators.
VALUES_TYPE Primary (void)
Computes the 'parenthesis', 'Unary +' and 'Unary -' operators.
TokenValue GetToken (void)
Reads the tokens from the input stream.
bool StepIndexForward (void)
Steps the stream reading index of one position further.

Private Attributes

const VALUES_TYPE m_PI
const VALUES_TYPE m_E
TokenValue m_tokCurrentToken
std::string m_strSource
std::string m_strIdentifierValue
std::string m_strWarningMsg
VALUES_TYPE m_valNumberValue
bool m_bWarningFlag
bool m_bEndEncountered
int m_iCurrentIndex
std::list< std::string > m_lstFunctions
std::map< std::string, VALUES_TYPEm_mapVariables
std::string m_strParserVersion

Constructor & Destructor Documentation

CVCalcParser::CVCalcParser  )

VisualCalc Parser Constructor.

Constructs an instance of the VisualCalc Parser.
It initializes the constant members m_PI, m_E and the Parser version string.
The Functions, Variables and Answers lists are also reset (cleared), as the other data members are also set to their default value.

Definition at line 22 of file VCalcParser.cpp.

CVCalcParser::~CVCalcParser  )  [virtual]

VisualCalc Parser Destructor.

As in the Constructor, the lists are reset to an empty content, and the other data members are set to a default state.

Definition at line 39 of file VCalcParser.cpp.

Member Function Documentation

VALUES_TYPE CVCalcParser::abs VALUES_TYPE  valOperand  )  [private]

Returns the absolute value of the operand.

Parameters:
valOperand Angle on which the absolute value is calculated.
Returns:
The absolute value of the operand.
This functions calculates the absolute value of its operand, and don't cause any error.

Definition at line 379 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::Acos VALUES_TYPE  valOperand  )  [private]

Returns the arccosine of the operand.

Parameters:
valOperand Operand on which the arccosine is calculated.
Returns:
The Angle in radian which is the arcosine of the operand.
Exceptions:
CParameterOutOfRangeException If an error occured during calculation.
This functions calculates the arccosine of its operand which is a value in the range [-1 ; 1] and the resulting angle is in the interval [0 ; pi]. Otherwise, a consequent exception is thrown.

Definition at line 546 of file VCalcParser.cpp.

AnswerItem CVCalcParser::Ans VALUES_TYPE  valIndex  )  [private]

Returns the required Answer in the history.

Parameters:
valIndex Index of the answer in the history.
Returns:
The Answer in the history at the position specified by the parameter.
Exceptions:
CDomParameterMustBePositiveException If the parameter is not strictly greater than 0.
CDomParameterMustBeAnIntegerException If the parameter is not an integer.
CAnswerRequestedNotFoundException If the parameter is not in the range [1 ; history_length].
It returns the AnswerItem positionned in the answers history at the index specified by the parameter.
The Index parameter value must be between 1 and the number of elements stored in the history, otherwise, a consequent exception is thrown.

Definition at line 353 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::Asin VALUES_TYPE  valOperand  )  [private]

Returns the arcsine of the operand.

Parameters:
valOperand Operand on which the arcsine is calculated.
Returns:
The Angle in radian which is the arcsine of the operand.
Exceptions:
CParameterOutOfRangeException If an error occured during calculation.
This functions calculates the arcsine of its operand which is a value in the range [-1 ; 1] and the resulting angle is in the interval [-pi/2 ; pi/2]. Otherwise, a consequent exception is thrown.

Definition at line 567 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::Atan VALUES_TYPE  valOperand  )  [private]

Returns the arctangent of the operand.

Parameters:
valOperand Operand on which the arctangent is calculated.
Returns:
The Angle in radian which is the arctangent of the operand.
Exceptions:
CParameterOutOfRangeException If an error occured during calculation.
This functions calculates the arctangent of its operand and the resulting angle is in the interval [-pi/2 ; pi/2]. Otherwise, a consequent exception is thrown.

Definition at line 587 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::cos VALUES_TYPE  valOperand  )  [private]

Returns the cosine of the operand.

Parameters:
valOperand Operand in radian on which the cosine is calculated.
Returns:
The cosine of the operand.
Exceptions:
CParameterOutOfRangeException If an error occured during calculation.
This functions calculates the cosine of its operand which is an angle in radians. If the angle is out of the range [-2^63 ; 2^63], the result may have a loss of significance.

Definition at line 395 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::cosh VALUES_TYPE  valOperand  )  [private]

Returns the hyperbolic cosine of the operand.

Parameters:
valOperand Angle in radian on which the hyperbolic cosine is calculated.
Returns:
The hyperbolic cosine of the operand.
Exceptions:
CParameterOutOfRangeException If an error occured during calculation.
This functions calculates the hyperbolic cosine of its operand which is an angle in radians :

If the angle is out of the range [-2^63 ; 2^63], the result may have a loss of significance.

Definition at line 469 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::deg VALUES_TYPE  valOperand  )  [private]

Returns a radian angle converted into degrees.

Parameters:
Returns:
The equivalence of the angle in degree.
This functions calculates the equivalent of its operand in degrees into radians.

Definition at line 604 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::Evaluate const std::string &  strSource  )  throw (CVCalcParserException)

Returns the result of the parsed formula.

Parameters:
strSource Formula to parse.
Returns:
The result of formula parsed.
Exceptions:
CVCalcParserException Whatever exception inherited from VisualCalc Parser Exceptions base class.
This function calculates the value of the formula passed in the strSource parameter.
If an error occured during the calculation, a meaningful exception is thrown describing the condition why this happend, and where it happened in the formula.
If the calculation succeed, the formula and its associated result are pushed in the Answers history.

Definition at line 873 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::exp VALUES_TYPE  valOperand  )  [private]

Returns the exponential of the operand.

Parameters:
valOperand Operand on which is calculated the exponential.
Returns:
The exponential of the operand.
This functions calculates the exponential of its operand and the result is in the interval ]0 ; +inf[.

Definition at line 631 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::ffactor VALUES_TYPE  valOperand  )  [private]

Returns the factorial of the operand.

Parameters:
valOperand The value on which the factorial is calculated.
Returns:
The factorial of the operand.
Exceptions:
CFactorialDefForPositiveIntsException If the operand is not greater than or equal to 0.
CMathParameterMustBeAnIntegerException If the operand is not an integer.
It calculates the factorial of the operand as the following formula describes :

As the mathematic factorial operator implies, the operand must be a positive operand, otherwise, a consequent exception is thrown.

Definition at line 224 of file VCalcParser.cpp.

Returns:
A reference to the answers history.
This function is a part of the public members of the Parser and interfaces the deque of the last formulas typed by the user which resulted into a valid answer, with their associated result.

Definition at line 166 of file VCalcParser.cpp.

const std::list< std::string > & CVCalcParser::GetFunctions  )

Returns the functions list.

Returns:
A reference to the functions list.
This function is a part of the public members of the Parser and interfaces the list of the functions available for the user.

Definition at line 140 of file VCalcParser.cpp.

TokenValue CVCalcParser::GetToken void   )  [private]

Reads the tokens from the input stream.

Returns:
The token extracted from the input stream.
Exceptions:
CVCalcParserException Whatever exception inherited from VisualCalc Parser Exceptions base class.
Level_1(), Level_2(), Level_3(), Level_4(), Level_5(), Primary()
The main purpose of this function is to read the input stream character by character to extract the relative tokens.
The white spaces between 2 tokens are not taken in account and don't change at all the meaning of the formula parsed.

It recognizes the following tokens :

• Operators : Whatever operator stored in TokenValue
• Numbers : Whenever a digit or a period ('.') is read
• Identifiers : When a letter or an underscore ('_') is read

Depending on the cases above, the relative token is stored whether in m_tokCurrentToken for any operator, m_valNumberValue for numbers and m_strIdentifierValue for identifiers.

If an unknown character is read or if a number is being extracted with more than 1 period character ('.'), then a relative exception is thrown.

Definition at line 1370 of file VCalcParser.cpp.

const std::map< std::string, VALUES_TYPE > & CVCalcParser::GetVariables  )

Returns the variables map.

Returns:
A reference to the variables map.
This function is a part of the public members of the Parser and interfaces the map of the variables typed by the user and the constants, with their associated value.

Definition at line 153 of file VCalcParser.cpp.

std::string CVCalcParser::GetVersion  )

Returns the version of the Parser.

Returns:
The version of the Parser.
It simply returns as an informative data member a string which contains the version of the Parser.

Definition at line 204 of file VCalcParser.cpp.

std::string CVCalcParser::GetWarningMsg  )

Returns the warning message.

Returns:
The warning message.
If the parsing of a formula causes a warning (non blocking error) due to possible loss of data, then the flag is set and a descritpion message is exposed through this member function of the public interface of the Parser.

Definition at line 192 of file VCalcParser.cpp.

bool CVCalcParser::HasWarning  )

Tells if the parsing throws a warning.

Returns:
The warning flag.
If the parsing of a formula causes a warning (non blocking error) due to possible loss of data, then the flag can be tested with this member function of the public interface of the Parser.

Definition at line 179 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::Level_1 void   )  [private]

Computes the 'addition' and 'subtraction' operators.

Returns:
The result of the current expression parsed.
Exceptions:
CVCalcParserException Whatever exception inherited from VisualCalc Parser Exceptions base class.
Level_2(), Level_3(), Level_4(), Level_5(), Primary(), GetToken()
This function is the first of 5 of the recursive descending levels of the Parser.
It computes the following operators :
• Addition : <expr> + <expr>
• Subtraction : <expr> - <expr>

If the current operator is not in the ones below, then the result of Level_2() is returned.

Definition at line 908 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::Level_2 void   )  [private]

Computes the 'multiplication' and 'division' operators.

Returns:
The result of the current expression parsed.
Exceptions:
CVCalcParserException Whatever exception inherited from VisualCalc Parser Exceptions base class.
Level_1(), Level_3(), Level_4(), Level_5(), Primary(), GetToken()
This function is the second of 5 of the recursive descending levels of the Parser.
It computes the following operators :
• Multiplication : <expr> * <expr>
• Division : <expr> / <expr>

If the current operator is not in the ones below, then the result of Level_3() is returned.
If the Parser tries to resolve a division which dividend is equal to 0, then the relative exception is thrown.

Definition at line 951 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::Level_3 void   )  [private]

Computes the 'power' operator.

Returns:
The result of the current expression parsed.
Exceptions:
CVCalcParserException Whatever exception inherited from VisualCalc Parser Exceptions base class.
Level_1(), Level_2(), Level_4(), Level_5(), Primary(), GetToken()

CVCalcParser::pow()

This function is the third of 5 of the recursive descending levels of the Parser.
It computes the following operators :
• Power : <expr> ^ <expr>

If the current operator is not in the ones below, then the result of Level_4() is returned.
In the case of a Power evaluation, the parameters read from the input stream are passed to the pow() member function, which can result in an exception if the conditions required for this calculation are not filled.

Definition at line 999 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::Level_4 void   )  [private]

Computes the 'modulus' operator.

Returns:
The result of the current expression parsed.
Exceptions:
CVCalcParserException Whatever exception inherited from VisualCalc Parser Exceptions base class.
Level_1(), Level_2(), Level_3(), Level_5(), Primary(), GetToken()

CVCalcParser::mod()

This function is the fourth of 5 of the recursive descending levels of the Parser.
It computes the following operators :
• Modulus : <expr> % <expr>

If the current operator is not in the ones below, then the result of Level_5() is returned.
In the case of a Modulus evaluation, the parameters read from the input stream are passed to the mod() member function, which can result in an exception if the conditions required for this calculation are not filled.

Definition at line 1034 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::Level_5 void   )  [private]

Computes the 'factorial' and the "degree to radians" operators.

Returns:
The result of the current expression parsed.
Exceptions:
CVCalcParserException Whatever exception inherited from VisualCalc Parser Exceptions base class.
Level_1(), Level_2(), Level_3(), Level_4(), Primary(), GetToken()

This function is the fifth of 5 of the recursive descending levels of the Parser.
It computes the following operators :
• Factorial : <expr> !
• Degree to radians : <expr> �

If the current operator is not in the ones below, then the result of Primary() is returned.
In the case of a factorial evaluation, the only parameter read from the input stream is passed to the ffactor() member function.
In the case of a Degree to radians evaluation, the only parameter read from the input stream is passed to the rad() member function.
Both cases can result in an exception if the conditions required for this calculation are not filled.

Definition at line 1073 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::ln VALUES_TYPE  valOperand  )  [private]

Returns the natural logarithm of the operand.

Parameters:
valOperand Operand on which is calculated the natural logarithm.
Returns:
The natural logarithm of the operand.
Exceptions:
CMathParameterMustBePositiveException If the parameter is not higher than or equal to 0.
This functions calculates the natural logarithm of its operand which must be in the interval ]0 ; +inf[.
The natural logarithm is a base-e logarithm :

Definition at line 648 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::log VALUES_TYPE  valOperand  )  [private]

Returns the decimal logarithm of the operand.

Parameters:
valOperand Operand on which is calculated the decimal logarithm.
Returns:
The decimal logarithm of the operand.
Exceptions:
CMathParameterMustBePositiveException If the parameter is not higher than or equal to 0.
This functions calculates the decimal logarithm of its operand which must be in the interval ]0 ; +inf[.
The decimal logarithm is a base-10 logarithm :

Definition at line 669 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::logn VALUES_TYPE  valOperand,
VALUES_TYPE  valBase
[private]

Returns the base-n logarithm of the operand.

Parameters:
valOperand Operand on which is calculated the base-n logarithm.
valBase Operand which determinates the base of the logarithm.
Returns:
The base-n logarithm of the operand.
Exceptions:
CMathParameterMustBePositiveException If the operand and/or the base parameter is/are not higher than or equal to 0.
CDivisionByZeroException If the base parameter is equal to 0.
This functions calculates the base-n logarithm of its operand which must be in the interval ]0 ; +inf[.
This logarithm, as its name tells, is a base-n logarithm :

Definition at line 693 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::mod VALUES_TYPE  valLeftOperand,
VALUES_TYPE  valRightOperand
[private]

Returns the reminder of the first operand out of the second operand.

Parameters:
valLeftOperand Numerator of the division of which the reminder is calculated.
valRightOperand Denominator of the division of which the reminder is calculated.
Returns:
Reminder of the first operand out of the second operand.
Exceptions:
CDivisionByZeroException If the right operand is equal to 0.
This functions calculates the reminder of the first operand out of the second operand.

Definition at line 797 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::nAp VALUES_TYPE  n,
VALUES_TYPE  p
[private]

Returns the p arrangements on n.

Parameters:
n The set on wich are calculated the arrangements.
p The number of arrangements on the n set.
Returns:
The p arrangements on n.
Exceptions:
CNMustBePositiveException If n is not greater than or equal to 0.
CPMustBePositiveException If p is not greater than or equal to 0.
CMathParameterMustBeAnIntegerException If n and/or p are not integers.
CPMustBeSmallerThanNException If p is not smaller than or equal to n.
It calculates the p arrangements on n as the following formula describes :

As the mathematic nAp operator implies, the n and p operands must be positive integers, plus p must be smaller than n, otherwise, a consequent exception is thrown.

Definition at line 312 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::nCp VALUES_TYPE  n,
VALUES_TYPE  p
[private]

Returns the p combinations on n.

Parameters:
n The set on wich are calculated the combinations.
p The number of combinations on the n set.
Returns:
The p combinations on n.
Exceptions:
CNMustBePositiveException If n is not greater than or equal to 0.
CPMustBePositiveException If p is not greater than or equal to 0.
CMathParameterMustBeAnIntegerException If n and/or p are not integers.
CPMustBeSmallerThanNException If p is not smaller than or equal to n.
It calculates the p combinations on n as the following formula describes :

As the mathematic nCp operator implies, the n and p operands must be positive integers, plus p must be smaller than n, otherwise, a consequent exception is thrown.

Definition at line 266 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::pow VALUES_TYPE  valLeftOperand,
VALUES_TYPE  valRightOperand
[private]

Returns the left operand raised to the power of the right operand.

Parameters:
valLeftOperand Operand which is raised to the power of the right operand.
valRightOperand Operand which raises the left operand to his power.
Returns:
The power of the left operand by the right operand.
Exceptions:
CMathParameterMustBePositiveException If the function tries to compute 0^y, where y is a floating point decimal strictly lower than 0.
This functions computes the left operand raised to the power of the right operand.
If the function tries to compute 0^0, the following warning is sent :
Warning: 0^0 replaced by 1.

Definition at line 773 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::Primary void   )  [private]

Computes the 'parenthesis', 'Unary +' and 'Unary -' operators.

Returns:
The result of the current expression parsed.
Exceptions:
CVCalcParserException Whatever exception inherited from VisualCalc Parser Exceptions base class.
Level_1(), Level_2(), Level_3(), Level_4(), Level_5(), GetToken()

This function intervenes after the 5th level function of the Parser.
It computes the following operators :
• Parenthesis : ( <expr> )
• Unary + : + <expr>
• Unary - : - <expr>

It also perform the following additional actions :

• Calls to the user functions
• Assignations/Recoverage of user variables

If the current operator is not in the ones below, then an exception is thrown saying that a mathematic expression is expected.
In the case of a user function handling, then the parameters read from the input are passed to the relative member function (each function presented in the user interface have its own private implementation within the parser class).
In the case of a user-defined variable handling, then either the data is retrieved if the variable aleady exists, otherwise it is assigned with a new value.
All cases can result in an exception if the conditions required for the handling are not filled.

Definition at line 1129 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::product std::string  expr,
std::string  var,
VALUES_TYPE  low,
VALUES_TYPE  high
[private]

Returns the incremental product of the expression.

Parameters:
expr Expression of which the product is to be avaluated.
var Variable in the expression which varies by increments.
low The integral lower bound of the sum.
high The integral higher bound of the sum.
Returns:
the incremental product of the expression.
Exceptions:
CFunctionNotSupportedException The function is not implemented yet.
Warning:
Not implemented yet.
This functions calculates the incremental product of the expression in which the variable takes integral values from the lower to the higher bound :

Definition at line 848 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::rad VALUES_TYPE  valOperand  )  [private]

Returns a degrees angle converted into radians.

Parameters:
valOperand degrees Angle.
Returns:
The equivalence of the angle in radians.
This functions calculates the arctangent of its operand and the resulting angle is in the interval [-pi/2 ; pi/2]. Otherwise, a consequent exception is thrown.

Definition at line 618 of file VCalcParser.cpp.

Resets the answers history list to its default state.

The history of the formulas typed by the user and their relative result is cleared and reset to aa empty list.

Definition at line 128 of file VCalcParser.cpp.

void CVCalcParser::ResetFunctions  )

Resets the functions list to its default state.

It initializes the list of the functions exposed for and usable by the user (in the string to be parser) with the functions name as they have to be typed (the parser is case sensitive on identifiers).

Definition at line 79 of file VCalcParser.cpp.

void CVCalcParser::ResetParserMembers const std::string  strSource  )

Resets the parser members state to default.

Parameters:
strSource String to initialize the source member with.
Resets the parser data members ; it set them to a defaut value :
• Source string with the parameter value,
• default token (end of the string to be parsed),
• empty identifier value (used for function and variable names),
• zero number value (used for calculated results),
• no warning (no message, no flag set),
• reading index placed at the begin of the Source string.

Definition at line 59 of file VCalcParser.cpp.

void CVCalcParser::ResetVariables  )

Resets the variables list to its default state.

The list of the variables used and defined by the user is cleared and reset to a default list.
The default list contains the mathematic constants pi and e (which cannot be removed from the variable list).

Definition at line 115 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::sin VALUES_TYPE  valOperand  )  [private]

Returns the sine of the operand.

Parameters:
valOperand Angle in radian on which the sine is calculated.
Returns:
The sine of the operand.
Exceptions:
CParameterOutOfRangeException If an error occured during calculation.
This functions calculates the sine of its operand which is an angle in radians. If the angle is out of the range [-2^63 ; 2^63], the result may have a loss of significance.

Definition at line 419 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::sinh VALUES_TYPE  valOperand  )  [private]

Returns the hyperbolic sine of the operand.

Parameters:
valOperand Angle in radian on which the hyperbolic sine is calculated.
Returns:
The hyperbolic sine of the operand.
Exceptions:
CParameterOutOfRangeException If an error occured during calculation.
This functions calculates the hyperbolic sine of its operand which is an angle in radians :

If the angle is out of the range [-2^63 ; 2^63], the result may have a loss of significance.

Definition at line 495 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::sqrt VALUES_TYPE  valOperand  )  [private]

Returns the square root of the operand.

Parameters:
valOperand Operand on which is calculated the square root.
Returns:
The square root of the operand.
Exceptions:
CMathParameterMustBePositiveException If the operand is not higher than or equal to 0.
This functions calculates the square root of its operand which must be in the interval [0 ; +inf[ :

Definition at line 720 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::sqrtn VALUES_TYPE  valOperand,
VALUES_TYPE  valOrder
[private]

Returns the n-order root of the operand.

Parameters:
valOperand Operand on which is calculated the n-order root.
valOrder Operand which determinates the order of the root.
Returns:
The n-order root of the operand.
Exceptions:
CMathParameterMustBePositiveException If the operand is not higher than or equal to 0, or if the order is not strictly higher than 0.
CMathParameterMustBeAnIntegerException If the order is not an integer.
This functions calculates the n-order root of its operand which must be in the interval [0 ; +inf[, with an integral order :

Definition at line 744 of file VCalcParser.cpp.

bool CVCalcParser::StepIndexForward void   )  [private]

Steps the stream reading index of one position further.

Returns:
A flag saying if the end of the formula was reached.
This function was made to factorize some code of the GetToken() function.
It increments the index on the stream and set the m_bEndEncountered flag to true if the end of the formula is encountered.

Definition at line 1517 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::sum std::string  expr,
std::string  var,
VALUES_TYPE  low,
VALUES_TYPE  high
[private]

Returns the incremental sum of the expression.

Parameters:
expr Expression of which the sum is to be avaluated.
var Variable in the expression which varies by increments.
low The integral lower bound of the sum.
high The integral higher bound of the sum.
Returns:
the incremental sum of the expression.
Exceptions:
CFunctionNotSupportedException The function is not implemented yet.
Warning:
Not implemented yet.
This functions calculates the incremental sum of the expression in which the variable takes integral values from the lower to the higher bound :

Definition at line 821 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::tan VALUES_TYPE  valOperand  )  [private]

Returns the tangent of the operand.

Parameters:
valOperand Angle in radian on which the tangent is calculated.
Returns:
The tangent of the operand.
Exceptions:
CParameterOutOfRangeException If an error occured during calculation.
This functions calculates the tangent of its operand which is an angle in radians. If the angle is out of the range [-2^63 ; 2^63], the result may have a loss of significance.

Definition at line 443 of file VCalcParser.cpp.

VALUES_TYPE CVCalcParser::tanh VALUES_TYPE  valOperand  )  [private]

Returns the hyperbolic tangent of the operand.

Parameters:
valOperand Angle in radian on which the hyperbolic tangent is calculated.
Returns:
The hyperbolic tangent of the operand.
Exceptions:
CParameterOutOfRangeException If an error occured during calculation.
This functions calculates the hyperbolic tangent of its operand which is an angle in radians :

If the angle is out of the range [-2^63 ; 2^63], the result may have a loss of significance.

Definition at line 521 of file VCalcParser.cpp.

Member Data Documentation

bool CVCalcParser::m_bEndEncountered [private]

The end of the input stream is reached

Definition at line 126 of file VCalcParser.h.

bool CVCalcParser::m_bWarningFlag [private]

Non-interrupting low level message

Definition at line 125 of file VCalcParser.h.

Answers History mapping a formula with a result

Definition at line 131 of file VCalcParser.h.

const VALUES_TYPE CVCalcParser::m_E [private]

32 digits e value : 2.7182818284590452353602874713527

Definition at line 117 of file VCalcParser.h.

int CVCalcParser::m_iCurrentIndex [private]

Index in the input stream

Definition at line 127 of file VCalcParser.h.

std::list<std::string> CVCalcParser::m_lstFunctions [private]

Supported functions

Definition at line 128 of file VCalcParser.h.

std::map<std::string, VALUES_TYPE> CVCalcParser::m_mapVariables [private]

User defined variables table mapping the identifier with a value

Definition at line 130 of file VCalcParser.h.

const VALUES_TYPE CVCalcParser::m_PI [private]

32 digits pi value : 3.1415926535897932384626433832795

Definition at line 116 of file VCalcParser.h.

std::string CVCalcParser::m_strIdentifierValue [private]

Identifier extracted as an IDENTIFIER token

Definition at line 122 of file VCalcParser.h.

std::string CVCalcParser::m_strParserVersion [private]

Version of the Parser

Definition at line 132 of file VCalcParser.h.

std::string CVCalcParser::m_strSource [private]

Reference to the input stream

Definition at line 121 of file VCalcParser.h.

std::string CVCalcParser::m_strWarningMsg [private]

To describe the warning

Definition at line 123 of file VCalcParser.h.

TokenValue CVCalcParser::m_tokCurrentToken [private]

Current token extracted from the input stream

Definition at line 120 of file VCalcParser.h.

VALUES_TYPE CVCalcParser::m_valNumberValue [private]

Number extracted as a NUMBER token

Definition at line 124 of file VCalcParser.h.

The documentation for this class was generated from the following files:
Generated on Mon Feb 6 23:55:57 2006 for VisualCalc Parser by  1.4.5


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.

## Share

 Software Developer (Senior) Accenture Technology Solutions 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.

## You may also be interested in...

 Pro Pro