-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExecution.rb
91 lines (73 loc) · 1.49 KB
/
Execution.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#
# Hash para la ejecucion, guarda la variable con su valor
# ademas de atributo elastico(si se puede modificar)
class ValueTable
def initialize(padre = nil)
@padre = padre
@table = {}
end
def insert(variable)
@table[variable] = {:valor => nil, :elastico => true}
end
def update(variable, valor)
find(variable)[:valor] = valor
end
def elasticized(variable)
find(variable)[:elastico] = true
end
def d_elasticized(variable)
find(variable)[:elastico] = false
end
def find(variable)
if @table.has_key?(variable) then
return @table[variable]
elsif @padre.nil? then
return nil
end
@padre.find(variable)
end
end
#
# Clase de para interaccion de las cintas, con todos los metodos
# especificados.
#
class Band
attr_reader :cinta
def initialize(length)
@cinta = Array::new(length, 0)
@actual = 0
end
def dot
@cinta[@actual]
end
def coma
print "\nIntrodusca El Valor Para La Cinta(Solo importara el primer caracter, sin exiten mas solo seran ignorados): "
@cinta[@actual] = STDIN.gets.chomp.chr.ord
end
def plus
@cinta[@actual] += 1
end
def minus
@cinta[@actual] -= 1
end
def right
if @actual == (@cinta.length - 1) then
@actual = 0
else
@actual +=1
end
end
def left
if @actual == 0 then
@actual = @cinta.length - 1
else
@actual -= 1
end
end
def concat(tape)
@cinta + tape.cinta
end
def p_all
puts "#{@cinta}"
end
end