From 711ceb2567eb882e1f809c79c6036d7498f3be3c Mon Sep 17 00:00:00 2001 From: weckyy702 Date: Mon, 21 Dec 2020 22:07:20 +0100 Subject: [PATCH] updated .gitignore --- .gitignore | 8 +++-- NassiShneidermann.py | 6 +++- __pycache__/Iinstruction.cpython-39.pyc | Bin 4926 -> 4921 bytes __pycache__/code_to_image.cpython-39.pyc | Bin 3376 -> 3301 bytes interpet_source.py | 42 +++++++++++++++++------ 5 files changed, 41 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 15d44ee..b526ca6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ -__pycache__/ -res/output/ -res/input/ \ No newline at end of file +__pycache__/* +res/output/* +res/input/* +.vscode/* +*.pyc \ No newline at end of file diff --git a/NassiShneidermann.py b/NassiShneidermann.py index b7fc90b..685eb86 100644 --- a/NassiShneidermann.py +++ b/NassiShneidermann.py @@ -1,6 +1,7 @@ from os import cpu_count from code_to_image import NSD_save from Iinstruction import Iinstruction +import interpet_source as itp import logging class NassiShneidermanDiagram: @@ -29,6 +30,9 @@ class NassiShneidermanDiagram: x, y = instruction.to_image(x, y, x_sz, 200) cti.NSD_save(filename) + def load_from_file(self, filepath:str): + source_code = itp.load_src(filepath) + instructions = itp.get_scoped_instructions(filepath) @@ -39,6 +43,6 @@ if __name__ == "__main__": NSD = NassiShneidermanDiagram(True) - #NSD.load_from_file("res/input/input.java") + NSD.load_from_file("res/input/input.java") NSD.convert_to_image("Nina", 500) diff --git a/__pycache__/Iinstruction.cpython-39.pyc b/__pycache__/Iinstruction.cpython-39.pyc index c1ec0497f33da854ba173426515821d8a99ab940..9cf077e26b9c33f8807a102a083edbb3bb4d19d6 100644 GIT binary patch delta 417 zcmXYrKTpD75XO7ZzLb_qOQHTl0cnaA(E5i-7mbT?a3FDDYXU|R7fW<>aWK*G1{0l} z9Gnb;aWT623H$&KuKE$YE4;})d2;u>_q#Xm)zd=5&?I^nx6fJ%3U=3ikU{FHU2zE@ zb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N!&#ZxQgV|vIH8Cd!|E$&!?3wy%AOb+Z6gi|CbO}WSwNRf1DN)#2Y$O}t& z6B|ehsG`y&WnZte#zM&Ul`KQ(ioT3Gsy~c>gL#S62kc?Vk-n*CZe!Gmo}wlLJUhKe zCH;E-eIAuMyO5);yrKiA0hMXf8N=>%BmVkugz=@`J1dUrasg*< zp!V$)V_rYDvL)mSDmM`}5YX2+UUVP8=2W=Pp>hkEY8p5`I=Rf`j#;S_+ diff --git a/interpet_source.py b/interpet_source.py index 03ddb4f..a5939dd 100644 --- a/interpet_source.py +++ b/interpet_source.py @@ -1,6 +1,7 @@ +from Iinstruction import * import logging import re -from typing import Iterator +from typing import Any, Iterator class Scope(): @@ -27,7 +28,7 @@ def load_src(filepath: str) -> list[str]: return lines -def read_scopes(src: list[str]): +def get_scopes(src: list[str]): global_scope = Scope(None) current_scope = global_scope @@ -47,18 +48,37 @@ def read_scopes(src: list[str]): return global_scope -def print_scope(scope: Scope): - print('[', end='') +def get_instructions(scope: Scope) -> list[Any]: + instructions = [] + for item in scope.contents: if isinstance(item, Scope): - print_scope(item) + instructions.extend(get_instructions(item)) else: - print(item, end=", ") - print(']') + instructions.append(item) + + return instructions + + + +def get_scoped_instructions(filepath:str) -> list[Any]: + source_code = load_src(filepath) + global_scope = get_scopes(source_code) + + instructions = get_instructions(global_scope) + return instructions if __name__ == "__main__": + + def print_scope(scope: Scope): + print('[', end='') + for item in scope.contents: + if isinstance(item, Scope): + print_scope(item) + else: + print(item, end=", ") + print(']') + logging.basicConfig(level=logging.DEBUG) - lines = load_src("res/input/input.java") - scope = read_scopes(lines) - - print_scope(scope) \ No newline at end of file + inst = get_scoped_instructions("res/input/input.java") + print(inst) \ No newline at end of file