<s>
Stack-oriented	B-Language
programming	I-Language
is	O
a	O
programming	O
paradigm	O
which	O
relies	O
on	O
a	O
stack	B-Application
machine	I-Application
model	O
for	O
passing	O
parameters	O
.	O
</s>
<s>
Stack-oriented	B-Language
languages	I-Language
operate	O
on	O
one	O
or	O
more	O
stacks	B-Application
,	O
each	O
of	O
which	O
may	O
serve	O
a	O
different	O
purpose	O
.	O
</s>
<s>
Programming	O
constructs	O
in	O
other	O
programming	O
languages	O
need	O
to	O
be	O
modified	O
for	O
use	O
in	O
a	O
stack-oriented	O
system	O
.	O
</s>
<s>
Most	O
stack-oriented	B-Language
languages	I-Language
operate	O
in	O
postfix	O
or	O
Reverse	B-Application
Polish	I-Application
notation	O
.	O
</s>
<s>
The	O
programming	O
languages	O
Forth	B-Application
,	O
Factor	B-Application
,	O
RPL	B-Device
,	O
PostScript	B-Language
,	O
BibTeX	B-Language
style	O
design	O
language	O
and	O
many	O
assembly	B-Language
languages	I-Language
fit	O
this	O
paradigm	O
.	O
</s>
<s>
Stack-based	B-Language
algorithms	O
consider	O
data	O
,	O
by	O
utilising	O
one	O
piece	O
of	O
data	O
from	O
atop	O
the	O
stack	B-Application
,	O
and	O
returning	O
data	O
back	O
atop	O
the	O
stack	B-Application
.	O
</s>
<s>
The	O
need	O
for	O
stack	B-Application
manipulation	O
operators	O
,	O
allow	O
for	O
the	O
stack	B-Application
to	O
manipulate	O
data	O
.	O
</s>
<s>
To	O
emphasise	O
the	O
effect	O
of	O
a	O
statement	O
,	O
a	O
comment	O
is	O
used	O
showing	O
the	O
top	O
of	O
the	O
stack	B-Application
before	O
and	O
after	O
the	O
statement	O
.	O
</s>
<s>
This	O
is	O
known	O
as	O
the	O
stack	B-Application
effect	O
diagram	O
.	O
</s>
<s>
Postscript	B-Language
stacks	B-Application
consider	O
separate	O
stacks	B-Application
for	O
additional	O
purposes	O
.	O
</s>
<s>
The	O
analysis	O
of	O
the	O
language	B-Language
model	I-Language
allows	O
expressions	O
and	O
programs	O
to	O
be	O
interpreted	O
simply	O
and	O
theoretically	O
.	O
</s>
<s>
PostScript	B-Language
is	O
an	O
example	O
of	O
a	O
postfix	O
stack-based	B-Language
language	I-Language
.	O
</s>
<s>
Calculating	O
the	O
expression	O
involves	O
understanding	O
how	O
stack-orientation	O
works	O
.	O
</s>
<s>
Stack-orientation	O
can	O
be	O
presented	O
as	O
the	O
following	O
conveyor	O
belt	O
analogy	O
.	O
</s>
<s>
The	O
plates	O
can	O
only	O
be	O
stored	O
in	O
a	O
stack	B-Application
,	O
and	O
can	O
only	O
be	O
added	O
or	O
removed	O
from	O
atop	O
the	O
stack	B-Application
,	O
not	O
from	O
the	O
middle	O
or	O
bottom	O
.	O
</s>
<s>
Take	O
plate	O
2	O
and	O
put	O
it	O
on	O
the	O
stack	B-Application
,	O
then	O
take	O
plate	O
3	O
and	O
put	O
it	O
on	O
the	O
stack	B-Application
.	O
</s>
<s>
Then	O
,	O
take	O
the	O
top	O
two	O
plates	O
off	O
the	O
stack	B-Application
,	O
multiply	O
their	O
labels	O
(	O
2	O
and	O
3	O
)	O
,	O
and	O
write	O
the	O
result	O
(	O
6	O
)	O
on	O
a	O
new	O
plate	O
.	O
</s>
<s>
Discard	O
the	O
two	O
old	O
plates	O
(	O
2	O
and	O
3	O
)	O
and	O
the	O
plate	O
mul	O
,	O
and	O
put	O
the	O
new	O
plate	O
on	O
the	O
stack	B-Application
.	O
</s>
<s>
With	O
no	O
more	O
plates	O
remaining	O
on	O
the	O
conveyor	O
,	O
the	O
result	O
of	O
the	O
calculation	O
(	O
6	O
)	O
is	O
shown	O
on	O
the	O
plate	O
atop	O
the	O
stack	B-Application
.	O
</s>
<s>
Each	O
column	O
shows	O
an	O
input	O
element	O
(	O
the	O
plate	O
at	O
the	O
end	O
of	O
the	O
conveyor	O
)	O
,	O
and	O
the	O
contents	O
of	O
the	O
stack	B-Application
after	O
processing	O
that	O
input	O
.	O
</s>
<s>
After	O
processing	O
all	O
the	O
input	O
,	O
the	O
stack	B-Application
contains	O
56	O
,	O
which	O
is	O
the	O
answer	O
.	O
</s>
<s>
From	O
this	O
,	O
the	O
following	O
can	O
be	O
concluded	O
:	O
a	O
stack-based	B-Language
programming	O
language	O
has	O
only	O
one	O
way	O
to	O
handle	O
data	O
,	O
by	O
taking	O
one	O
piece	O
of	O
data	O
from	O
atop	O
the	O
stack	B-Application
,	O
termed	O
popping	O
,	O
and	O
putting	O
data	O
back	O
atop	O
the	O
stack	B-Application
,	O
termed	O
pushing	O
.	O
</s>
<s>
Any	O
expression	O
that	O
can	O
be	O
written	O
conventionally	O
,	O
or	O
in	O
another	O
programming	O
language	O
,	O
can	O
be	O
written	O
in	O
postfix	O
(	O
or	O
prefix	O
)	O
form	O
and	O
thus	O
be	O
amenable	O
to	O
being	O
interpreted	O
by	O
a	O
stack-oriented	B-Language
language	I-Language
.	O
</s>
<s>
Since	O
the	O
stack	B-Application
is	O
the	O
key	O
means	O
to	O
manipulate	O
data	O
in	O
a	O
stack-oriented	B-Language
language	I-Language
,	O
such	O
languages	O
often	O
provide	O
some	O
sort	O
of	O
stack	B-Application
manipulation	O
operators	O
.	O
</s>
<s>
Commonly	O
provided	O
are	O
dup	O
,	O
to	O
duplicate	O
the	O
element	O
atop	O
the	O
stack	B-Application
,	O
exch	O
(	O
or	O
swap	O
)	O
,	O
to	O
exchange	O
elements	O
atop	O
the	O
stack	B-Application
(	O
the	O
first	O
becomes	O
second	O
and	O
the	O
second	O
becomes	O
first	O
)	O
,	O
roll	O
,	O
to	O
cyclically	O
permute	O
elements	O
in	O
the	O
stack	B-Application
or	O
on	O
part	O
of	O
the	O
stack	B-Application
,	O
pop	O
(	O
or	O
drop	O
)	O
,	O
to	O
discard	O
the	O
element	O
atop	O
the	O
stack	B-Application
(	O
push	O
is	O
implicit	O
)	O
,	O
and	O
others	O
.	O
</s>
<s>
As	O
an	O
aid	O
to	O
understanding	O
the	O
effect	O
of	O
statement	O
,	O
a	O
short	O
comment	O
is	O
used	O
showing	O
the	O
top	O
of	O
the	O
stack	B-Application
before	O
and	O
after	O
the	O
statement	O
.	O
</s>
<s>
The	O
top	O
of	O
the	O
stack	B-Application
is	O
rightmost	O
if	O
there	O
are	O
multiple	O
items	O
.	O
</s>
<s>
This	O
notation	O
is	O
commonly	O
used	O
in	O
the	O
Forth	B-Application
language	I-Application
,	O
where	O
comments	O
are	O
enclosed	O
in	O
parentheses	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
basic	O
Forth	B-Application
stack	B-Application
operators	O
are	O
described	O
:	O
</s>
<s>
Both	O
comments	O
may	O
also	O
be	O
referenced	O
as	O
assertions	O
,	O
though	O
not	O
necessarily	O
in	O
context	O
of	O
Stack-based	B-Language
languages	I-Language
.	O
</s>
<s>
PostScript	B-Language
and	O
some	O
other	O
stack	B-Language
languages	I-Language
have	O
other	O
separate	O
stacks	B-Application
for	O
other	O
purposes	O
.	O
</s>
<s>
The	O
implementation	O
of	O
variables	O
is	O
important	O
for	O
any	O
programming	O
language	O
,	O
but	O
for	O
stack-oriented	B-Language
languages	I-Language
it	O
is	O
of	O
special	O
concern	O
,	O
as	O
there	O
is	O
only	O
one	O
way	O
to	O
interact	O
with	O
data	O
.	O
</s>
<s>
The	O
way	O
variables	O
are	O
implemented	O
in	O
stack-oriented	B-Language
languages	I-Language
such	O
as	O
PostScript	B-Language
usually	O
involves	O
a	O
separate	O
,	O
specialized	O
stack	B-Application
which	O
holds	O
dictionaries	O
of	O
key	B-Application
–	I-Application
value	I-Application
pairs	I-Application
.	O
</s>
<s>
In	O
PostScript	B-Language
,	O
a	O
name	O
data	O
object	O
is	O
prefixed	O
with	O
a	O
/	O
,	O
so	O
/x	O
is	O
a	O
name	O
data	O
object	O
which	O
can	O
be	O
associated	O
with	O
,	O
for	O
example	O
,	O
the	O
number	O
42	O
.	O
</s>
<s>
associates	O
with	O
the	O
name	O
x	O
with	O
the	O
number	O
42	O
in	O
the	O
dictionary	O
atop	O
the	O
stack	B-Application
.	O
</s>
<s>
A	O
procedure	O
in	O
a	O
stack-based	B-Language
programming	O
language	O
is	O
treated	O
as	O
a	O
data	O
object	O
in	O
its	O
own	O
right	O
.	O
</s>
<s>
In	O
PostScript	B-Language
,	O
procedures	O
are	O
denoted	O
between	O
{	O
and	O
}	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
PostScript	B-Language
syntax	O
,	O
</s>
<s>
represents	O
an	O
anonymous	O
procedure	O
to	O
duplicate	O
what	O
is	O
on	O
the	O
top	O
of	O
the	O
stack	B-Application
and	O
then	O
multiply	O
the	O
result	O
-	O
a	O
squaring	O
procedure	O
.	O
</s>
<s>
To	O
examine	O
a	O
Fibonacci	B-Algorithm
number	I-Algorithm
program	O
in	O
PostScript	B-Language
:	O
</s>
<s>
A	O
recursive	O
definition	O
is	O
used	O
on	O
the	O
stack	B-Application
.	O
</s>
<s>
The	O
Fibonacci	B-Algorithm
number	I-Algorithm
function	O
takes	O
one	O
argument	O
.	O
</s>
<s>
Decomposing	O
each	O
of	O
the	O
program	O
's	O
key	O
steps	O
,	O
reflecting	O
the	O
stack	B-Application
,	O
assuming	O
calculation	O
of	O
fib(4 )	O
:	O
</s>
<s>
This	O
procedure	O
does	O
not	O
use	O
named	O
variables	O
,	O
purely	O
the	O
stack	B-Application
.	O
</s>
<s>
Three	O
pieces	O
of	O
data	O
are	O
required	O
for	O
an	O
if-then-else	B-Language
statement	O
:	O
a	O
condition	O
,	O
a	O
procedure	O
to	O
be	O
done	O
if	O
the	O
condition	O
is	O
true	O
,	O
and	O
one	O
to	O
be	O
done	O
if	O
the	O
condition	O
is	O
false	O
.	O
</s>
<s>
In	O
PostScript	B-Language
for	O
example	O
,	O
</s>
<s>
The	O
simple	O
model	O
provided	O
in	O
a	O
stack-oriented	B-Language
language	I-Language
allows	O
expressions	O
and	O
programs	O
to	O
be	O
interpreted	O
simply	O
and	O
theoretically	O
evaluated	O
much	O
faster	O
,	O
since	O
no	O
syntax	B-Language
analysis	I-Language
need	O
be	O
done	O
,	O
only	O
lexical	B-Application
analysis	I-Application
.	O
</s>
<s>
The	O
way	O
such	O
programs	O
are	O
written	O
facilitates	O
being	O
interpreted	O
by	O
machines	O
,	O
which	O
is	O
why	O
PostScript	B-Language
suits	O
printers	O
well	O
for	O
its	O
use	O
.	O
</s>
<s>
However	O
,	O
the	O
slightly	O
artificial	O
way	O
of	O
writing	O
PostScript	B-Language
programs	O
can	O
form	O
an	O
initial	O
barrier	O
to	O
understanding	O
stack-oriented	B-Language
languages	I-Language
such	O
as	O
PostScript	B-Language
.	O
</s>
<s>
While	O
the	O
ability	O
to	O
shadow	O
by	O
overriding	B-Language
inbuilt	O
and	O
other	O
definitions	O
can	O
make	O
programs	O
hard	O
to	O
debug	O
,	O
and	O
irresponsible	O
use	O
of	O
this	O
feature	O
can	O
cause	O
unpredictable	O
behaviour	O
,	O
it	O
can	O
simplify	O
some	O
functions	O
greatly	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
PostScript	B-Language
use	O
,	O
the	O
showpage	O
operator	O
can	O
be	O
overridden	O
with	O
a	O
custom	O
one	O
that	O
applies	O
a	O
certain	O
style	O
to	O
the	O
page	O
,	O
instead	O
of	O
having	O
to	O
define	O
a	O
custom	O
operator	O
or	O
to	O
repeat	O
code	O
to	O
generate	O
the	O
style	O
.	O
</s>
