int main(int argc, const char * argv[]) { Token *token; Token *token_list; //This needs to be implemented as a linked list in scanner.h. char source_name[MAX_FILE_NAME_LENGTH]; char date[DATE_STRING_LENGTH]; FILE *source_file = init_lister(argv[1], source_name, date); init_scanner(source_file, source_name, date); do { token = get_token(); add_token_to_list(token_list, token); print_token(token); } while (???);//What is the sentinal value that ends this loop? quit_scanner(source_file, token_list); return 0; }
int main(int argc, const char * argv[]) { Token *token; Token *token_list; char source_name[MAX_FILE_NAME_LENGTH]; char date[DATE_STRING_LENGTH]; FILE *source_file = init_lister(argv[1], source_name, date); init_scanner(source_file, source_name, date); init_scanner2(source_name, date); token_list = malloc(sizeof(Token)); token_list->nextptr = NULL; do { token = get_token(); add_token_to_list(token_list, token); print_token(token); } while (token->token_string[0] != '.'); quit_scanner(source_file, token_list); return 0; }
t_token_list *lexer(t_program_file *file, t_bool *lexer_result) { t_token_list *list; t_result result; t_file_reader file_reader; list = NULL; if (file == NULL) return (NULL); file_reader = generate_file_reader(file); while (string_reader_has_more(&file_reader)) { result = lex_token(&file_reader); if (result.type == RESULT_ERROR) return (print_syntax_error(&file_reader, &result.syntax_error, list)); else if (result.type == RESULT_NULL) return (print_unexpected_char_error(&file_reader, list)); else if (result.type == RESULT_TOKEN && add_token_to_list(&list, result.token)) return (print_error_n("Error while adding token to list.\n")); } *lexer_result = true; return (list); }