static int rdp_check_nullable(void * base) { int bad = 0; rdp_data * temp =(rdp_data *) symbol_next_symbol_in_scope(base); set_ work = SET_NULL; while (temp != NULL) { if (temp->contains_null &&(temp->kind != K_CODE)) { set_assign_set(& work, & temp->first); set_intersect_set(& work, & temp->follow); if (set_cardinality(& work)!= 0) { text_message(TEXT_ERROR, "LL(1) violation - rule\n %s ::= ", temp->id); rdp_print_sub_item(temp, 1); text_printf(".\n contains null but first and follow sets both include: "); set_print_set(& work, rdp_token_string, 78); text_printf("\n"); temp->ll1_violation = 1; bad = 1; } } temp =(rdp_data *) symbol_next_symbol_in_scope(temp); } return bad; }
static int rdp_check_disjoint(void * base) { int bad = 0; set_ work = SET_NULL; rdp_data * temp =(rdp_data *) symbol_next_symbol_in_scope(base); while (temp != NULL) { if (set_includes_element(& rdp_production_set, temp->kind)&& temp->kind != K_SEQUENCE) { rdp_list * left = temp->list; while (left != NULL) { rdp_list * right = left->next; while (right != NULL) { /* First check for disjoint on epsilon */ if (left->production->contains_null && right->production->contains_null) { text_message(TEXT_ERROR, "LL(1) violation - rule \'%s\'\n", temp->id); text_printf(" productions %s ::= ", left->production->id); rdp_print_sub_item(left->production, 1); text_printf(".\n and %s ::= ", right->production->id); rdp_print_sub_item(right->production, 1); text_printf(".\n are both nullable \n"); left->production->ll1_violation = 1; right->production->ll1_violation = 1; bad = 1; } set_assign_set(& work, & left->production->first); set_intersect_set(& work, & right->production->first); if (set_cardinality(& work)!= 0) { text_message(TEXT_ERROR, "LL(1) violation - rule \'%s\'\n", temp->id); text_printf(" productions %s ::= ", left->production->id); rdp_print_sub_item(left->production, 1); text_printf(".\n and %s ::= ", right->production->id); rdp_print_sub_item(right->production, 1); text_printf(".\n share these start tokens: "); set_print_set(& work, rdp_token_string, 78); text_printf("\n"); left->production->ll1_violation = 1; right->production->ll1_violation = 1; bad = 1; } right = right->next; } left = left->next; } } temp =(rdp_data *) symbol_next_symbol_in_scope(temp); } return bad; }
int scan_test_set(const char * production, set_ * valid, set_ * stop) { if (!set_includes_element(valid, SCAN_CAST->token)) { if (stop != NULL) { if (production != NULL) text_message(TEXT_ERROR_ECHO, "In rule \'%s\', scanned ", production); else text_message(TEXT_ERROR_ECHO, "Scanned "); set_print_element(SCAN_CAST->token, scan_token_names); text_printf(" whilst expecting %s", set_cardinality(valid)== 1 ? "": "one of "); set_print_set(valid, scan_token_names, 60); text_printf("\n"); scan_skip(stop); } return 0; } else return 1; }