Created
October 14, 2018 04:40
-
-
Save ampli/01a2b82fbe23e3231bcfcb9d50cbd4bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define EXP_STACKSIZE 1000 | |
static void push_elist(E_list *s[], int *i, E_list *e) | |
{ | |
assert(*i < EXP_STACKSIZE); | |
s[(*i)++] = e; | |
} | |
static E_list *pop_elist(E_list *s[], int *i) | |
{ | |
return s[--(*i)]; | |
} | |
static E_list *next_E_list(E_list *s[], int *si) | |
{ | |
E_list *p = pop_elist(s, si); | |
Exp *t = p->e; | |
if (t->type != CONNECTOR_type) | |
{ | |
for (E_list *l = t->u.l; l != NULL; l = l->next) | |
push_elist(s, si, l); | |
} | |
return p; | |
} | |
void free_Exp(Exp *e) | |
{ | |
if (e == NULL) return; | |
int si; | |
E_list *s[EXP_STACKSIZE]; | |
/* Make the expression look like E_list. */ | |
s[0] = &(E_list){ NULL, e }; | |
si = 1; | |
while (si > 0) | |
{ | |
E_list *p = next_E_list(s, &si); | |
free(p->e); | |
if (e != p->e) free(p); | |
} | |
} | |
void free_E_list(E_list *l) | |
{ | |
if (l == NULL) return; | |
int si; | |
E_list *s[EXP_STACKSIZE]; | |
s[0] = l; | |
si = 1; | |
while (si > 0) | |
{ | |
E_list *p = next_E_list(s, &si); | |
free(p->e); | |
free(p); | |
} | |
} | |
int size_of_expression(Exp * e) | |
{ | |
if (e == NULL) return 0; | |
E_list *s[1000]; | |
int si; | |
int size = 0; | |
/* Make the expression look like E_list. */ | |
s[0] = &(E_list){ NULL, e }; | |
si = 1; | |
while (si > 0) | |
{ | |
E_list *p = next_E_list(s, &si); | |
if (p->e->type == CONNECTOR_type) size++; | |
} | |
return size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment