(passedIn="")
| 44 | gc.threshold(gc.mem_free() // 4 + gc.mem_alloc()) |
| 45 | |
| 46 | def main(passedIn=""): |
| 47 | |
| 48 | banner = ( |
| 49 | """ |
| 50 | PPPP Y Y BBBB AAA SSSS I CCC |
| 51 | P P Y Y B B A A S I C |
| 52 | P P Y Y B B A A S I C |
| 53 | PPPP Y BBBB AAAAA SSSS I C |
| 54 | u u P Y B B A A S I C |
| 55 | u u P Y B B A A S I C |
| 56 | uuuu P Y BBBB A A SSSS I CCC |
| 57 | microPyBasic |
| 58 | """) |
| 59 | |
| 60 | print(banner) |
| 61 | |
| 62 | lexer = Lexer() |
| 63 | program = Program() |
| 64 | |
| 65 | fOpened = False |
| 66 | #initialize and open temporary file |
| 67 | tmpfile = open('_pybTmp.tmp','w+') |
| 68 | infile = tmpfile |
| 69 | |
| 70 | if passedIn != "": |
| 71 | infile = program.load(passedIn,tmpfile) |
| 72 | program.execute(infile,tmpfile) |
| 73 | |
| 74 | # Continuously accept user input and act on it until |
| 75 | # the user enters 'EXIT' |
| 76 | while True: |
| 77 | |
| 78 | # kfw stmt = input_keyboard(': ') |
| 79 | stmt = input(': ') |
| 80 | |
| 81 | try: |
| 82 | #if True: |
| 83 | tokenlist = lexer.tokenize(stmt) |
| 84 | |
| 85 | # Execute commands directly, otherwise |
| 86 | # add program statements to the stored |
| 87 | # BASIC program |
| 88 | |
| 89 | if len(tokenlist) > 0: |
| 90 | |
| 91 | # remove blank tokens |
| 92 | i = 0 |
| 93 | iend = len(tokenlist) |
| 94 | for _ in range(iend): |
| 95 | if i>0 and tokenlist[i].lexeme.strip() == "" and tokenlist[i].category != Token.STRING: |
| 96 | tokenlist.pop(i) |
| 97 | else: |
| 98 | i+=1 |
| 99 | |
| 100 | # Exit the interpreter |
| 101 | if tokenlist[0].category == Token.EXIT: |
| 102 | if fOpened: |
| 103 | infile.close() |
nothing calls this directly
no test coverage detected