BINTREE *createBinTree() { int k; FILE *file = fopen("input.txt", "r"); BINTREENODE *p, *t; BINTREE *bt; bt = malloc(sizeof(BINTREE)); memset(bt, 0, sizeof(BINTREE)); STACK stack; stack.top = 0; char c; c = getc(file); while (c != '#') { switch (c) { case '(': stackPush(&stack, (int)p); k = 1; break; case ')': stackPop(&stack, (int *)&t); break; case ',': k = 2; break; default: p = malloc(sizeof(BINTREENODE)); memset(p, 0, sizeof(BINTREENODE)); p->data = c; if (bt->root == NULL) { bt->root = p; } else { if (k == 1) { stackGet(&stack, (int *)&t); t->left = p; } else { stackGet(&stack, (int *)&t); t->right= p; } } break; } c = getc(file); } fclose(file); return bt; }
// Return the index on stack of previous indent level == i else -1 static STACK_INT pythonbriefLexer_findPreviousIndent( ppythonbriefLexer ctx, STACK_INT i ) { STACK_INT j; for ( j = ctx->identStack->vector->count - 1; j >= 0; --j ) { STACK_INT pos = (STACK_INT) (stackGet( ctx->identStack, j )); if ( pos == i ) return j; } return FIRST_CHAR_POSITION; }