Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Parse.h"
- #include <vector>
- using namespace std;
- int GetCharacterRange (char input)
- {
- if (input >= CHAR_RANGE_UPPER_LOW)
- {
- if (input <= CHAR_RANGE_LOWER_HIGH)
- {
- if (input <= CHAR_RANGE_UPPER_HIGH)
- {
- return CHAR_RANGE_LETTER;
- }
- else if (input >= CHAR_RANGE_LOWER_LOW)
- {
- return CHAR_RANGE_LETTER;
- }
- else
- return CHAR_RANGE_INVALID;
- }
- }
- if (input < CHAR_RANGE_UPPER_LOW)
- {
- if (input >= CHAR_RANGE_NUM_LOW)
- {
- if (input <= CHAR_RANGE_NUM_HIGH)
- {
- return CHAR_RANGE_NUM;
- }
- }
- }
- if (input == CHAR_SIGN_MULTIPLY)
- return CHAR_RANGE_SIGN;
- if (input == CHAR_SIGN_MINUS)
- return CHAR_RANGE_SIGN;
- if (input == CHAR_SIGN_PLUS)
- return CHAR_RANGE_SIGN;
- if (input == CHAR_SIGN_DIVIDE)
- return CHAR_RANGE_SIGN;
- if (input == CHAR_SIGN_EQUAL)
- return CHAR_RANGE_SIGN;
- if (input == CHAR_SIGN_MULTIPLY)
- return CHAR_RANGE_SIGN;
- if (input == CHAR_MISC_SPACE)
- return CHAR_RANGE_SPACE;
- if (input == CHAR_MISC_PAR_R)
- return CHAR_RANGE_PAR;
- if (input == CHAR_MISC_PAR_L)
- return CHAR_RANGE_PAR;
- return CHAR_RANGE_INVALID;
- }
- Term * ParseForTerm (int start, int end)
- {
- return 0;
- }
- unsigned int ParseInput (char * input, Equation * output)
- {
- int inputLength = 0;
- while (input[inputLength] != 0)
- inputLength++;
- int * characterTypes;
- characterTypes = new int [inputLength];
- bool first = true;
- char variable;
- for (int i = 0; i < inputLength; i++)
- {
- characterTypes[i] = GetCharacterRange(input[i]);
- if (characterTypes[i] == CHAR_RANGE_INVALID)
- return -1; // Invalid symbol
- if (characterTypes[i] == CHAR_RANGE_LETTER)
- {
- if (first)
- {
- first = false;
- variable = input[i];
- }
- else if (!first)
- {
- if (input[i] != variable)
- return -2; // Multiple variables
- }
- }
- }
- int charCounter = 0;
- int parLCounter = 0;
- int parRCounter = 0;
- vector<int> signPositions;
- vector<int> parLPositions;
- vector<int> parRPositions;
- bool equalSign = false;
- while (charCounter < inputLength)
- {
- switch (characterTypes[charCounter])
- {
- case CHAR_RANGE_LETTER:
- break;
- case CHAR_RANGE_NUM:
- break;
- case CHAR_RANGE_SIGN:
- signPositions.push_back(charCounter);
- break;
- case CHAR_RANGE_SPACE:
- break;
- case CHAR_RANGE_PAR:
- if (characterTypes[charCounter] == CHAR_MISC_PAR_L)
- {
- parLPositions.push_back(charCounter);
- parLCounter++;
- }
- else if (characterTypes[charCounter] == CHAR_MISC_PAR_R)
- {
- parRPositions.push_back(charCounter);
- parRCounter++;
- }
- break;
- }
- charCounter++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement