updated .gitignore

This commit is contained in:
weckyy702
2020-12-21 22:07:20 +01:00
parent 862c6ef904
commit 711ceb2567
5 changed files with 41 additions and 15 deletions

8
.gitignore vendored
View File

@@ -1,3 +1,5 @@
__pycache__/ __pycache__/*
res/output/ res/output/*
res/input/ res/input/*
.vscode/*
*.pyc

View File

@@ -1,6 +1,7 @@
from os import cpu_count from os import cpu_count
from code_to_image import NSD_save from code_to_image import NSD_save
from Iinstruction import Iinstruction from Iinstruction import Iinstruction
import interpet_source as itp
import logging import logging
class NassiShneidermanDiagram: class NassiShneidermanDiagram:
@@ -29,6 +30,9 @@ class NassiShneidermanDiagram:
x, y = instruction.to_image(x, y, x_sz, 200) x, y = instruction.to_image(x, y, x_sz, 200)
cti.NSD_save(filename) 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 = NassiShneidermanDiagram(True)
#NSD.load_from_file("res/input/input.java") NSD.load_from_file("res/input/input.java")
NSD.convert_to_image("Nina", 500) NSD.convert_to_image("Nina", 500)

View File

@@ -1,6 +1,7 @@
from Iinstruction import *
import logging import logging
import re import re
from typing import Iterator from typing import Any, Iterator
class Scope(): class Scope():
@@ -27,7 +28,7 @@ def load_src(filepath: str) -> list[str]:
return lines return lines
def read_scopes(src: list[str]): def get_scopes(src: list[str]):
global_scope = Scope(None) global_scope = Scope(None)
current_scope = global_scope current_scope = global_scope
@@ -47,18 +48,37 @@ def read_scopes(src: list[str]):
return global_scope return global_scope
def print_scope(scope: Scope): def get_instructions(scope: Scope) -> list[Any]:
print('[', end='') instructions = []
for item in scope.contents: for item in scope.contents:
if isinstance(item, Scope): if isinstance(item, Scope):
print_scope(item) instructions.extend(get_instructions(item))
else: else:
print(item, end=", ") instructions.append(item)
print(']')
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__": 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) logging.basicConfig(level=logging.DEBUG)
lines = load_src("res/input/input.java") inst = get_scoped_instructions("res/input/input.java")
scope = read_scopes(lines) print(inst)
print_scope(scope)