Parses an open statement, opens the indicated file and places the file handle into handle table
(self)
| 613 | str(self.__line_number)) |
| 614 | |
| 615 | def __openstmt(self): |
| 616 | """Parses an open statement, opens the indicated file and |
| 617 | places the file handle into handle table |
| 618 | |
| 619 | """ |
| 620 | self.__advance() # Advance past OPEN token |
| 621 | |
| 622 | # Acquire the filename |
| 623 | self.__logexpr() |
| 624 | filename = self.__operand_stack.pop() |
| 625 | |
| 626 | # Process the FOR keyword |
| 627 | self.__consume(Token.FOR) |
| 628 | |
| 629 | if self.__token.lexeme == "INPUT": |
| 630 | accessMode = "r" |
| 631 | elif self.__token.lexeme == "APPEND": |
| 632 | accessMode = "r+" |
| 633 | elif self.__token.lexeme == "OUTPUT": |
| 634 | accessMode = "w+" |
| 635 | else: |
| 636 | raise SyntaxError('Invalid Open access mode in line ' + str(self.__line_number)) |
| 637 | |
| 638 | self.__advance() # Advance past acess type |
| 639 | |
| 640 | if self.__token.lexeme != "AS": |
| 641 | raise SyntaxError('Expecting AS in line ' + str(self.__line_number)) |
| 642 | |
| 643 | self.__advance() # Advance past AS keyword |
| 644 | |
| 645 | #if self.__token.category != Token.HASH: |
| 646 | #raise SyntaxError('Expecting (#filenum) in line ' + str(self.__line_number)) |
| 647 | |
| 648 | #self.__advance() # Advance past Hashmark (#) |
| 649 | |
| 650 | # Process the # keyword |
| 651 | self.__consume(Token.HASH) |
| 652 | |
| 653 | # Acquire the file number |
| 654 | self.__expr() |
| 655 | filenum = self.__operand_stack.pop() |
| 656 | |
| 657 | branchOnError = False |
| 658 | if self.__token.category == Token.ELSE: |
| 659 | branchOnError = True |
| 660 | self.__advance() # Advance past ELSE |
| 661 | |
| 662 | if self.__token.category == Token.GOTO: |
| 663 | self.__advance() # Advance past optional GOTO |
| 664 | |
| 665 | self.__expr() |
| 666 | |
| 667 | if self.__file_handles.get(filenum) != None: |
| 668 | if branchOnError: |
| 669 | return FlowSignal(ftarget=self.__operand_stack.pop()) |
| 670 | else: |
| 671 | raise RuntimeError("File #",filenum," already opened in line " + str(self.__line_number)) |
| 672 |
no test coverage detected