-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
29 lines (25 loc) · 824 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from lark import Lark, logger
import logging
from lark import Transformer
def parseVerilogTree(tree, level = 0):
print(tree.data)
for c in tree.children:
for i in range(0, level):
if i < level - 1:
print('#', end='')
else:
print('#', end=' ')
if hasattr(c, 'children'):
parseVerilogTree(c, level + 1)
else:
print(c)
verilog_grammar = '/home/zdebel/kodasy/AwesomeHDLSimByzD/grammars/verilog2001.lark'
verilog_parser = Lark.open(verilog_grammar, start="source_text")
try:
tree = verilog_parser.parse(open("/home/zdebel/kodasy/AwesomeHDLSimByzD/test_data/verilog/fifo.v").read())
print(tree.pretty())
print("#### !!!! ####")
parseVerilogTree(tree)
except Exception as e:
print(e)
exit()