int main() { int i; struct Grammar *pointer; struct Grammar *pointer1; struct Grammar *pointer2; pointer = (struct Grammar *)malloc(sizeof(struct Grammar)); pointer1 = (struct Grammar *)malloc(sizeof(struct Grammar)); pointer2 = (struct Grammar *)malloc(sizeof(struct Grammar)); printf("Grammar[Vn, Vt, P, S] Test\n"); printf("Input(1: Use built-in example 2: Input random grammar): "); scanf("%d", &i); if (i == 1) { // Initialize grammar's data. pointer->vn_len = 4; pointer->vt_len = 3; pointer->production_num = 7; pointer->vn[0] = 'S'; pointer->vn[1] = 'U'; pointer->vn[2] = 'V'; pointer->vn[3] = 'W'; pointer->vt[0] = 'a'; pointer->vt[1] = 'b'; pointer->vt[2] = 'c'; pointer->s = 'S'; pointer->production[0].tail_len = 2; pointer->production[1].tail_len = 1; pointer->production[2].tail_len = 1; pointer->production[3].tail_len = 1; pointer->production[4].tail_len = 2; pointer->production[5].tail_len = 2; pointer->production[6].tail_len = 2; pointer->production[0].head[0] = 'S'; pointer->production[0].tail[0] = 'a'; pointer->production[0].tail[1] = 'S'; pointer->production[1].head[0] = 'S'; pointer->production[1].tail[0] = 'W'; pointer->production[2].head[0] = 'S'; pointer->production[2].tail[0] = 'U'; pointer->production[3].head[0] = 'U'; pointer->production[3].tail[0] = 'a'; pointer->production[4].head[0] = 'V'; pointer->production[4].tail[0] = 'b'; pointer->production[4].tail[1] = 'V'; pointer->production[5].head[0] = 'V'; pointer->production[5].tail[0] = 'a'; pointer->production[5].tail[1] = 'c'; pointer->production[6].head[0] = 'W'; pointer->production[6].tail[0] = 'a'; pointer->production[6].tail[1] = 'W'; for (i = 0; i < 7; i++) { pointer->production[i].choose_flag = 0; } } else if (i == 2) { inputGrammar(pointer); } else { printf("Error, choice is not within the specified range!"); exit(0); } displayGrammar(pointer, 0); deleteUselessGrammar1(pointer, pointer1); deleteUselessGrammar2(pointer1, pointer2); return 0; }
/* constructor * initial garmmar input path * */ Parser:: Parser(char* input_path){ inputGrammar(input_path); }