MCPcopy Create free account
hub / github.com/geekcomputers/Python / parser

Function parser

Assembler/assembler.py:759–1235  ·  view source on GitHub ↗

parser: parses the tokens of the list 'tokens'

()

Source from the content-addressed store, hash-verified

757
758
759def parser():
760 """
761 parser: parses the tokens of the list 'tokens'
762 """
763
764 global tokens
765 global eax, ebx, ecx, edx
766
767 assert len(tokens) > 0, "no tokens"
768
769 pointer = 0 # pointer for tokens
770 token = Token("", "")
771 tmpToken = Token("", "")
772
773 while pointer < len(tokens):
774 token = tokens[pointer]
775
776 if token.token == "mov": # mov commando
777 # it must follow a register
778 if pointer + 1 < len(tokens):
779 pointer += 1
780 token = tokens[pointer]
781 else:
782 print("Error: Not found argument!")
783 return
784
785 # TODO use token.t for this stuff
786 if token.t == "register":
787 tmpToken = token
788
789 # it must follow a value / string / register / variable
790 if pointer + 1 < len(tokens):
791 pointer += 1
792 token = tokens[pointer]
793 else:
794 print("Error: Not found argument!")
795 return
796
797 # converts the token into float, if token contains only digits.
798 # TODO response of float
799 if token.t == "identifier": # for variables
800 # check of exists of variable
801 if token.token in variables:
802 token.token = variables[token.token]
803 else:
804 print(f"Error: Undefined variable {token.token}")
805 return
806
807 elif token.t == "string":
808 token.token = str(token.token)
809
810 elif isinstance(token.token, float):
811 pass
812 elif token.token.isdigit():
813 token.token = float(token.token)
814 elif token.token[0] == "-" and token.token[1:].isdigit():
815 token.token = float(token.token[1:])
816 token.token *= -1

Callers 1

mainFunction · 0.85

Calls 4

TokenClass · 0.85
setZeroFlagFunction · 0.85
appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected