blob: 00ad493bb178546de6ffca7684c13c96b1d5fb2e (
plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#define MAXOP 100
#define MAXLINE 1000
#define NUM '0'
#define FUN '1'
#define VAR '2'
int getop(char[]);
void push(double);
double peek();
double pop();
void clear();
int main(int argc, char *argv[]) {
int type;
char s[MAXOP];
printf("Press CTRL+C to exit\n");
while (type == getop(s)) {
switch (type) {
case NUM:
break;
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
break;
case '%':
break;
case '=':
break;
case FUN:
break;
default:
printf("error: unknown command %s\n", s);
}
}
return 0;
}
int ptr = 0;
int line[MAXLINE];
void mgetline() {
int i, c;
for (i = 0; i < MAXLINE - 1 && (c = getchar()) != '\n' && c != EOF; i++) {
line[i] = c;
}
line[i] = 0;
ptr = 0;
}
int getop(char s[]) {
int i, c;
if (line[ptr] == 0)
mgetline();
// get next token
for (i = 0; i < MAXOP - 1 && (c = line[ptr]) != ' ' && c != 0; i++, ptr++)
s[i] = c;
s[i] = 0;
// opertor, single digit or variable
if (i == 1) {
if (isdigit(s[0]))
return NUM;
else if (isalpha(s[0]))
return VAR;
else
return s[0];
}
return FUN;
}
|