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

Method __inputstmt

PyBasic/basicparser.py:751–829  ·  view source on GitHub ↗

Parses an input statement, extracts the input from the user and places the values into the symbol table

(self)

Source from the content-addressed store, hash-verified

749 self.__file_handles[filenum].seek(self.__operand_stack.pop())
750
751 def __inputstmt(self):
752 """Parses an input statement, extracts the input
753 from the user and places the values into the
754 symbol table
755
756 """
757 self.__advance() # Advance past INPUT token
758
759 fileIO = False
760 if self.__token.category == Token.HASH:
761 fileIO = True
762
763 # Process the # keyword
764 self.__consume(Token.HASH)
765
766 # Acquire the file number
767 self.__expr()
768 filenum = self.__operand_stack.pop()
769
770 if self.__file_handles.get(filenum) == None:
771 raise RuntimeError("INPUT: file #"+str(filenum)+" not opened in line " + str(self.__line_number))
772
773 # Process the comma
774 self.__consume(Token.COMMA)
775
776 prompt = '? '
777 if self.__token.category == Token.STRING:
778 if fileIO:
779 raise SyntaxError('Input prompt specified for file I/O ' +
780 'in line ' + str(self.__line_number))
781
782 # Acquire the input prompt
783 self.__logexpr()
784 prompt = self.__operand_stack.pop()
785 self.__consume(Token.COMMA)
786
787 # Acquire the comma separated input variables
788 variables = []
789 if not self.__tokenindex >= len(self.__tokenlist):
790 if self.__token.category != Token.NAME:
791 raise ValueError('Expecting NAME in INPUT statement ' +
792 'in line ' + str(self.__line_number))
793 variables.append(self.__token.lexeme)
794 self.__advance() # Advance past variable
795
796 while self.__token.category == Token.COMMA:
797 self.__advance() # Advance past comma
798 variables.append(self.__token.lexeme)
799 self.__advance() # Advance past variable
800
801 # Gather input into the variables
802 if fileIO:
803 #inputvals = self.__file_handles[filenum].readline()[:(-2 if implementation.name.upper() ==
804 #'MICROPYTHON' else -1)].split(',', (len(variables)-1))
805 inputvals = ((self.__file_handles[filenum].readline().replace("\n","")).replace("\r","")).split(',', (len(variables)-1))
806 else:
807 # kfw inputvals = self.input_keyboard(prompt).split(',', (len(variables)-1))
808 inputvals = input(prompt).split(',', (len(variables)-1))

Callers 1

__simplestmtMethod · 0.95

Calls 6

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

Tested by

no test coverage detected