static struct iteration_statement *parse_iteration_statement(struct parser *parser) { union token tok = lexer_next_token(parser->lexer); switch (tok.tok_tag) { case TOK_WHILE: return parse_while_statement(parser); case TOK_DO: return parse_do_while_statement(parser); case TOK_FOR: return parse_for_statement(parser); default: panic("ni %s", token_tag_str(tok.tok_tag)); } }
void test_while_statement() { char tmp; FILE *inn = fopen("tests/test_while_statement.txt", "r"); init_fake_symbol_table(); while (!feof(inn)) { in = fopen("test.txt", "w+"); while ((tmp = fgetc(inn)) != '}' && tmp != -1) fprintf(in, "%c", tmp); if (tmp == EOF) break; if (tmp <= 31) continue; fseek(in, 0, SEEK_SET); idx = 0; printf("******************\n"); label_top = 0; temp_table_top = 0; quadruple_top = 0; get_token_with_history(); parse_while_statement(); print_quadruples(); fclose(in); remove("test.txt"); } }