Class: Stack
Overview
CLAZ declare############################################
Constant Summary collapse
- @@log =
Logger.new(STDOUT)
Class Method Summary collapse
Instance Method Summary collapse
- #evalStackTop ⇒ Object
- #getSp ⇒ Object
-
#initialize ⇒ Stack
constructor
A new instance of Stack.
- #insertNumber ⇒ Object
- #isTopofStack(item) ⇒ Object
- #pop ⇒ Object
- #push(pair) ⇒ Object
- #sizeofStack ⇒ Object
Constructor Details
#initialize ⇒ Stack
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
.destroy ⇒ Object
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 |
.dump ⇒ Object
398 399 400 |
# File 'lib/AoBane/utilities.rb', line 398 def self.dump @@log.debug("Stack DUMP:#{@stack}") end |
Instance Method Details
#evalStackTop ⇒ Object
376 377 378 |
# File 'lib/AoBane/utilities.rb', line 376 def evalStackTop return @stack.last end |
#getSp ⇒ Object
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 |
#insertNumber ⇒ Object
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 |
#pop ⇒ Object
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 |
#sizeofStack ⇒ Object
386 387 388 |
# File 'lib/AoBane/utilities.rb', line 386 def sizeofStack return @stack.size end |