static int analyze_def(NODE* head, enum nonterminal_enum tp){ const char * ctemp ; if((ctemp = head->child_head->child_head->name) == terminal_name[TYPE - WHILE] ){ NODE* temp = head->child_head->child_head ;//TYPE node analyze_basictype(temp); temp = head->child_head->next_sister ;//SEMI or ExtDecList or FunDec or DecList or VarDec process_def(temp ,tp); }else if(ctemp == nonterminal_name[StructSpecifier]){ const char * ctemp = head->child_head->child_head->child_head->next_sister->name; NODE* temp = head->child_head->child_head->child_head->next_sister ;//OptTag or tag if(ctemp == nonterminal_name[OptTag]){ NODE* temp = head->child_head->child_head->child_head->next_sister;//OptTag analyze_opttag(temp,tp); }else if(ctemp == nonterminal_name[Tag]){ NODE* temp = head->child_head->child_head->child_head->next_sister->child_head ;//ID analyze_tag(temp,tp); }else { perror("unknown error :2"); exit(EXIT_FAILURE); } temp = head->child_head->next_sister ;//SEMI or ExtDecList or FunDec or DecList or VarDec process_def(temp,tp); }else { perror("unknown error :1"); exit(EXIT_FAILURE); } return 0; }
int main(int argc, char **argv) { char ch[TailleLigne], ch2[TailleLigne], *chid, *chpos, *chword, *chdesc, *chtype, *chextent, chNE[100]; int nb, insent, i, j, beginNE; FILE *file_tk, *file_pos; file_tk = file_pos = NULL; if (argc > 1) for (nb = 1; nb < argc; nb++) if (!strcmp(argv[nb], "-tk")) { if (nb + 1 == argc) ERREUR("an option must follow option:", argv[nb]); if (!(file_tk = fopen(argv[++nb], "rt"))) ERREUR("can't open:", argv[nb]); } else if (!strcmp(argv[nb], "-pos")) { if (nb + 1 == argc) ERREUR("an option must follow option:", argv[nb]); if (!(file_pos = fopen(argv[++nb], "rt"))) ERREUR("can't open:", argv[nb]); } else if (!strcmp(argv[nb], "-h")) { fprintf(stderr, "Syntax: %s [-h] -tk <file> -pos <file>\n", argv[0]); exit(0); } else ERREUR("unknown option:", argv[nb]); if ((!file_tk) || (!file_pos)) ERREUR("bad syntax, check '-h'", ""); while ((fgets(ch2, TailleLigne, file_pos)) && (!strstr(ch2, "<word"))); if (!feof(file_pos)) analyze_pos(ch2, &chid, &chpos, &chword); else ERREUR("empty POS file ??", ""); for (chNE[0] = '\0', beginNE = insent = False, nb = 0; fgets(ch, TailleLigne, file_tk); nb++) if (strstr(ch, "<tokens")) insent = True; else if (strstr(ch, "</tokens")) { insent = False; printf("\n"); } else if (insent) { if (strstr(ch, "<token ")) if (!strstr(ch, "sgmltag")) { if (chid == NULL) ERREUR("files TOKEN and POS are not synchronized !!", ""); for (i = 0; (ch[i]) && (strncmp(ch + i, "id=", 3)); i++); if (!ch[i]) ERREUR("bad token string:", ch); for (j = i + 4; (ch[j]) && (ch[j] != '"'); j++); if (!ch[j]) ERREUR("bad token string:", ch); ch[j] = '\0'; /* * printf("[%s] == * [%s]\n",ch+i+4,chid) ; */ if (!strcmp(ch + i + 4, chid)) { printf("%s\t%s\t", chword, chpos); if (chNE[0]) printf("%c-%s\n", beginNE ? 'B' : 'I', chNE); else printf("O\n"); while ((fgets(ch2, TailleLigne, file_pos)) && (!strstr(ch2, "<word"))); if (!feof(file_pos)) analyze_pos(ch2, &chid, &chpos, &chword); else chid = chpos = chword = NULL; } beginNE = False; } else { analyze_tag(ch, &chdesc, &chtype, &chextent); if (!strcmp(chtype, "entities")) { if (!strcmp(chextent, "begin")) { for (i = 0; (chdesc[i]) && (chdesc[i] != '.'); i++) chNE[i] = SI_MINUSCULE(chdesc[i]) ? chdesc[i] - ('a' - 'A') : chdesc[i]; chNE[i] = '\0'; beginNE = True; } else { beginNE = False; chNE[0] = '\0'; } } } } exit(0); }