;
ungetch (ch);
get_number ();
return curr_tok = NUMBER;
default:
ps = ' X0';
if (Isalpha (ch))
ungetch (ch);
get_name ();
return curr_tok = NAME;
error ("Invalid symbol ");
return curr_tok = PRINT;
/* ===================== Перевірка дублювання знаку операції ================ */ p>
void dupl_oper_verify (char ps, char ch)
if (Ps == '*' | | ps == '/' | | ps == '+' | | ps == '-' | | ps == '^')
error ("Operation is duplicated "),
ch = Ps;
else
putch (ch);
if (Ps == '*' | | ps == '/' | | ps == '+' | | ps == '-' | | ps == '^') ps = ch;
/* ==================================== Введення числа ======= ==================== */
void get_number ()
char ch, dec_flag = 0;
char * Anum;
int i = 0;
anum = (Char *) Malloc (32);
do
ch = getch ();
if (Isdigit (ch))
putch (ch);
* (anum + i) = Ch;
i + +;
else
if (Ch == '.') br/>
if (Dec_flag) error ("Second decimal point is forbidden");
else
В
dec_flag = 1;
putch (ch);
* (anum + i) = Ch;
i + +;
В
else
if (Ch == BACKSPACE) back_space (& i);
else
if (! Term_sym (ch))
В
error ("Invalid symbol ");
ch = BACKSPACE;
В
while (I <31 && (isdigit (ch) | | ch == '.' | | Ch == BACKSPACE));
anum [i] = ' X0';
number_value = _atold (Anum);
ungetch (ch);
free (anum);
/* ===================== Перевірка на термінальний символ ===================== */
int term_sym (char ch)
if (Ch == '*' | | ch == '/' | | ch == '+' | | ch == '-' | |
ch == '(' | | Ch == ')' | | ch == '=' | | ch == '^' | |
ch == ESC | | ch == ';' | | ch == ' r') return 1;
else return 0;
/* ================ Виправлення помилки клавішею BACKSPACE ==================== */
void back_space (int * i)
if (I)
gotoxy (wherex () -1, wherey ());
putch (' '); p> gotoxy (wherex () -1, wherey ());
i -;
/* ======================== Введення імені функції ================== ============ */
void get_name ()
char ch;
int i = 0, j;
do
ch = Getch ();
if (Isalnum (ch))
putch (ch);
* (func_name + i) = Ch;
i + +;
for (J = 0; j <42 && strncmp (funcs + j, func_name, i), j + = 6),
if (J> = 42)
error ("Invalid function ");
i -;
else
if (Ch == BACKSPACE) back_space (& i);
else
if (! Term_sym (ch))
В
error ("Invalid symbol ");
ch = BACKSPACE;
В
while (I <5 && (isalnum (ch) | | ch == BACKSPACE));
* (func_name + i) = ' X0';
function_number = J/6;
ungetch (ch);
/* ===================== Обчислення повного вираження ======================== */
double expr ()
double left = term ();
while (1)
switch (curr_tok)
case PLUS:
get_token ();
left + = Term ();
break;
case MINUS:
get_token ();
left - = Term ();
break;
default:
if (Curr_tok! = RP)
// gotoxy (31,8);
gotoxy (23,8);
printf ("");
gotoxy (23,8);
return left;
/* =========================== Обчислення доданка ================ ========= */
double term ()
double left = prim ();
while (1)
switch (curr_tok)
case MUL:
get_token ();
left * = Term ();
break;
case DIV:
get_token ();
float d = prim ();
if (! D) return error ("Division by zero");
left/= D;
break;
case POWER:
get_token ();
left = Pow (left, term ());
default:
return left;
/* ================== Обчислення первинної частині виразу =================== */
double prim ()
switch (curr_tok)
case NUMBER
get_token ();
return number_value;
case NAME:
get_token ();
return function_value ();
case MINUS:
get_token ();
return -Prim ();
case LP:
get_token ();
...