Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1. #include "Parse.h"
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int GetCharacterRange (char input)
  6. {
  7.     if (input >= CHAR_RANGE_UPPER_LOW)
  8.     {
  9.         if (input <= CHAR_RANGE_LOWER_HIGH)
  10.         {
  11.             if (input <= CHAR_RANGE_UPPER_HIGH)
  12.             {
  13.                 return CHAR_RANGE_LETTER;
  14.             }
  15.             else if (input >= CHAR_RANGE_LOWER_LOW)
  16.             {
  17.                 return CHAR_RANGE_LETTER;
  18.             }
  19.             else
  20.                 return CHAR_RANGE_INVALID;
  21.         }
  22.     }
  23.  
  24.     if (input < CHAR_RANGE_UPPER_LOW)
  25.     {
  26.         if (input >= CHAR_RANGE_NUM_LOW)
  27.         {
  28.             if (input <= CHAR_RANGE_NUM_HIGH)
  29.             {
  30.                 return CHAR_RANGE_NUM;
  31.             }
  32.         }
  33.     }
  34.  
  35.     if (input == CHAR_SIGN_MULTIPLY)
  36.         return CHAR_RANGE_SIGN;
  37.     if (input == CHAR_SIGN_MINUS)
  38.         return CHAR_RANGE_SIGN;
  39.     if (input == CHAR_SIGN_PLUS)
  40.         return CHAR_RANGE_SIGN;
  41.     if (input == CHAR_SIGN_DIVIDE)
  42.         return CHAR_RANGE_SIGN;
  43.     if (input == CHAR_SIGN_EQUAL)
  44.         return CHAR_RANGE_SIGN;
  45.     if (input == CHAR_SIGN_MULTIPLY)
  46.         return CHAR_RANGE_SIGN;
  47.     if (input == CHAR_MISC_SPACE)
  48.         return CHAR_RANGE_SPACE;
  49.     if (input == CHAR_MISC_PAR_R)
  50.         return CHAR_RANGE_PAR;
  51.     if (input == CHAR_MISC_PAR_L)
  52.         return CHAR_RANGE_PAR;
  53.  
  54.     return CHAR_RANGE_INVALID;
  55. }
  56.  
  57. Term * ParseForTerm (int start, int end)
  58. {
  59.     return 0;
  60. }
  61.  
  62. unsigned int ParseInput (char * input, Equation * output)
  63. {
  64.     int inputLength = 0;
  65.  
  66.     while (input[inputLength] != 0)
  67.         inputLength++;
  68.  
  69.     int * characterTypes;
  70.     characterTypes = new int [inputLength];
  71.  
  72.     bool first = true;
  73.     char variable;
  74.     for (int i = 0; i < inputLength; i++)
  75.     {
  76.         characterTypes[i] = GetCharacterRange(input[i]);
  77.         if (characterTypes[i] == CHAR_RANGE_INVALID)
  78.             return -1; // Invalid symbol
  79.  
  80.         if (characterTypes[i] == CHAR_RANGE_LETTER)
  81.         {
  82.             if (first)
  83.             {
  84.                 first = false;
  85.                 variable = input[i];
  86.             }
  87.             else if (!first)
  88.             {
  89.                 if (input[i] != variable)
  90.                     return -2; // Multiple variables
  91.             }
  92.         }
  93.     }
  94.    
  95.     int charCounter = 0;
  96.     int parLCounter = 0;
  97.     int parRCounter = 0;
  98.  
  99.     vector<int> signPositions;
  100.     vector<int> parLPositions;
  101.     vector<int> parRPositions;
  102.  
  103.     bool equalSign = false;
  104.  
  105.     while (charCounter < inputLength)
  106.     {
  107.         switch (characterTypes[charCounter])
  108.         {
  109.         case CHAR_RANGE_LETTER:
  110.             break;
  111.         case CHAR_RANGE_NUM:
  112.             break;
  113.         case CHAR_RANGE_SIGN:
  114.             signPositions.push_back(charCounter);
  115.             break;
  116.         case CHAR_RANGE_SPACE:
  117.             break;
  118.         case CHAR_RANGE_PAR:
  119.             if (characterTypes[charCounter] == CHAR_MISC_PAR_L)
  120.             {
  121.                 parLPositions.push_back(charCounter);
  122.                 parLCounter++;
  123.             }
  124.             else if (characterTypes[charCounter] == CHAR_MISC_PAR_R)
  125.             {
  126.                 parRPositions.push_back(charCounter);
  127.                 parRCounter++;
  128.             }
  129.             break;
  130.         }
  131.         charCounter++;
  132.     }
  133.    
  134.     return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement