Пример #1
0
    def getScientificNotationToken(self, sourceCode):
        try:
            if self.getFloatNumberToken(sourceCode) != None:
                floatTK = self.getFloatNumberToken(sourceCode)[0]
                index = len(floatTK.lexeme)
                if sourceCode[index] == 'e' or sourceCode[index] == 'E':
                    index = index + 1
                    if sourceCode[index] == "+" or sourceCode[index] == "-":
                        index = index + 1
                
                    if self.getFloatNumberToken(sourceCode[index:]) != None:
                        floatTK = self.getFloatNumberToken(sourceCode[index:])[0]
                        totalIndex = index + len(floatTK.lexeme)
                        tokenval = TokenVal.SCIENTIFIC_NOTATION.value
                        tokentype = TokenType.SCIENTIFIC_NOTATION.value
                        
                        lexeme = sourceCode[0:totalIndex]
                        tk = token(tokentype, tokenval, lexeme)
                        slicedSourceCode = sourceCode[totalIndex:]
                        return tk, slicedSourceCode
                    elif self.getIntegerNumberToken(sourceCode[index:]) != None:
                        intTK = self.getIntegerNumberToken(sourceCode[index:])[0]
                        totalIndex = index + len(intTK.lexeme)
                        tokenval = TokenVal.SCIENTIFIC_NOTATION.value
                        tokentype = TokenType.SCIENTIFIC_NOTATION.value
                        lexeme = sourceCode[0:totalIndex]
                        tk = token(tokentype, tokenval, lexeme)
                        slicedSourceCode = sourceCode[totalIndex:]
                        return tk, slicedSourceCode

            elif self.getIntegerNumberToken(sourceCode) != None:
                intTK = self.getIntegerNumberToken(sourceCode)[0]
                index = len(intTK.lexeme)
                if sourceCode[index] == 'e' or sourceCode[index] == 'E':
                    index = index + 1
                    if sourceCode[index] == "+" or sourceCode[index] == "-":
                        index = index + 1
                
                    if self.getFloatNumberToken(sourceCode[index:]) != None:
                        floatTK = self.getFloatNumberToken(sourceCode[index:])[0]
                        totalIndex = index + len(floatTK.lexeme)
                        tokenval = TokenVal.SCIENTIFIC_NOTATION.value
                        tokentype = TokenType.SCIENTIFIC_NOTATION.value
                        lexeme = sourceCode[0:totalIndex]
                        tk = token(tokentype, tokenval, lexeme)
                        slicedSourceCode = sourceCode[totalIndex:]
                        return tk, slicedSourceCode
                    elif self.getIntegerNumberToken(sourceCode[index:]) != None:
                        intTK = self.getIntegerNumberToken(sourceCode[index:])[0]
                        totalIndex = index + len(intTK.lexeme)
                        tokenval = TokenVal.SCIENTIFIC_NOTATION.value
                        tokentype = TokenType.SCIENTIFIC_NOTATION.value
                        lexeme = sourceCode[0:totalIndex]
                        tk = token(tokentype, tokenval, lexeme)
                        slicedSourceCode = sourceCode[totalIndex:]
                        return tk, slicedSourceCode
            else:
                return None
        except IndexError:
            return None
Пример #2
0
 def getFloatNumberToken(self, sourceCode):
     if self.__isNumber__(sourceCode):
         try:
             index = 0
             for i in range(len(sourceCode)):
                 if self.__isNumber__(sourceCode[i]):
                     index = i
                 else:
                         break
             index = index + 1
             if sourceCode[index] == ".":
                 newIndex = index + 1
                 if newIndex > len(sourceCode):
                     index = newIndex
                 else:    
                     for j in range(newIndex, len(sourceCode)):
                         if self.__isNumber__(sourceCode[j]):
                             index = j
                         else:
                             break
                 index = index + 1
                 if index > len(sourceCode):
                     index = len(sourceCode) - 1
                 tokentype = TokenType.FLOAT_NUMBER
                 tokenval = TokenVal.FLOAT_NUMBER
                 lexeme = sourceCode[0:index]
                 tk = token(tokentype.value, tokenval.value, lexeme)
                 slicedSourceCode = sourceCode[index:]
                 return tk, slicedSourceCode
         except IndexError:
             return None
         else:
             return None
Пример #3
0
 def getLogicEqualsToken(self, sourceCode):
     if self.__isEqualityLexeme__(sourceCode):
         tokentype = TokenType.LOGIC_EQUALS
         tokenval = TokenVal.LOGIC_EQUALS
         lexeme = "="
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[1:]
         return tk, slicedSourceCode
     else:
         return None
Пример #4
0
 def getLogicOrToken(self, sourceCode):
     if self.__isLogicOrLexeme__(sourceCode):
         tokentype = TokenType.LOGIC_OR
         tokenval = TokenVal.LOGIC_OR
         lexeme = "||"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[2:]
         return tk, slicedSourceCode
     else:
         return None
Пример #5
0
 def getOpenBracketsToken(self, sourceCode):
     if self.__isOpenBracketsLexeme__(sourceCode):
         tokentype = TokenType.OPEN_BRACKETS
         tokenval = TokenVal.OPEN_BRACKETS
         lexeme = "["
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[1:]
         return tk, slicedSourceCode
     else:
         return None
Пример #6
0
 def getCloseParenthesesToken(self, sourceCode):
     if self.__isCloseParenthesesLexeme__(sourceCode):
         tokentype = TokenType.CLOSE_PARENTHESES
         tokenval = TokenVal.CLOSE_PARENTHESES
         lexeme = ")"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[1:]
         return tk, slicedSourceCode
     else:
         return None
Пример #7
0
 def getHigherEqualsToken(self, sourceCode):
     if self.__isHigherEqualsLexeme__(sourceCode):
         tokentype = TokenType.HIGHER_EQUALS
         tokenval = TokenVal.HIGHER_EQUALS
         lexeme = ">="
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[2:]
         return tk, slicedSourceCode
     else:
         return None
Пример #8
0
 def getHigherToken(self, sourceCode):
     if self.__isHigherLexeme__(sourceCode):
         tokentype = TokenType.HIGHER
         tokenval = TokenVal.HIGHER
         lexeme = ">"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[1:]
         return tk, slicedSourceCode
     else:
         return None
Пример #9
0
 def getReadToken(self, sourceCode):
     if self.__isReadLexeme__(sourceCode):
         tokentype = TokenType.READ
         tokenval = TokenVal.READ
         lexeme = "leia"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[4:]
         return tk, slicedSourceCode
     else:
         return None
Пример #10
0
 def getUntilToken(self, sourceCode):
     if self.__isUntilLexeme__(sourceCode):
         tokentype = TokenType.UNTIL
         tokenval = TokenVal.UNTIL
         lexeme = "até"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[3:]
         return tk, slicedSourceCode
     else:
         return None
Пример #11
0
 def getReturnToken(self, sourceCode):
     if self.__isReturnLexeme__(sourceCode):
         tokentype = TokenType.RETURN
         tokenval = TokenVal.RETURN
         lexeme = "retorna"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[7:]
         return tk, slicedSourceCode
     else:
         return None
Пример #12
0
 def getForToken(self, sourceCode):
     if self.__isForLexeme__(sourceCode):
         tokentype = TokenType.FOR
         tokenval = TokenVal.FOR
         lexeme = "repita"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[6:]
         return tk, slicedSourceCode
     else:
         return None
Пример #13
0
 def getEndToken(self, sourceCode):
     if self.__isEndLexeme__(sourceCode):
         tokentype = TokenType.END
         tokenval = TokenVal.END
         lexeme = "fim"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[3:]
         return tk, slicedSourceCode
     else:
         return None
Пример #14
0
 def getThenToken(self, sourceCode):
     if self.__isThenLexeme__(sourceCode):
         tokentype = TokenType.THEN
         tokenval = TokenVal.THEN
         lexeme = "então"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[5:]
         return tk, slicedSourceCode
     else:
         return None
Пример #15
0
 def getElseToken(self, sourceCode):
     if self.__isElseLexeme__(sourceCode):
         tokentype = TokenType.ELSE
         tokenval = TokenVal.ELSE
         lexeme = "senão"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[5:]
         return tk, slicedSourceCode
     else:
         return None
Пример #16
0
 def getAssignmentToken(self, sourceCode):
     if self.__isAssignmentLexeme__(sourceCode):
         tokentype = TokenType.ASSIGNMENT
         tokenval = TokenVal.ASSIGNMENT
         lexeme = ":="
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[2:]
         return tk, slicedSourceCode
     else:
         return None
Пример #17
0
 def getWriteToken(self, sourceCode):
     if self.__isWriteLexeme__(sourceCode):
         tokentype = TokenType.WRITE
         tokenval = TokenVal.WRITE
         lexeme = "escreve"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[7:]
         return tk, slicedSourceCode
     else:
         return None
Пример #18
0
 def getLessEqualsToken(self, sourceCode):
     if self.__isLessEqualsLexeme__(sourceCode):
         tokentype = TokenType.LESS_EQUALS
         tokenval = TokenVal.LESS_EQUALS
         lexeme = "<="
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[2:]
         return tk, slicedSourceCode
     else:
         return None
Пример #19
0
 def getIntegerTypeToken(self, sourceCode):
     if self.__isIntegerTypeLexeme__(sourceCode):
         tokentype = TokenType.INTEGER_TYPE
         tokenval = TokenVal.INTEGER_TYPE
         lexeme = "inteiro"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[7:]
         return tk, slicedSourceCode
     else:
         return None
Пример #20
0
 def getOpenParethesesToken(self, sourceCode):
     if self.__isOPenParenthesesLexeme__(sourceCode):
         tokentype = TokenType.OPEN_PARENTHESES
         tokenval = TokenVal.OPEN_PARENTHESES
         lexeme = "("
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[1:]
         return tk, slicedSourceCode
     else:
         return None
Пример #21
0
 def getFloatTypeToken(self, sourceCode):
     if self.__isFloatTypeLexeme__(sourceCode):
         tokentype = TokenType.FLOAT_TYPE
         tokenval = TokenVal.FLOAT_TYPE
         lexeme = "flutuante"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[9:]
         return tk, slicedSourceCode
     else:
         return None
Пример #22
0
 def getTwoDotsToken(self, sourceCode):
     if self.__isTwoDotsLexeme_(sourceCode):
         tokentype = TokenType.TWO_DOTS
         tokenval = TokenVal.TWO_DOTS
         lexeme = ":"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[1:]
         return tk, slicedSourceCode
     else:
         return None
Пример #23
0
 def getMinusToken(self, sourceCode):
     if self.__isMinusLexeme__(sourceCode):
         tokentype = TokenType.MINUS
         tokenval = TokenVal.MINUS
         lexeme = "-"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[1:]
         return tk, slicedSourceCode
     else:
         return None
Пример #24
0
 def getCloseBracketsToken(self, sourceCode):
     if self.__isCloseBracketsLexeme__(sourceCode):
         tokentype = TokenType.CLOSE_BRACKETS
         tokenval = TokenVal.CLOSE_BRACKETS
         lexeme = "]"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[1:]
         return tk, slicedSourceCode
     else:
         return None
Пример #25
0
 def getTimesToken(self, sourceCode):
     if self.__isTimesLexeme__(sourceCode):
         tokentype = TokenType.TIMES
         tokenval = TokenVal.TIMES
         lexeme = "*"    
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[1:]
         return tk, slicedSourceCode
     else:
         return None
Пример #26
0
 def getLogicNotToken(self, sourceCode):
     if self.__isNotLexeme__(sourceCode):
         tokentype = TokenType.LOGIC_NOT
         tokenval = TokenVal.LOGIC_NOT
         lexeme = "!"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[1:]
         return tk, slicedSourceCode
     else:
         return None
Пример #27
0
 def getDivisionToken(self, sourceCode):
     if self.__isDivisionLexeme__(sourceCode):
         tokentype = TokenType.DIVISION
         tokenval = TokenVal.DIVISION
         lexeme = "/"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[1:]
         return tk, slicedSourceCode
     else:
         return None
Пример #28
0
 def getCommaToken(self, sourceCode):
     if self.__isCommaLexeme__(sourceCode):
         tokentype = TokenType.COMMA
         tokenval = TokenVal.COMMA
         lexeme = ","
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[1:]
         return tk, slicedSourceCode
     else:
         return None
Пример #29
0
 def getIfToken(self, sourceCode):
     if self.__isIFLexeme__(sourceCode):
         tokentype = TokenType.IF
         tokenval = TokenVal.IF
         lexeme = "se"
         tk = token(tokentype.value, tokenval.value, lexeme)
         slicedSourceCode = sourceCode[2:]
         return tk, slicedSourceCode
     else:
         return None
Пример #30
0
    def getIdToken(self, sourceCode):
        letters = self.uppercaseLetters + self.lowercaseLetters + self.specialUpperCases + self.specialLowerCases
        lettersAndDigits = letters + self.naturalDigits
        if sourceCode[0] not in letters:
            return None
        for i in range(len(sourceCode)):

            if sourceCode[i] not in lettersAndDigits:
                tokentype = TokenType.IDENTIFICATOR.value
                tokenval = TokenVal.IDENTIFICATOR.value
                lexeme = sourceCode[0:i]
                tk = token(tokentype, tokenval, lexeme) 
                slicedSourceCode = sourceCode[i:]
                return tk, slicedSourceCode
        tokentype = TokenType.IDENTIFICATOR.value
        tokenval = TokenVal.IDENTIFICATOR.value
        lexeme = sourceCode[0:]
        tk = token(tokentype, tokenval, lexeme) 
        slicedSourceCode = ""
        return tk, slicedSourceCode