Class: Korekto::Statements

Inherits:
Object
  • Object
show all
Defined in:
lib/korekto/statements.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStatements

Returns a new instance of Statements.



4
5
6
7
8
9
# File 'lib/korekto/statements.rb', line 4

def initialize
  @statements = []
  @heap = Heap.new(13)
  @symbols = Symbols.new
  @syntax = Syntax.new
end

Instance Attribute Details

#heapObject (readonly)

Returns the value of attribute heap.



3
4
5
# File 'lib/korekto/statements.rb', line 3

def heap
  @heap
end

#symbolsObject (readonly)

Returns the value of attribute symbols.



3
4
5
# File 'lib/korekto/statements.rb', line 3

def symbols
  @symbols
end

#syntaxObject (readonly)

Returns the value of attribute syntax.



3
4
5
# File 'lib/korekto/statements.rb', line 3

def syntax
  @syntax
end

Instance Method Details

#add(statement, code, title, filename, statement_number) ⇒ Object



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
# File 'lib/korekto/statements.rb', line 14

def add(statement,code,title,filename,statement_number)
  c = code[0]; w = c=='W'
  if restatement = @statements.detect{(w or _1.type==c) and _1.to_s==statement}
    case restatement.type
    when 'D','X','S','P','T','C','R'
      @heap.add restatement
    else
      raise Error, "restatement: #{restatement.code}"
    end
    code,_ = restatement.code
    title ||= restatement.title
    return code, title
  end
  statement = Statement.new(statement,code,title,filename,statement_number,self)
  @statements.push statement
  case statement.type
  when 'A','I','E','M','L'
    @symbols.define! statement
  when 'D','X','S'
    @symbols.define! statement
    @heap.add statement
  when 'P','T','C','R'
    @heap.add statement
  end
  return statement.code, statement.title
end

#lengthObject



12
# File 'lib/korekto/statements.rb', line 12

def length = @statements.length

#type(c) ⇒ Object



11
# File 'lib/korekto/statements.rb', line 11

def type(c) = @statements.select{_1.type==c}