ANSI C conversion.
This commit is contained in:
parent
21e15965cc
commit
53d2894ed1
|
@ -17,40 +17,46 @@ struct symtab *idtable, *deftable;
|
||||||
|
|
||||||
extern void error(char *s, char* s1);
|
extern void error(char *s, char* s1);
|
||||||
|
|
||||||
struct symtab *
|
struct symtab * findident(char *s, int mode, struct symtab **table)
|
||||||
findident(s, mode, table) char *s; struct symtab **table; {
|
{
|
||||||
/*
|
|
||||||
* Look for identifier s in the symboltable referred to by *table.
|
|
||||||
* If mode = LOOKING, no new entry's will be made.
|
|
||||||
* If mode = ENTERING, a new entry will be made if s is not in the
|
|
||||||
* table yet, otherwise an error results
|
|
||||||
*/
|
|
||||||
register struct symtab *p;
|
|
||||||
register int n;
|
|
||||||
|
|
||||||
if (!*table) { /* No entry for this symbol */
|
|
||||||
if (mode == LOOKING) return (struct symtab *) 0;
|
|
||||||
/*
|
/*
|
||||||
* Make new entry
|
* Look for identifier s in the symboltable referred to by *table.
|
||||||
|
* If mode = LOOKING, no new entry's will be made.
|
||||||
|
* If mode = ENTERING, a new entry will be made if s is not in the
|
||||||
|
* table yet, otherwise an error results
|
||||||
*/
|
*/
|
||||||
p = (struct symtab *) malloc(sizeof *p);
|
register struct symtab *p;
|
||||||
p->s_left = p->s_right = (struct symtab *) 0;
|
register int n;
|
||||||
p->s_name = malloc( (unsigned) (strlen(s) + 1));
|
|
||||||
strcpy(p->s_name,s);
|
if (!*table)
|
||||||
*table = p;
|
{ /* No entry for this symbol */
|
||||||
return p;
|
if (mode == LOOKING)
|
||||||
}
|
return (struct symtab *) 0;
|
||||||
else {
|
/*
|
||||||
p = *table;
|
* Make new entry
|
||||||
if ((n = strcmp(p->s_name,s)) == 0) { /* This is it! */
|
*/
|
||||||
if (mode == ENTERING) {
|
p = (struct symtab *) malloc(sizeof *p);
|
||||||
error("Identifier %s redefined",s);
|
p->s_left = p->s_right = (struct symtab *) 0;
|
||||||
}
|
p->s_name = malloc((unsigned) (strlen(s) + 1));
|
||||||
return p;
|
strcpy(p->s_name, s);
|
||||||
|
*table = p;
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
/* Binary tree ..... */
|
else
|
||||||
if (n < 0) return findident(s,mode,&(p->s_left));
|
{
|
||||||
return findident(s,mode,&(p->s_right));
|
p = *table;
|
||||||
}
|
if ((n = strcmp(p->s_name, s)) == 0)
|
||||||
/* NOTREACHED */
|
{ /* This is it! */
|
||||||
|
if (mode == ENTERING)
|
||||||
|
{
|
||||||
|
error("Identifier %s redefined", s);
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
/* Binary tree ..... */
|
||||||
|
if (n < 0)
|
||||||
|
return findident(s, mode, &(p->s_left));
|
||||||
|
return findident(s, mode, &(p->s_right));
|
||||||
|
}
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue