-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefinition.cpp
69 lines (57 loc) · 1.5 KB
/
Definition.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "Definition.h"
#include<iostream>
#include<string>
using std::string;
using std::prev;
bool is_alpha(const char simbol)
{
return (simbol >= ALPHABET_BEGIN && simbol <= ALPHABET_END) ? true : false;
}
bool is_point(const char simbol)
{
return (simbol == POINT || simbol == COMA) ? true : false;
}
bool is_digit(const char simbol)
{
return (simbol != p && isdigit(simbol));
}
bool is_digit(const char* str)
{
string str1(str),str2("0");
if (str1==str2)
return true;
return atof(str) ? true : false;
}
bool is_digit_or_alpha(const string::const_iterator & pos)
{
return(isalnum(*pos)) ? true : false;
}
bool is_operator(const string::const_iterator & pos)
{
return (*pos == ADDITION || *pos == DEDACTION || *pos == MULTIPLE || *pos == DIVISION || *pos==POWER || *pos== FACTORIAL || *pos==PERSENT) ? true : false;
}
bool is_bracket(const string::const_iterator & pos)
{
return (*pos == LEFT_BRACKET || *pos == RIGHT_BRACKET ) ? true : false;
}
size_t group_number(const string::const_iterator & pos)
{
if (is_digit_or_alpha(pos)) return 1;
if (is_operator(pos)) return is_unary_minus(pos) ? 1 : 2;
if (is_bracket(pos)) return 3;
return ERROR_FAILURE;
}
bool is_unary_minus(const string::const_iterator & pos)
{
return (*pos == DEDACTION && (*pos == 0 || *prev(pos)== LEFT_BRACKET || is_operator(prev(pos)))) ? true : false;
}
size_t simbol_type(const string::const_iterator & pos)
{
switch (group_number(pos))
{
case 1: {return 1; }
case 2: {return 2; }
case 3: {return 3;}
}
return ERROR_FAILURE;
}