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

Method __assignmentstmt

PyBasic/basicparser.py:485–516  ·  view source on GitHub ↗

Parses an assignment statement, placing the corresponding variable and its value in the symbol table.

(self)

Source from the content-addressed store, hash-verified

483 return FlowSignal(ftype=FlowSignal.STOP)
484
485 def __assignmentstmt(self):
486 """Parses an assignment statement,
487 placing the corresponding
488 variable and its value in the symbol
489 table.
490
491 """
492 left = self.__token.lexeme # Save lexeme of
493 # the current token
494 self.__advance()
495
496 if self.__token.category == Token.LEFTPAREN:
497 # We are assiging to an array
498 self.__arrayassignmentstmt(left)
499
500 else:
501 # We are assigning to a simple variable
502 self.__consume(Token.ASSIGNOP)
503 self.__logexpr()
504
505 # Check that we are using the right variable name format
506 right = self.__operand_stack.pop()
507
508 if left.endswith('$') and not isinstance(right, str):
509 raise SyntaxError('Syntax error: Attempt to assign non string to string variable' +
510 ' in line ' + str(self.__line_number))
511
512 elif not left.endswith('$') and isinstance(right, str):
513 raise SyntaxError('Syntax error: Attempt to assign string to numeric variable' +
514 ' in line ' + str(self.__line_number))
515
516 self.__symbol_table[left] = right
517
518 def __dimstmt(self):
519 """Parses DIM statement and creates a symbol

Callers 2

__simplestmtMethod · 0.95
__letstmtMethod · 0.95

Calls 4

__advanceMethod · 0.95
__arrayassignmentstmtMethod · 0.95
__consumeMethod · 0.95
__logexprMethod · 0.95

Tested by

no test coverage detected