updated .gitignore
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
__pycache__/
|
||||
res/output/
|
||||
res/input/
|
||||
__pycache__/*
|
||||
res/output/*
|
||||
res/input/*
|
||||
.vscode/*
|
||||
*.pyc
|
||||
@@ -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)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -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,6 +48,28 @@ def read_scopes(src: list[str]):
|
||||
|
||||
return global_scope
|
||||
|
||||
def get_instructions(scope: Scope) -> list[Any]:
|
||||
instructions = []
|
||||
|
||||
for item in scope.contents:
|
||||
if isinstance(item, Scope):
|
||||
instructions.extend(get_instructions(item))
|
||||
else:
|
||||
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:
|
||||
@@ -56,9 +79,6 @@ def print_scope(scope: Scope):
|
||||
print(item, end=", ")
|
||||
print(']')
|
||||
|
||||
if __name__ == "__main__":
|
||||
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)
|
||||
Reference in New Issue
Block a user