Stack.st
author Claus Gittinger <cg@exept.de>
Fri, 10 May 1996 13:09:23 +0200
changeset 296 3519dbc41ab1
parent 188 74c8f104cd71
child 482 6cc6fd9e31fe
permissions -rw-r--r--
*** empty log message ***

'From Smalltalk/X, Version:2.10.8 on 12-feb-1996 at 15:36:51'                   !

OrderedCollection subclass:#Stack
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'T-gen-Scanning/Parsing'
!

!Stack class methodsFor:'instance creation'!

new
        ^self new: 100
! !

!Stack methodsFor:'accessing'!

pop
        "Answer the object on top of the stack."

    ^ self removeLast

    "Created: 7.2.1996 / 00:12:53 / stefan"
    "Modified: 7.2.1996 / 00:13:53 / stefan"
!

pop: numElem 
        "Pop and discard top numElems and answer receiver"

        self removeLast:numElem

    "Created: 7.2.1996 / 00:12:53 / stefan"
    "Modified: 7.2.1996 / 00:14:16 / stefan"
!

push: anObject 
        "Push anObject onto the top of the stack."

    ^ self add:anObject

    "Created: 7.2.1996 / 00:12:53 / stefan"
    "Modified: 7.2.1996 / 00:14:52 / stefan"
!

top
        "Answer (without removing) the object on top of the stack."

        ^self last

    "Created: 7.2.1996 / 00:12:54 / stefan"
    "Modified: 7.2.1996 / 00:15:26 / stefan"
! !

!Stack methodsFor:'enumerating'!

do: aBlock
        "Evaluate aBlock for each object on the stack, from top to bottom."

        ^ super reverseDo:aBlock

    "Created: 7.2.1996 / 00:12:53 / stefan"
    "Modified: 7.2.1996 / 00:16:00 / stefan"
!

reverseDo: aBlock
        "Evaluate aBlock for each object on the stack, from bottom to top."

        ^ super do:aBlock

    "Created: 7.2.1996 / 00:12:54 / stefan"
    "Modified: 7.2.1996 / 00:16:18 / stefan"
! !