Skip to content

Commit 847ea39

Browse files
committed
correcting variable Token value
1 parent 9c5b0dc commit 847ea39

File tree

22 files changed

+35
-51
lines changed

22 files changed

+35
-51
lines changed
15 KB
Binary file not shown.
4 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

2019117865김나형/GLOBALS.H

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ typedef struct treeNode
7676
struct ScopeListRec* scope;
7777
} attr;
7878
ExpType type; /* for type checking of exps */
79-
int isParam;
80-
int arraysize;
8179
} TreeNode;
8280

8381
/**************************************************/

2019117865김나형/MAIN.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int Error = FALSE;
4848

4949
main( int argc, char * argv[] )
5050
{ TreeNode * syntaxTree;
51-
char pgm[120]="1.c"; /* source code file name */
51+
char pgm[120]; /* source code file name */
5252
if (argc != 2)
5353
{ fprintf(stderr,"usage: %s <filename>\n",argv[0]);
5454
exit(1);

2019117865김나형/UTIL.C

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -125,36 +125,3 @@ static void printSpaces(void)
125125
for (i=0;i<indentno;i++)
126126
fprintf(listing," ");
127127
}
128-
129-
/* procedure printTree prints a syntax tree to the
130-
* listing file using indentation to indicate subtrees
131-
*/
132-
void printTree( TreeNode * tree )
133-
{ int i;
134-
INDENT;
135-
while (tree != NULL) {
136-
printSpaces();
137-
if (tree->nodekind==ExpK)
138-
{ switch (tree->kind.exp) {
139-
case OpK:
140-
fprintf(listing,"Op: ");
141-
printToken(tree->attr.op,"\0");
142-
break;
143-
case ConstK:
144-
fprintf(listing,"Const: %d\n",tree->attr.val);
145-
break;
146-
case IdK:
147-
fprintf(listing,"Id: %s\n",tree->attr.name);
148-
break;
149-
default:
150-
fprintf(listing,"Unknown ExpNode kind\n");
151-
break;
152-
}
153-
}
154-
else fprintf(listing,"Unknown node kind\n");
155-
for (i=0;i<MAXCHILDREN;i++)
156-
printTree(tree->child[i]);
157-
tree = tree->sibling;
158-
}
159-
UNINDENT;
160-
}

2019117865김나형/scan.c

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,30 @@ static int EOF_flag = FALSE; /* corrects ungetNextChar behavior on EOF */
3131
/* getNextChar fetches the next non-blank character
3232
from lineBuf, reading in a new line if lineBuf is
3333
exhausted */
34+
static int getBeforeChar(void)
35+
{
36+
if (!(linepos < bufsize))
37+
{
38+
lineno++;
39+
if (fgets(lineBuf, BUFLEN - 1, source))
40+
{
41+
if (EchoSource) fprintf(listing, "%4d: %s", lineno, lineBuf);
42+
bufsize = strlen(lineBuf);
43+
linepos = 0;
44+
return lineBuf[linepos++];
45+
}
46+
else
47+
{
48+
lineno--;
49+
EOF_flag = TRUE;
50+
return EOF;
51+
}
52+
}
53+
else {
54+
return lineBuf[linepos - 1];
55+
}
56+
}
57+
3458
static int getNextChar(void)
3559
{
3660
if (!(linepos < bufsize))
@@ -93,7 +117,6 @@ TokenType getToken(void)
93117
/* current state - always begins at START */
94118
StateType state = START;
95119
/* flag to indicate save to tokenString */
96-
char rtn = "return";
97120

98121
int save;
99122
while (state != DONE)
@@ -289,30 +312,26 @@ TokenType getToken(void)
289312
if (!isdigit(c))
290313
{ /* backup in the input */
291314
if (isalpha(c)) {
292-
save = TRUE;
293315
currentToken = ERROR;
294316
}
295-
else {
296-
ungetNextChar();
297-
save = FALSE;
298-
state = DONE;
317+
if (currentToken != ERROR) {
299318
currentToken = NUM;
300319
}
320+
ungetNextChar();
321+
save = FALSE;
322+
state = DONE;
301323
}
302324
break;
303325
case INID:
304326
if (!isalpha(c))
305327
{ /* backup in the input */
306328
if (isdigit(c)) {
307-
save = TRUE;
308329
currentToken = ERROR;
309330
}
310-
else {
311-
ungetNextChar();
312-
save = FALSE;
313-
state = DONE;
314-
currentToken = ID;
315-
}
331+
currentToken = ID;
332+
ungetNextChar();
333+
save = FALSE;
334+
state = DONE;
316335
}
317336
break;
318337
case DONE:
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)