Token Parser::nextToken(void) { Token token; // Inicialmente marcamos como token no válido token.type = TK_NOTK; token.value = 0; if (m_tokenizer.hasMoreTokens()) { // De momento marcamos como cadena y obtenemos esta del tokenizador token.type = TK_STR; token.string = m_tokenizer.nextToken(); // Comprobamos si se trata de un número if (m_detect_numbers) { checkNum(token); } checkReservedWords(token); } else { // Si no quedan tokens, devolvemos el token fin de fichero token.type = TK_EOF; } return token; }
int scanFile(FILE *fp){ if(fp == NULL){ printf("File could not be found.\n"); return -1; } printf("Reading in tokens..."); while(fpeek(fp) != EOF){ int tokenStart = fgetc(fp); int error = 0; //If we read whitespace, continue; if(tokenStart == '\n' || tokenStart == '\r' || tokenStart == '\t' || tokenStart == '\v' || tokenStart == ' '){ continue; } error = checkSymbols(fp, tokenStart); if(error == 4){ printf("ERROR Invalid symbol '%c'\n", tokenStart); exit(4); } else if(error == 0){ continue; } error = checkReservedWords(fp, tokenStart); if(error == -1){ error = checkVariable(fp, tokenStart); if(error == 3){ printf("ERROR Name exceeds 11 characters\n"); exit(3); } else if(error == 0){ continue; } } else if(error == 0){ continue; } error = checkNumber(fp, tokenStart); if(error == 2){ printf("ERROR number exceeds 5 digits\n"); exit(2); } else if(error == 1){ printf("ERROR Variables can't start with a letter"); exit(1); } else if(error == 0){ continue; } } createToken("null", 1); printf("COMPLETE\n"); return 0; }