-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrpnCalc.c
41 lines (38 loc) · 864 Bytes
/
rpnCalc.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lexical.h"
#include "nextInputChar.h"
#include "tokenStack.h"
#include "doOperator.h"
int main(int argc, char *argv[])
{
struct tokenStack *stack;
struct lexToken *token;
int ret;
stack = createTokenStack();
setFile(stdin);
while(1) {
token = nextToken();
#ifdef DEBUG
printf("read in token "); dumpToken(stdout, token);
#endif
switch(token->kind) {
case LEX_TOKEN_EOF:
exit(0);
break;
case LEX_TOKEN_IDENTIFIER:
case LEX_TOKEN_OPERATOR:
ret = doOperator(stack, token->symbol);
freeToken(token);
if(ret < 0)
printf("unknown operator\n");
break;
case LEX_TOKEN_NUMBER:
pushTokenStack(stack, token);
break;
default:
fprintf(stderr,"unknown lex token kind %d\n", token->kind);
}
}
}