Exemple #1
0
    def getFollow(self):
        
        self.textBrowser_3 = QtGui.QTextBrowser(self.centralwidget)
        self.textBrowser_3.setObjectName(_fromUtf8("textBrowser_3"))
        self.gridLayout_3.addWidget(self.textBrowser_3, 1, 0, 1, 2)
        
        if len(self.grammar_list) == 0:
            self.showWarningMsg()
        else:
            follow = find_follow(self.grammar_list)

            self.showFollow(follow)
Exemple #2
0
    def getFollow(self):
        
        self.textBrowser_3 = QtGui.QTextBrowser(self.centralwidget)
        self.textBrowser_3.setObjectName(_fromUtf8("textBrowser_3"))
        self.gridLayout_3.addWidget(self.textBrowser_3, 1, 0, 1, 2)
        
        if len(self.grammar_list) == 0:
            self.showWarningMsg()
        else:
            follow = find_follow(self.grammar_list)

            self.showFollow(follow)
Exemple #3
0
def generate_table(grammar1):
    grammar_list = grammar1[:]
    O = getclosures(grammar1)
    # print(O)
    grammar = []
    k = 0
    for prod in grammar_list:
        prod = prod.split("->")
        grammar.append(prod)
        s = grammar[k][0].replace(' ', '')
        t = grammar[k][1].replace(' ', '')
        grammar[k][0] = s
        grammar[k][1] = t
        k = k + 1
        # print(s, t)

    follow = find_follow(grammar1)
    # print(follow)

    max = 0
    for o in O:
        S = o['to']
        integer = int(S[0])
        # print(integer, max)
        if integer > max:
            max = integer

    di = {}
    di['$'] = ''
    t = []
    for g in grammar:
        di[g[0]] = ''
        list_ = list(g[1])
        for l in list_:
            di[l] = ''
    L = []

    di['e'] = ''
    di[''] = ''
    del di['e']
    del di['']

    for i in range(0, max + 1):
        L.append(copy.deepcopy(di))

    for o in O:
        i = o['to'][0]
        i1 = int(i)
        R = o.items()
        for r in R:
            for r1 in r[1]:

                if '.' in r1:
                    pos_of_dot = r1.index('.')

                    if pos_of_dot < (len(r1) - 2):

                        L = shift(r1[pos_of_dot + 2], i, i1, L, O)

                    elif pos_of_dot == len(r1) - 2:
                        if len(r1) == 4:

                            r2 = r1.split('.')
                            r3 = r2[0].split(' ')

                            if r3[0] == grammar[0][0] and r[0] == 'H':
                                L[i1]['$'] = 'accept'
                            else:
                                L = reduce(r[0], r1, i, L, grammar, follow)
                        else:
                            L = reduce(r[0], r1, i, L, grammar, follow)

    return L
Exemple #4
0
def generate_table(grammar1):
    grammar_list = grammar1[:]
    O = getclosures(grammar1)
    grammar = []
    k=0
    for prod in grammar_list:
        prod = prod.split("->")
        grammar.append(prod)
        s=grammar[k][0].replace(' ','')
        t=grammar[k][1].replace(' ','')
        grammar[k][0]=s
        grammar[k][1]=t
        k=k+1

    follow=find_follow(grammar1)

    max=0
    for o in O:
        S=o['to']
        integer = int(S[0])
        if integer > max:
            max=integer
    #Creating a dictionary containing all the elements of the grammar
    di={}
    di['$']=''
    t=[]
    for g in grammar:
        di[g[0]]=''
        list_=list(g[1])
        for l in list_:
            di[l]=''
    L=[]

    di['e']=''
    di['']=''
    del di['e']
    del di['']

    #Creating a list of dictionaries.
    for i in range(0,max+1):
        L.append(copy.deepcopy(di))
    #Checks whether to shift, reduce or accept
    for o in O:
        i=o['to'][0]
        i1=int(i)
        R=o.items()
        for r in R:
            for r1 in r[1]:
                # Checking if dot is present in string. Because '.' is not present in 'from','to','on' and 'state'
                if '.' in r1:
                    pos_of_dot=r1.index('.')
                    #Checking if dot is present in the middle of the string. If in middle goto shift
                    if pos_of_dot < (len(r1)-2):
                        
                        L = shift(r1[pos_of_dot+2],i,i1,L,O)
                    # If dot is present at the end of the string, reduce.
                    elif pos_of_dot==len(r1)-2 :
                        if len(r1)==4:
                            
                            r2=r1.split('.')
                            r3=r2[0].split(' ')

                            if r3[0]==grammar[0][0] and r[0]=='H':
                                L[i1]['$']='accept'
                            else:
                                L = reduce(r[0],r1,i,L,grammar,follow)
                        else:
                            L = reduce(r[0],r1,i,L,grammar,follow)
    
    return L
Exemple #5
0
def generate_table(grammar1):
    grammar_list = grammar1[:]
    O = getclosures(grammar1)
    grammar = []
    k = 0
    for prod in grammar_list:
        prod = prod.split("->")
        grammar.append(prod)
        s = grammar[k][0].replace(' ', '')
        t = grammar[k][1].replace(' ', '')
        grammar[k][0] = s
        grammar[k][1] = t
        k = k + 1

    follow = find_follow(grammar1)

    max = 0
    for o in O:
        S = o['to']
        integer = int(S[0])
        if integer > max:
            max = integer
    #Creating a dictionary containing all the elements of the grammar
    di = {}
    di['$'] = ''
    t = []
    for g in grammar:
        di[g[0]] = ''
        list_ = list(g[1])
        for l in list_:
            di[l] = ''
    L = []

    di['e'] = ''
    di[''] = ''
    del di['e']
    del di['']

    #Creating a list of dictionaries.
    for i in range(0, max + 1):
        L.append(copy.deepcopy(di))
    #Checks whether to shift, reduce or accept
    for o in O:
        i = o['to'][0]
        i1 = int(i)
        R = o.items()
        for r in R:
            for r1 in r[1]:
                # Checking if dot is present in string. Because '.' is not present in 'from','to','on' and 'state'
                if '.' in r1:
                    pos_of_dot = r1.index('.')
                    #Checking if dot is present in the middle of the string. If in middle goto shift
                    if pos_of_dot < (len(r1) - 2):

                        L = shift(r1[pos_of_dot + 2], i, i1, L, O)
                    # If dot is present at the end of the string, reduce.
                    elif pos_of_dot == len(r1) - 2:
                        if len(r1) == 4:

                            r2 = r1.split('.')
                            r3 = r2[0].split(' ')

                            if r3[0] == grammar[0][0] and r[0] == 'H':
                                L[i1]['$'] = 'accept'
                            else:
                                L = reduce(r[0], r1, i, L, grammar, follow)
                        else:
                            L = reduce(r[0], r1, i, L, grammar, follow)

    return L