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

Method __ifstmt

PyBasic/basicparser.py:1140–1189  ·  view source on GitHub ↗

Parses if-then-else statements :return: The FlowSignal to indicate to the program how to branch if necessary, None otherwise

(self)

Source from the content-addressed store, hash-verified

1138 return self.__ongosubstmt()
1139
1140 def __ifstmt(self):
1141 """Parses if-then-else
1142 statements
1143
1144 :return: The FlowSignal to indicate to the program
1145 how to branch if necessary, None otherwise
1146
1147 """
1148
1149 self.__advance() # Advance past IF token
1150 self.__logexpr()
1151
1152 # Save result of expression
1153 saveval = self.__operand_stack.pop()
1154
1155 # Process the THEN part and save the jump value
1156 self.__consume(Token.THEN)
1157
1158 if self.__token.category != Token.UNSIGNEDINT:
1159 if saveval:
1160 return FlowSignal(ftype=FlowSignal.EXECUTE)
1161 else:
1162 self.__expr()
1163
1164 # Jump if the expression evaluated to True
1165 if saveval:
1166 # Set up and return the flow signal
1167 return FlowSignal(ftarget=self.__operand_stack.pop())
1168 else:
1169 self.__operand_stack.pop()
1170
1171 # advance to ELSE
1172 while self.__tokenindex < len(self.__tokenlist) and self.__token.category != Token.ELSE:
1173 self.__advance()
1174
1175 # See if there is an ELSE part
1176 if self.__token.category == Token.ELSE:
1177 self.__advance()
1178
1179 if self.__token.category != Token.UNSIGNEDINT:
1180 return FlowSignal(ftype=FlowSignal.EXECUTE)
1181 else:
1182 self.__expr()
1183
1184 # Set up and return the flow signal
1185 return FlowSignal(ftarget=self.__operand_stack.pop())
1186
1187 else:
1188 # No ELSE action
1189 return None
1190
1191 def __forstmt(self):
1192 """Parses for loops

Callers 1

__compoundstmtMethod · 0.95

Calls 5

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

Tested by

no test coverage detected