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

Method __ongosubstmt

PyBasic/basicparser.py:1305–1344  ·  view source on GitHub ↗

Process the ON-GOSUB/GOTO statement :return: A FlowSignal indicating the subroutine line number if the condition is true, None otherwise

(self)

Source from the content-addressed store, hash-verified

1303 return FlowSignal(ftype=FlowSignal.LOOP_REPEAT,floop_var=loop_variable)
1304
1305 def __ongosubstmt(self):
1306 """Process the ON-GOSUB/GOTO statement
1307
1308 :return: A FlowSignal indicating the subroutine line number
1309 if the condition is true, None otherwise
1310
1311 """
1312
1313 self.__advance() # Advance past ON token
1314
1315 self.__expr()
1316
1317 # Save result of expression
1318 saveval = self.__operand_stack.pop()
1319
1320 if self.__token.category == Token.GOTO:
1321 self.__consume(Token.GOTO)
1322 branchtype = 1
1323 else:
1324 self.__consume(Token.GOSUB)
1325 branchtype = 2
1326
1327 branch_values = []
1328 # Acquire the comma separated values
1329 if not self.__tokenindex >= len(self.__tokenlist):
1330 self.__expr()
1331 branch_values.append(self.__operand_stack.pop())
1332
1333 while self.__token.category == Token.COMMA:
1334 self.__advance() # Advance past comma
1335 self.__expr()
1336 branch_values.append(self.__operand_stack.pop())
1337
1338 if saveval < 1 or saveval > len(branch_values) or len(branch_values) == 0:
1339 return None
1340 elif branchtype == 1:
1341 return FlowSignal(ftarget=branch_values[saveval-1])
1342 else:
1343 return FlowSignal(ftarget=branch_values[saveval-1],
1344 ftype=FlowSignal.GOSUB)
1345
1346
1347 def __relexpr(self):

Callers 1

__compoundstmtMethod · 0.95

Calls 4

__advanceMethod · 0.95
__exprMethod · 0.95
__consumeMethod · 0.95
FlowSignalClass · 0.90

Tested by

no test coverage detected