-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.rb
58 lines (53 loc) · 1.05 KB
/
token.rb
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
class Token
Plus = 1
Minus = 2
Multiply = 3
Devide = 4
LeftParen = 5
RightParen = 6
Power = 7
Modulo = 8
Number = 9
Variable = 10
Assign = 11
Function = 12
Defun = 13
If = 14
Then = 15
Else = 16
End = 17
Equal = 18
Greater = 19
Less = 20
EndLine = 21
attr_reader :kind
attr_accessor :value, :name
def initialize(kind)
@kind = kind
end
end
class NumberToken < Token
attr_reader :value
def initialize(value)
@kind = Token::Number
@value = value
end
end
class FunctionToken < Token
attr_reader :name
def initialize(name)
@kind = Token::Function
@name = get_name(name)
end
private
def get_name(str)
str.gsub(/\(/, "")
end
end
class VariableToken < Token
attr_reader :name
def initialize(name)
@kind = Token::Variable
@name = name
end
end