summaryrefslogblamecommitdiffstats
path: root/src/front/token.py
blob: 78e9dab3b258427e0b11cead7c98a5836053f3b6 (plain) (tree)
1
2
3
4
5
6
7
8
                       
 


                        

                             
 





                                 
            
                               
                             











                                
                             


                                   

                              
 
                    
                               
 
                                          
                      
                          

                       
                      

                                                                         
# -*- coding: utf-8 -*-

class Tag(object):
    __slots__ = ["name"]

    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name

    def __repr__(self):
        return "<Tag: %s>" % self

# token tags
Tag.NUMBER      = Tag("NUMBER")
Tag.BOOL        = Tag("BOOL")
Tag.IDENT       = Tag("IDENT")
Tag.WHILE       = Tag("WHILE")
Tag.IF          = Tag("IF")
Tag.ELSE        = Tag("ELSE")
Tag.END         = Tag("END")
Tag.LBRAK       = Tag("LBRAK")
Tag.RBRAK       = Tag("RBRAK")
Tag.LPAREN      = Tag("LPAREN")
Tag.RPAREN      = Tag("RPAREN")
Tag.NEWLINE     = Tag("NEWLINE")
Tag.COMMA       = Tag("COMMA")
Tag.FUN         = Tag("FUN")
Tag.CALL        = Tag("CALL")
Tag.ASSIGNMENT  = Tag("ASSIGNMENT")
Tag.RETURN      = Tag("RETURN")
Tag.OPERATOR    = Tag("OPERATOR")
Tag.TRUE        = Tag("TRUE")
Tag.FALSE       = Tag("FALSE")

class Token(object):
    __slots__ = ["tag","value"]

    def __init__(self, tag, value = None):
        self.tag = tag
        self.value = value

    def __repr__(self):
        if self.value:
            return "<Token: %s, Value: %s>" % (self.tag, str(self.value))
        return "<Token: %s>" % self.tag