Parses a PRINT statement, causing the value that is on top of the operand stack to be printed on the screen.
(self)
| 332 | + str(self.__line_number)) |
| 333 | |
| 334 | def __printstmt(self): |
| 335 | """Parses a PRINT statement, causing |
| 336 | the value that is on top of the |
| 337 | operand stack to be printed on |
| 338 | the screen. |
| 339 | |
| 340 | """ |
| 341 | self.__advance() # Advance past PRINT token |
| 342 | |
| 343 | fileIO = False |
| 344 | if self.__token.category == Token.HASH: |
| 345 | fileIO = True |
| 346 | |
| 347 | # Process the # keyword |
| 348 | self.__consume(Token.HASH) |
| 349 | |
| 350 | # Acquire the file number |
| 351 | self.__expr() |
| 352 | filenum = self.__operand_stack.pop() |
| 353 | |
| 354 | if self.__file_handles.get(filenum) == None: |
| 355 | raise RuntimeError("PRINT: file #"+str(filenum)+" not opened in line " + str(self.__line_number)) |
| 356 | |
| 357 | # Process the comma |
| 358 | if self.__tokenindex < len(self.__tokenlist) and self.__token.category != Token.COLON: |
| 359 | self.__consume(Token.COMMA) |
| 360 | |
| 361 | # Check there are items to print |
| 362 | last_token_cat = None |
| 363 | if not self.__tokenindex >= len(self.__tokenlist) and self.__token.category != Token.COLON: |
| 364 | last_token_cat = self.__token.category |
| 365 | prntTab = (self.__token.category == Token.TAB) |
| 366 | self.__logexpr() |
| 367 | |
| 368 | #if type(self.__operand_stack[-1]) == tuple and self.__operand_stack[-1][0] == "TAB": |
| 369 | if prntTab: |
| 370 | if self.__prnt_column >= len(self.__operand_stack[-1]): |
| 371 | if fileIO: |
| 372 | self.__file_handles[filenum].write("\n") |
| 373 | else: |
| 374 | print() |
| 375 | self.__prnt_column = 0 |
| 376 | |
| 377 | current_pr_column = len(self.__operand_stack[-1]) - self.__prnt_column |
| 378 | self.__prnt_column = len(self.__operand_stack.pop()) - 1 |
| 379 | if current_pr_column > 1: |
| 380 | if fileIO: |
| 381 | self.__file_handles[filenum].write(" "*(current_pr_column-1)) |
| 382 | else: |
| 383 | print(" "*(current_pr_column-1), end="") |
| 384 | else: |
| 385 | self.__prnt_column += len(str(self.__operand_stack[-1])) |
| 386 | if fileIO: |
| 387 | self.__file_handles[filenum].write('%s' %(self.__operand_stack.pop())) |
| 388 | else: |
| 389 | print(self.__operand_stack.pop(), end='') |
| 390 | |
| 391 | while self.__token.category == Token.COMMA or self.__token.category == Token.SEMICOLON: |