-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_token.c
30 lines (22 loc) · 887 Bytes
/
input_token.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
#include "input_token.h"
#include "error.h"
void get_operand(int *w) {
int c;
*w = 0;
while ((c = getc(fpi)) != EOF)
if (c >= '0' && c <= '9') *w = 10*(*w) + c - 48;
else {ungetc(c,fpi); return;}
}
int get_token(int *w) {
int c;
while ((c = getc(fpi)) != EOF)
if ( c=='(' ) return(OpenBracket);
else if ( c==')' ) return(CloseBracket);
else if ( c=='+' ) return(Plus);
else if ( c=='-' ) return(Minus);
else if ( c=='*' ) return(Mult);
else if ( c=='/' ) return(Divide);
else if ( c>='0' && c<='9' ) {ungetc(c,fpi);get_operand(w);return(Operand);}
else if ( c>=33 && c<=126 ) error(1);
return(EOF);
}