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

Method __openstmt

PyBasic/basicparser.py:615–703  ·  view source on GitHub ↗

Parses an open statement, opens the indicated file and places the file handle into handle table

(self)

Source from the content-addressed store, hash-verified

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

Callers 1

__simplestmtMethod · 0.95

Calls 6

__advanceMethod · 0.95
__logexprMethod · 0.95
__consumeMethod · 0.95
__exprMethod · 0.95
FlowSignalClass · 0.90
getMethod · 0.80

Tested by

no test coverage detected