30 lines
612 B
Plaintext
30 lines
612 B
Plaintext
include c:\cxpl\codes; \intrinsic 'code' declarations
|
|
int Stack(100), SP;
|
|
|
|
proc Push(I); \Push an integer onto the Stack
|
|
int I;
|
|
[SP:= SP+1;
|
|
Stack(SP):= I;
|
|
]; \Push
|
|
|
|
func Pop; \Pop an integer from the Stack
|
|
int I;
|
|
[I:= Stack(SP);
|
|
SP:= SP-1;
|
|
return I;
|
|
]; \Pop
|
|
|
|
func Empty; \Return 'true' if Stack is empty
|
|
return SP<0;
|
|
|
|
func Top; \Return the integer at top of Stack
|
|
return Stack(SP);
|
|
|
|
int I;
|
|
[SP:= -1; \initialize stack pointer
|
|
for I:= 0 to 10 do Push(I*I);
|
|
IntOut(0, Top); CrLf(0);
|
|
while not Empty do [IntOut(0, Pop); ChOut(0, ^ )];
|
|
CrLf(0);
|
|
]
|