Skip to content

Commit b4b84f5

Browse files
committed
modified dcl
1 parent c28fd90 commit b4b84f5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: Chapter-5/Exercise 5-18/main.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define MAXTOKEN 100
77

88
enum { NAME, PARENS, BRACKETS };
9+
enum { NO, YES };
910

1011
void dcl(void);
1112
void dirdcl(void);
@@ -16,6 +17,7 @@ char token[MAXTOKEN]; /* last token string */
1617
char name[MAXTOKEN]; /* indetifier name */
1718
char datatype[MAXTOKEN]; /* data type = char, int, etc. */
1819
char out[1024]; /* output string */
20+
int prevtoken = NO; /* to indicate if there was a previous token */
1921

2022
int main() {
2123
while (gettoken() != EOF) { /* 1st token on line */
@@ -50,8 +52,10 @@ void dirdcl(void) {
5052
printf("error: missing )\n");
5153
} else if (tokentype == NAME) /* variable name */
5254
strcpy(name, token);
53-
else
55+
else {
5456
printf("error: expected name or (dcl)\n");
57+
prevtoken = YES;
58+
}
5559
while ((type = gettoken()) == PARENS || type == BRACKETS)
5660
if (type == PARENS)
5761
strcat(out, " function returning");
@@ -67,6 +71,11 @@ int gettoken(void) /* return next token */ {
6771
void ungetch(int);
6872
char *p = token;
6973

74+
if (prevtoken == YES) {
75+
prevtoken = NO;
76+
return tokentype;
77+
}
78+
7079
while((c = getch()) == ' ' || c == '\t')
7180
;
7281
if (c == '(') {

0 commit comments

Comments
 (0)