Class: Stack

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/AoBane/utilities.rb

Overview

CLAZ declare############################################

Constant Summary collapse

@@log =
Logger.new(STDOUT)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStack

Returns a new instance of Stack.



347
348
349
350
# File 'lib/AoBane/utilities.rb', line 347

def initialize
  @stack = []
  @sp = 0
end

Class Method Details

.destroyObject



402
403
404
405
406
# File 'lib/AoBane/utilities.rb', line 402

def self.destroy
  if @stack.nil? then @stack = [] else @stack.clear end
  p @stack
  @sp = 0
end

.dumpObject



398
399
400
# File 'lib/AoBane/utilities.rb', line 398

def self.dump
  @@log.debug("Stack DUMP:#{@stack}")
end

Instance Method Details

#evalStackTopObject



376
377
378
# File 'lib/AoBane/utilities.rb', line 376

def evalStackTop
  return @stack.last
end

#getSpObject



380
381
382
383
384
# File 'lib/AoBane/utilities.rb', line 380

def getSp
  if @sp >= 0 then return @sp
  else raise FatalError,"SP is negative!"
  end
end

#insertNumberObject



372
373
374
# File 'lib/AoBane/utilities.rb', line 372

def insertNumber
 #   return str
end

#isTopofStack(item) ⇒ Object



390
391
392
393
394
395
396
# File 'lib/AoBane/utilities.rb', line 390

def isTopofStack(item)
  if item == @stack.last then
    return true
  else
    return false
  end
end

#popObject



363
364
365
366
367
368
369
370
# File 'lib/AoBane/utilities.rb', line 363

def pop
  @@log.debug("#{__LINE__} pop")
  if (@stack.size - 1) >= 0 then @sp -= 1;return @stack.pop
  else
    raise SyntaxError,"Stack Under Flow!"
  end
  @@log.debug "#{@stack}"
end

#push(pair) ⇒ Object



352
353
354
355
356
357
358
359
360
361
# File 'lib/AoBane/utilities.rb', line 352

def push(pair)
  @@log.debug("#{__LINE__} push #{pair}")
  if (@stack.size + 1) < $MAX_STACK then
    @stack.push(pair)
    @sp += 1
    @@log.debug @stack
  else
    raise SyntaxError,"Stack Over Flow!"
  end
end

#sizeofStackObject



386
387
388
# File 'lib/AoBane/utilities.rb', line 386

def sizeofStack
  return @stack.size
end