예제 #1
0
def parse_file(file_path):
    inp = FileStream(file_path)
    lexer = VhdlLexer(inp)
    stream = CommonTokenStream(lexer)
    parser = VhdlParser(stream)
    listener = VhdlListenerForGraph()
    parser._interp.predictionMode = PredictionMode.LL
    tree = parser.design_file()
    walker = ParseTreeWalker()
    walker.walk(listener, tree)
    return listener
예제 #2
0
def main(argv):
    input = FileStream(argv[1])
    lexer = VhdlLexer(input)
    stream = CommonTokenStream(lexer)
    parser = VhdlParser(stream)
    listener = VhdlListenerForGraph()
    parser_option = argv[2]

    if (parser_option == "SLL"):
        parser._interp.predictionMode = PredictionMode.SLL
        try:
            print("Parsing with SLL...")
            tree = parser.design_file()
        except:
            print("SLL didn't work, parsing with LL...")
            stream.reset()
            parser.reset()
            parser._interp.predictionMode = PredictionMode.LL
            tree = parser.design_file()
        finally:
            print("Done parsing, walking parse tree...")
            walker = ParseTreeWalker()
            walker.walk(listener, tree)
    elif (parser_option == "LL"):
        print("Parsing with LL...")
        parser._interp.predictionMode = PredictionMode.LL
        tree = parser.design_file()
        print("Done parsing, walking parse tree...")
        walker = ParseTreeWalker()
        walker.walk(listener, tree)

    print(len(listener.components_list))