def find_first(prod) : list_first_production = [] bool_epsilon = True list_elem_prod = first.segment_production_into_terminals_and_non_terminals(prod) for elem in list_elem_prod : print elem + ' ---- ' list_first_production += [] list_first_production += first_table[elem] if not '@' in list_first_production : bool_epsilon = False break # end for firsts = list(set(list_first_production)) #print firsts if '@' in firsts : return firsts.remove('@'), bool_epsilon else : return firsts, bool_epsilon
def generate_follow_variables() : global graph augmented_dic = {} for elem in graph : for prod in graph[elem] : segmented_production = first.segment_production_into_terminals_and_non_terminals(prod) len_of_production = len(segmented_production) for i in range(len_of_production - 1) : if segmented_production[i] in augmented_dic : augmented_dic[segmented_production[i]] += [update_aug(segmented_production[i + 1:] + [elem])] else : augmented_dic[segmented_production[i]] = [update_aug(segmented_production[i + 1:] + [elem])] #end loop #linking last element to the BOSS if segmented_production[len_of_production - 1] in augmented_dic : augmented_dic[segmented_production[len_of_production - 1]] += [update_aug([elem])] else : augmented_dic[segmented_production[len_of_production - 1]] = [update_aug([elem])] #end 2nd inner loop #end outer loop return augmented_dic
def generate_follow_variables(): global graph, set_terminal, set_non_terminal augmented_dic = {} for elem in graph: for prod in graph[elem]: segmented_production = first.segment_production_into_terminals_and_non_terminals( prod) len_of_production = len(segmented_production) for i in range(len_of_production - 1): if segmented_production[i] in augmented_dic: augmented_dic[segmented_production[i]] += [ update_aug(segmented_production[i + 1:] + [elem]) ] else: augmented_dic[segmented_production[i]] = [ update_aug(segmented_production[i + 1:] + [elem]) ] #end loop #linking last element to the BOSS if segmented_production[len_of_production - 1] in augmented_dic: augmented_dic[segmented_production[len_of_production - 1]] += [update_aug([elem])] else: augmented_dic[segmented_production[len_of_production - 1]] = [update_aug([elem])] #end 2nd inner loop #end outer loop for elem in set_non_terminal: #print elem if not elem in augmented_dic: print "yes" augmented_dic[elem] = [[]] #covering the loop hole #print augmented_dic #print "--Augmented dic----" return augmented_dic