MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / Program

Class Program

PyBasic/program.py:38–495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36collect()
37
38class Program:
39
40 def __init__(self):
41 # Dictionary to represent program
42 # statements, keyed by line number
43 self.__program = {}
44
45 # Program counter
46 self.__next_stmt = 0
47
48 # Initialise return stack for subroutine returns
49 self.__return_stack = []
50
51 # return dictionary for loop returns
52 self.__return_loop = {}
53
54 # Setup DATA object
55 self.__data = BASICData()
56
57 if uname()[0].upper() == 'LINUX' or \
58 implementation.name.upper() in ['MICROPYTHON','CIRCUITPYTHON']:
59
60 self.__imp = 'X'
61 else:
62 self.__imp = 'W'
63
64 def list(self, strt_line, end_line, infile, tmpfile):
65 """Lists the program"""
66 line_numbers = self.line_numbers()
67
68 for line_number in line_numbers:
69 if (int(line_number) >= strt_line and int(line_number) <= end_line) or strt_line == -1:
70 print(line_number, end=' ')
71
72 statement = self.getprogram(line_number,infile,tmpfile)
73 for token in statement:
74 # Add in quotes for strings
75 if token.category == Token.STRING:
76 print('"' + token.lexeme + '"', end=' ')
77
78 else:
79 print(token.lexeme, end=' ')
80
81 print()
82
83 def save(self, file, infile, tmpfile):
84 """Save the program
85
86 :param file: The name and path of the save file
87
88 """
89 retCode = False
90
91 ans = "Y"
92 if file in listdir():
93 ans = input("Overwrite "+file+" (y/n): ").upper()
94
95 if ans == "Y":

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected