-
Notifications
You must be signed in to change notification settings - Fork 0
/
Symbol.rb
78 lines (63 loc) · 1.43 KB
/
Symbol.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
module Yisiel
class Symbol
attr_reader :ident, :line, :col
def initialize(ident, line, col)
@ident = ident
@line = line
@col = col
end
end
class SymValue < Symbol
attr_accessor :value
def initialize(ident, line, col)
super(ident, line, col)
@value = nil
end
def get_value
self.value
end
def set_value(x)
self.value = x
end
end
class SymParametroIn < SymValue; end
class SymParametroOut < SymValue; end
class SymArray < Symbol
def initialize(ident, line, col, size)
super(ident, line, col)
@size = size
@array = Array::new(@size)
end
def [](i)
@array[i]
end
def []=(i, value)
@array[i] = value
end
def size
@array.size
end
def get_value(i)
self[i]
end
def set_value(i,x)
self[i] = x
end
end
class SymProc < Symbol
attr_reader :tabla, :instruccion
def initialize(ident, line, col, parametros, definiciones, instruccion)
super(ident, line, col)
@tabla = SymTable::new
parametros.each do |parametro|
if parametro.kind_of? ParametroIn
@tabla.insert(SymParametroIn::new(parametro.ident))
elsif parametro.kind_of? ParametroOut
@tabla.insert(SymParametroOut::new(parametro.ident))
end
end
@definiciones = definiciones
@instruccion = instruccion
end
end
end