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__/
res/output/
res/input/
__pycache__/*
res/output/*
res/input/*
.vscode/*
*.pyc

View File

@@ -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)

View File

@@ -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)
inst = get_scoped_instructions("res/input/input.java")
print(inst)