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

Method parse

PyBasic/basicparser.py:147–217  ·  view source on GitHub ↗

Must be initialised with the list of BTokens to be processed. These tokens represent a BASIC statement without its corresponding line number. :param tokenlist: The tokenized program statement :param line_number: The line number of the statement

(self, tokenlist, line_number, cstmt_number, infile, tmpfile, datastmts)

Source from the content-addressed store, hash-verified

145
146
147 def parse(self, tokenlist, line_number, cstmt_number, infile, tmpfile, datastmts):
148 """Must be initialised with the list of
149 BTokens to be processed. These tokens
150 represent a BASIC statement without
151 its corresponding line number.
152
153 :param tokenlist: The tokenized program statement
154 :param line_number: The line number of the statement
155 :param cstmt_number: Which statement in a multistatment line
156
157 :return: The FlowSignal to indicate to the program
158 how to branch if necessary, None otherwise
159
160 """
161
162 self.__tokenlist = tokenlist
163 self.__tokenindex = 0
164
165
166 # This block locates the index number of the first token in the statement
167 # referenced by che cstmt_number argument
168 indx = 0
169 colon_count = 0
170 if cstmt_number > 0:
171 for e in tokenlist:
172 if e.category == Token.COLON:
173 colon_count += 1
174 self.__tokenindex = indx + 1
175 indx += 1
176 if colon_count >= cstmt_number:
177 break
178
179 # Remember the line number to aid error reporting
180 self.__line_number = line_number
181
182 # Assign the first token
183 self.__token = self.__tokenlist[self.__tokenindex]
184
185 flow = self.__stmt(infile,tmpfile,datastmts)
186
187 # If the statement returns an EXECUTE flowsignal then it's a conditional
188 # and we need to parse the THEN or ELSE block depending on where the
189 # __ifstmt method left the current __tokenindex
190 if flow and (flow.ftype == FlowSignal.EXECUTE):
191
192 # Find the number of compound statements in the current
193 # conditional block (to an ELSE or end of line)
194 number_of_stmts = 1
195 for e in tokenlist[self.__tokenindex:]:
196 if e.category == Token.COLON:
197 number_of_stmts += 1
198 elif e.category == Token.ELSE:
199 break
200
201 recur_tokenindex = self.__tokenindex
202 self.__tokenindex = 0
203 for cstmtNo in range(0,number_of_stmts):
204 try:

Callers 1

__executeMethod · 0.80

Calls 1

__stmtMethod · 0.95

Tested by

no test coverage detected