File tree 1 file changed +10
-1
lines changed
1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 6
6
#define MAXTOKEN 100
7
7
8
8
enum { NAME , PARENS , BRACKETS };
9
+ enum { NO , YES };
9
10
10
11
void dcl (void );
11
12
void dirdcl (void );
@@ -16,6 +17,7 @@ char token[MAXTOKEN]; /* last token string */
16
17
char name [MAXTOKEN ]; /* indetifier name */
17
18
char datatype [MAXTOKEN ]; /* data type = char, int, etc. */
18
19
char out [1024 ]; /* output string */
20
+ int prevtoken = NO ; /* to indicate if there was a previous token */
19
21
20
22
int main () {
21
23
while (gettoken () != EOF ) { /* 1st token on line */
@@ -50,8 +52,10 @@ void dirdcl(void) {
50
52
printf ("error: missing )\n" );
51
53
} else if (tokentype == NAME ) /* variable name */
52
54
strcpy (name , token );
53
- else
55
+ else {
54
56
printf ("error: expected name or (dcl)\n" );
57
+ prevtoken = YES ;
58
+ }
55
59
while ((type = gettoken ()) == PARENS || type == BRACKETS )
56
60
if (type == PARENS )
57
61
strcat (out , " function returning" );
@@ -67,6 +71,11 @@ int gettoken(void) /* return next token */ {
67
71
void ungetch (int );
68
72
char * p = token ;
69
73
74
+ if (prevtoken == YES ) {
75
+ prevtoken = NO ;
76
+ return tokentype ;
77
+ }
78
+
70
79
while ((c = getch ()) == ' ' || c == '\t' )
71
80
;
72
81
if (c == '(' ) {
You can’t perform that action at this time.
0 commit comments