Source code

This page describes the content of the source files briefly.

main.cpp
The main file contains the function main which is executed when the program is started. It contains a loop where the user can give an expression as input, then calculates and dispays the result. The loop is repeated until the user enters an empty expression, then the program is ended.

parser.h
parser.cpp
The class Parser which is declared in parser.h is the core of the expression parser. This class contains the code required for parsing a string containing a mathematical expression.

variablelist.h
variablelist.cpp
To store declared variables, a class Variablelist is used. The class Parser has (amongst others) one Variablelist as data.

functions.h
functions.cpp
These files contain two mathematical functions which are not pre-defined in c++, and therefore had to be written by hand: factorial and sign.

error.h
error.cpp
When an error occurs when parsing an expression, an error of class Error is thrown. All possible error messages are stored in the class Error, to make it easy to extend the parser to support multiple languages. All errors have a unique number.

constants.h
This file just contains some constants used in the parser, for the maximum length of expressions, function names, and variable names.