/** * Production: * stmt -> 'IF_IDEN' 'PAREN_S' expr 'PAREN_E' 'BRACE_S' stmt 'BRACE_E' */ void ifStatement(struct Term *term, FILE *input, ProgramData *prog){ // vars char value; const unsigned int buf_size = 64; char misc_buf[buf_size]; struct Term * new_term; // The 'IF_IDEN' terminal has already been consumed, process all else value = readNonEmptyChar(input, prog); if(value == PAREN_S){ addChildTerm(createSingleCharTerm(PAREN_S), term); } else{ // produce error } // consume the expression until the 'PAREN_E' is found if(consumeUntil(input, misc_buf, buf_size, PAREN_E, prog) == -1){ // produce error } // produce a Term for the expression, then attempt to parse it addChildTerm(createTerm(misc_buf, buf_size), term); // parse statement within the if-statement // STUB // check parsed statement if(prog->has_error) return; // someone beneath us failed // add the closing parenthesis addChildTerm(createSingleCharTerm(PAREN_S), term); // next, consume the 'BRACE_S' identifier value = readNonEmptyChar(input, prog); if(value == PAREN_S){ addChildTerm(createSingleCharTerm(BRACE_S), term); } else{ // produce error } // consume the following statement // consume the final identifier, 'BRACE_E' }
void readWordbyWord(const char * path , Index * i) { FILE * text = fopen(path,"r") ; char * word ; word = malloc(sizeof(char)*100) ; if (text != NULL) { while(fscanf(text,"%s",word) != EOF) { if ((!isInBeacons(word)) && (isWordRelevant(word))) { if (doesTermExist(*i ,word) == FALSE) { Term * t = (Term*) malloc(sizeof(Term)) ; createTerm(t , word) ; addTerm(i , *t) ; } else { Cell * cTmp = *i ; while ( strcmp(cTmp->t1.word , word) != 0) { cTmp = (cTmp)->ptr_next ; } (cTmp)->t1.occur ++ ; } } } fclose(text) ; } free(word) ; }
Document::Document(uint64_t id, std::string contents): mId(id), mContents(contents) { createTerm(); }