Ejemplo n.º 1
0
    def organize_collection(self):
        tokens = []

        for file_item in self.vhdl_source_file_list:

            vhdl_object = VHD(file_item)

            with open(file_item, 'r') as file:
                content = file.read()

            # Lexer
            lex = Lexer(content)
            tokens = lex.tokenize()

            # Parser
            parser = Parser(tokens)
            # Get the vhdl objects dependencies
            dep_list = parser.get_dependency()
            # Get the type of vhdl object
            vhdl_type = parser.get_type()

            # vhdl object
            # Set the name of vhdl object
            vhdl_object.set_name(vhdl_type)
            # Set the type of vhdl object
            vhdl_object.set_type(vhdl_type)
            # Set the vhdl object dependencies
            vhdl_object.add_dependency(dep_list)

            # Add vhdl object to list
            self.vhdl_obj_list.append(vhdl_object)

            vhdl_object.get_generics(tokens)

        self._sort_compile_order(self.vhdl_obj_list)
Ejemplo n.º 2
0
 def start(self, event):
     p = Parser(
         self.elements["url_e"]["element"].get(),
         int(self.elements["depth_e"]["element"].get()),
         self.dir,
     ).find_all_links()
     p.save_images()
Ejemplo n.º 3
0
def main():
    lexer = Lexer().build()
    file = open('./input.txt')
    text_input = file.read()
    file.close()
    lexer.input(text_input)
    parser = Parser()
    parser.build().parse(text_input, lexer, False)
Ejemplo n.º 4
0
    def organize_collection(self) -> list :
        """
        With all files in collection do:
        1. Create a vhdl_object() object
        2. Tokenize file
        3. Parse file
        4. Read file dependencies
        5. Read type of file
        6. Set vhdl_object name, type and dependencies.
        7. Add vhdl_object to vhdl_object_list
        8. Detect vhdl_object generics

        -> Final, sort vhdl_objects by dependency.
        """

        for file_item in self.vhdl_source_file_list:
            # Get new VHDL object
            vhdl_object = VHD(file_item)

            # Read file content
            with open(file_item, 'r') as file:
                content = file.read()

            # Get tokens from Lexer
            lexer = Lexer(content)
            tokens = lexer.get_tokens()

            # Parser
            parser      = Parser(tokens)
            # Get the vhdl objects dependencies
            dep_list    = parser.get_dependency()

            # Get the type of vhdl object
            vhdl_type    = parser.get_type()

            # VHDL object
            # Set the name of vhdl object
            vhdl_object.set_name(vhdl_type)
            # Set the type of vhdl object
            vhdl_object.set_type(vhdl_type)
            # Set the vhdl object dependencies
            vhdl_object.add_dependency(dep_list)

            # Add vhdl object to list
            self.vhdl_obj_list.append(vhdl_object)

            #vhdl_object.get_generics(tokens)

        # Organize VHDL objects by internal dependeny
        return self._sort_compile_order(self.vhdl_obj_list)
Ejemplo n.º 5
0
def test_words_in():
    words_in = ['python', 'linux', 'flask']
    jobs = Parser('python')
    info = jobs.vacancies_pars(words_in)
    words_d = {'python': 58, 'linux': 16.8, 'flask': 4}
    check = True
    for i in info[1]:
        for j in i:
            words = i[j]
            for w in words:
                if int(words[w]) == 0 or w == 'all_vacancies':
                    continue
                else:
                    prev = words_d[w]
                    print(prev)
                    if prev - 1 < int(words[w]) / 5 < prev + 1:
                        pass
                    else:
                        check = False
    assert (check == True)
Ejemplo n.º 6
0
def main():
    name = str(input('Введите название вакансии: '))
    words_in = str(input('Введите ключевые слова через пробел: ')).split(' ')
    jobs = Parser(name)
    info = jobs.vacancies_pars(words_in)

    if info == 0:
        print(f'Ваканский по слову {name} не найдено')
    else:
        print(info[0])
        print(info[1])
        for i in info[0]:
            for j in i:
                print(f'На странице {int(j[0]) + 1} найдено {i[j]} ключевых слов')
        for i in info[1]:
            for j in i:
                words = i[j]
                for w in words:
                    if int(words[w]) == 0 or w == 'all_vacancies':
                        continue
                    else:
                        all_vac = int(words['all_vacancies'])
                        d = round((int(words[w])/all_vac), 3)
                        print(f'В среднем на странице №{int(j[0]) + 1} слово {w} встречается {d} раз')
Ejemplo n.º 7
0
from transfer_to_pn import PN
from stack_machine import stack_machine
from triad_processing import Triad
from thread_manager import Thread_manager
from my_thread import Thread


f = open('test2.txt')
inp = f.read()
f.close()

print('\nlexer:')
l = Lexer()
tokens = l.lex(inp)

p = Parser(tokens)
pars = p.lang()
print('\nparser:', pars)

if pars:
    pn = PN(tokens)
    transfer, fun = pn.transfer_PN()

    tr = Triad(transfer, fun)
    t, val = tr.triad_op()

    for i in range(len(fun)):
        print("\nFunctions triads processing:")
        triad = Triad(fun[i][-1], fun)
        fun[i][-1] = triad.triad_op(False)
Ejemplo n.º 8
0
 def printTable(self):
     self.parser = Parser(self.grammar)
     self.parser.generateFirstSet()
     self.parser.follow()
     self.parser.Table()
     print(self.parser.table)
Ejemplo n.º 9
0
 def printFollowSet(self):
     self.parser = Parser(self.grammar)
     self.parser.generateFirstSet()
     self.parser.follow()
     print(self.parser.getFollow())
Ejemplo n.º 10
0
class UI:
    def __init__(self):
        self.grammar = g.Grammar()
        self.parser = None

    def readFile(self):

        self.grammar.readFile()

    def printGrammar(self):
        if self.grammar.getOK():
            print(self.grammar)
        else:
            print("read file first")

    def printNonTerminals(self):
        if self.grammar.getOK():
            print(self.grammar.printNonTerminals())
        else:
            print("read file first")

    def printTerminals(self):
        if self.grammar.getOK():
            print(self.grammar.printTerminals())
        else:
            print("read file first")

    def printProduction(self):
        noTerminal = input("type nonTerminal here: ")
        if self.grammar.getOK():
            print(str(self.grammar.getProductionForNonTerminal(noTerminal)))
        else:
            print("read file first")

    def printFirstSet(self):
        self.parser = Parser(self.grammar)
        self.parser.generateFirstSet()
        print(self.parser.getFirst())

    def printFollowSet(self):
        self.parser = Parser(self.grammar)
        self.parser.generateFirstSet()
        self.parser.follow()
        print(self.parser.getFollow())

    def printTable(self):
        self.parser = Parser(self.grammar)
        self.parser.generateFirstSet()
        self.parser.follow()
        self.parser.Table()
        print(self.parser.table)

    def parseSequence(self):
        sequence = "a+a"
        #out1 = open('D:\\anul3\\semestrul1\\FLCD\\Lab5\\out1.txt', 'w') # pugna
        x = self.parser.parse(sequence)
        #print(self.grammar.getProdutionForIndex(5))
        #out1.write(str(x))

    def menu(self):
        print("1 - read input")
        print("2 - print Productions")
        print("3 - print NonTerminals")
        print("4 - print Terminals")
        print("5 - print Production for terminal")
        print("6 - print FirstSet")
        print("7 - print FollowSet")
        print("8 - print Table")
        print("9 - parse Sequence")

    def run(self):
        menuChoices = {
            '1': self.readFile,
            '2': self.printGrammar,
            '3': self.printNonTerminals,
            '4': self.printTerminals,
            '5': self.printProduction,
            '6': self.printFirstSet,
            '7': self.printFollowSet,
            '8': self.printTable,
            '9': self.parseSequence
        }
        while True:
            self.menu()
            choice = input("-")
            if choice in menuChoices.keys():
                menuChoices[choice]()
            else:
                break
Ejemplo n.º 11
0
from pars import Parser

if __name__ == '__main__':

    parser = Parser()
    parser.login()
    parser.parse_links()
Ejemplo n.º 12
0
def test_soup_desc(check_connect):
    pars = Parser('python')
    link = "https://rabota.by/vacancy/43048095?query=python"
    results = pars.get_info_vacancies(link)
    assert (results != [])
Ejemplo n.º 13
0
def test_soup(check_connect):
    jobs = Parser('python')
    info = jobs.vacancies_pars('')
    assert (info != False)
Ejemplo n.º 14
0
def test_word():
    jobs = Parser('дробовик')
    info = jobs.vacancies_pars('')
    assert (info == 0)