1 Star 0 Fork 0

hoNoSayaka/hack_compiler

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
reader.py 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
hoNoSayaka 提交于 2024-07-29 13:22 +08:00 . first commit
class Reader:
def __init__(self): ...
def process(self, filename):
d = {}
line_num = 1
label_line = ""
with open(filename, "r") as f:
for line in f.readlines():
if line.startswith('//') or line.startswith('\n'): continue
index = line.find("//")
if index != -1:
add_str = line[:index].strip()
if add_str.startswith("("):
label_line = add_str
continue
if len(add_str):
d[line_num] = label_line + add_str
label_line = ""
line_num += 1
else:
if line.strip().startswith("("):
label_line = line.strip()
continue
d[line_num] = label_line + line.strip()
label_line = ""
line_num += 1
return d
if __name__ == "__main__":
print(Reader().process("test.hasm")[0])
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/honosayaka/hack_compiler.git
git@gitee.com:honosayaka/hack_compiler.git
honosayaka
hack_compiler
hack_compiler
master

搜索帮助