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

Method __readstmt

PyBasic/basicparser.py:844–894  ·  view source on GitHub ↗

Parses a READ statement.

(self,infile,tmpfile,datastmts)

Source from the content-addressed store, hash-verified

842 """Parses a DATA statement"""
843
844 def __readstmt(self,infile,tmpfile,datastmts):
845 """Parses a READ statement."""
846
847 self.__advance() # Advance past READ token
848
849 # Acquire the comma separated input variables
850 variables = []
851 if not self.__tokenindex >= len(self.__tokenlist):
852 variables.append(self.__token.lexeme)
853 self.__advance() # Advance past variable
854
855 while self.__token.category == Token.COMMA:
856 self.__advance() # Advance past comma
857 variables.append(self.__token.lexeme)
858 self.__advance() # Advance past variable
859
860
861 # Check that we have enough data values to fill the
862 # variables
863 #if len(variables) > len(self.__data_values):
864 #raise RuntimeError('Insufficient constants supplied to READ ' +
865 #'in line ' + str(self.__line_number))
866
867
868 # Gather input from the DATA statement into the variables
869 for variable in variables:
870
871 if len(self.__data_values) < 1:
872 self.__data_values = datastmts.readData(self.__line_number,infile,tmpfile)
873
874 left = variable
875 #right = readlist.pop(0)
876 right = self.__data_values.pop(0)
877
878 if left.endswith('$'):
879 # Python inserts quotes around input data
880 if isinstance(right, int):
881 raise ValueError('Non-string input provided to a string variable ' +
882 'in line ' + str(self.__line_number))
883
884 else:
885 self.__symbol_table[left] = right
886
887 elif not left.endswith('$'):
888 try:
889 #self.__symbol_table[left] = int(right)
890 self.__symbol_table[left] = right
891
892 except ValueError:
893 raise ValueError('String input provided to a numeric variable ' +
894 'in line ' + str(self.__line_number))
895
896 def __soundstmt(self):
897 """Parses a SOUND statement"""

Callers 1

__simplestmtMethod · 0.95

Calls 2

__advanceMethod · 0.95
readDataMethod · 0.80

Tested by

no test coverage detected