Added comments in the code to provide a little bit more insight into what's happening.

This commit is contained in:
2020-04-27 11:01:27 -05:00
parent 5a585cf6f8
commit 6ba3414367
3 changed files with 35 additions and 9 deletions
+6 -3
View File
@@ -1,4 +1,6 @@
class Token:
# Represents the single smallest unit that makes up an expression.
def __init__(self, value, type, is_negative_variable = False):
self.value = value
self.type = type
@@ -47,19 +49,20 @@ class TokenType:
@staticmethod
def get_operator_verb(token):
# Returns the verb that corresponds to the supplied Token object's value field, or
# throws an error if the Token object isn't a mathmatical operator.
if not token in TokenType.OPERATOR_VERBS:
raise ValueError("An operator verb could not be found.", "token")
return TokenType.OPERATOR_VERBS[token]
@staticmethod
def get_operator(character):
#
#Accepts an individual character and returns either the math operator TokenType or unknown.
#
# Accepts an individual character and returns either the mathmatical operator TokenType or unknown.
if not character in TokenType.OPERATORS:
return TokenType.unknown
return TokenType.OPERATORS[character]
@staticmethod
def get_token_type_name(tokenType):
# Returns the token's full name based on the TokenType value.
return TokenType.TOKEN_NAMES[tokenType]