aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/tokens.py
blob: 7a3990308adc3104a9e6853ae07778c97cb0136d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright (c) 2015 Egor Tensin <Egor.Tensin@gmail.com>
# This file is part of the "Simple interpreter" project.
# For details, see https://github.com/egor-tensin/simple-interpreter.
# Distributed under the MIT License.

class Token:
    pass

class AdditionOpToken(Token):
    def __str__(self):
        return '+'

class SubtractionOpToken(Token):
    def __str__(self):
        return '-'

class MultiplicationOpToken(Token):
    def __str__(self):
        return '*'

class DivisionOpToken(Token):
    def __str__(self):
        return '/'

class AssignmentOpToken(Token):
    def __str__(self):
        return ':='

class SemicolonToken(Token):
    def __str__(self):
        return ';'

class PrintToken(Token):
    def __str__(self):
        return 'print'

class OpeningParenToken(Token):
    def __str__(self):
        return '('

class ClosingParenToken(Token):
    def __str__(self):
        return ')'

class OpeningBraceToken(Token):
    def __str__(self):
        return '{'

class ClosingBraceToken(Token):
    def __str__(self):
        return '}'

class IdentifierToken(Token):
    def __init__(self, i):
        self._i = i

    def __str__(self):
        return str(self._i)

class FloatingPointNumberToken(Token):
    def __init__(self, n):
        self._n = n

    def __float__(self):
        return float(self._n)

    def __str__(self):
        return str(self._n)

class IntegerNumberToken(Token):
    def __init__(self, n):
        self._n = n

    def __int__(self):
        return int(self._n)

    def __str__(self):
        return str(self._n)

class TrueToken(Token):
    def __str__(self):
        return 'True'

class FalseToken(Token):
    def __str__(self):
        return 'False'

class AndOpToken(Token):
    def __str__(self):
        return '&&'

class OrOpToken(Token):
    def __str__(self):
        return '||'

class IfToken(Token):
    def __str__(self):
        return 'if'

class EqualsOpToken(Token):
    def __str__(self):
        return '=='

class NotEqualsOpToken(Token):
    def __str__(self):
        return '!='