<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
canonical	B-Application
LR	I-Application
parser	I-Application
or	O
LR(1 )	O
parser	O
is	O
an	O
LR(k )	O
parser	O
for	O
k	O
=	O
1	O
,	O
i.e.	O
</s>
<s>
In	O
the	O
past	O
this	O
LR(k )	O
parser	O
has	O
been	O
avoided	O
because	O
of	O
its	O
huge	O
memory	O
requirements	O
in	O
favor	O
of	O
less	O
powerful	O
alternatives	O
such	O
as	O
the	O
LALR	B-Application
and	O
the	O
LL(1 )	O
parser	O
.	O
</s>
<s>
Recently	O
,	O
however	O
,	O
a	O
"	O
minimal	O
LR(1 )	O
parser	O
"	O
whose	O
space	O
requirements	O
are	O
close	O
to	O
LALR	B-Application
parsers	I-Application
,	O
is	O
being	O
offered	O
by	O
several	O
parser	B-Language
generators	I-Language
.	O
</s>
<s>
Like	O
most	O
parsers	O
,	O
the	O
LR(1 )	O
parser	O
is	O
automatically	O
generated	O
by	O
compiler-compilers	B-Language
like	O
GNU	B-Application
Bison	I-Application
,	O
MSTA	O
,	O
Menhir	O
,	O
HYACC	O
,	O
LRSTAR	O
.	O
</s>
<s>
In	O
1965	O
Donald	O
Knuth	O
invented	O
the	O
LR(k )	O
parser	O
(	O
Left	O
to	O
right	O
,	O
Rightmost	O
derivation	O
parser	O
)	O
a	O
type	O
of	O
shift-reduce	B-Application
parser	I-Application
,	O
as	O
a	O
generalization	O
of	O
existing	O
precedence	O
parsers	O
.	O
</s>
<s>
In	O
1969	O
,	O
Frank	O
DeRemer	O
suggested	O
two	O
simplified	O
versions	O
of	O
the	O
LR	B-Application
parser	I-Application
called	O
LALR	B-Application
and	O
SLR	B-Application
.	O
</s>
<s>
LALR(1 )	O
parsers	O
have	O
been	O
the	O
most	O
common	O
implementations	O
of	O
the	O
LR	B-Application
Parser	I-Application
.	O
</s>
<s>
However	O
,	O
a	O
new	O
type	O
of	O
LR(1 )	O
parser	O
,	O
some	O
people	O
call	O
a	O
"	O
Minimal	O
LR(1 )	O
parser	O
"	O
was	O
introduced	O
in	O
1977	O
by	O
David	O
Pager	O
who	O
showed	O
that	O
LR(1 )	O
parsers	O
can	O
be	O
created	O
whose	O
memory	O
requirements	O
rival	O
those	O
of	O
LALR(1 )	O
parsers	O
.	O
</s>
<s>
Recently	O
,	O
some	O
parser	B-Language
generators	I-Language
are	O
offering	O
Minimal	O
LR(1 )	O
parsers	O
,	O
which	O
not	O
only	O
solve	O
the	O
memory	O
requirement	O
problem	O
,	O
but	O
also	O
the	O
mysterious-conflict-problem	O
inherent	O
in	O
LALR(1 )	O
parser	B-Language
generators	I-Language
.	O
</s>
<s>
In	O
addition	O
,	O
Minimal	O
LR(1 )	O
parsers	O
can	O
use	O
shift-reduce	B-Application
actions	O
,	O
which	O
makes	O
them	O
faster	O
than	O
Canonical	O
LR(1 )	O
parsers	O
.	O
</s>
<s>
The	O
LR(1 )	O
parser	O
is	O
a	O
deterministic	B-Application
automaton	I-Application
and	O
as	O
such	O
its	O
operation	O
is	O
based	O
on	O
static	O
state	B-Application
transition	I-Application
tables	I-Application
.	O
</s>
<s>
An	O
item	O
set	O
has	O
a	O
one-to-one	O
correspondence	O
to	O
a	O
parser	O
state	O
,	O
while	O
the	O
items	O
within	O
the	O
set	O
,	O
together	O
with	O
the	O
next	O
symbol	O
,	O
are	O
used	O
to	O
decide	O
which	O
state	B-Application
transitions	I-Application
and	O
parser	O
action	O
are	O
to	O
be	O
applied	O
.	O
</s>
<s>
For	O
example	O
,	O
assume	O
a	O
language	O
consisting	O
of	O
the	O
terminal	O
symbols	O
'	O
n	O
 '	O
,	O
'	O
+	O
 '	O
,	O
'	O
( 	O
 '	O
,	O
'	O
)	O
'	O
,	O
the	O
nonterminals	B-Algorithm
'	O
E	O
 '	O
,	O
'	O
T	O
 '	O
,	O
the	O
starting	O
rule	O
'	O
S	O
 '	O
and	O
the	O
following	O
production	O
rules	O
:	O
</s>
<s>
Each	O
item	O
set	O
must	O
be	O
'	O
closed	O
 '	O
,	O
which	O
means	O
all	O
production	O
rules	O
for	O
each	O
nonterminal	B-Algorithm
following	O
a	O
'	O
•	O
 '	O
have	O
to	O
be	O
recursively	O
included	O
into	O
the	O
item	O
set	O
until	O
all	O
of	O
those	O
nonterminals	B-Algorithm
are	O
dealt	O
with	O
.	O
</s>
<s>
In	O
our	O
example	O
,	O
the	O
starting	O
symbol	O
requires	O
the	O
nonterminal	B-Algorithm
'	O
E	O
 '	O
which	O
in	O
turn	O
requires	O
'	O
T	O
 '	O
,	O
thus	O
all	O
production	O
rules	O
will	O
appear	O
in	O
item	O
set	O
0	O
.	O
</s>
<s>
FIRST(A )	O
is	O
the	O
set	O
of	O
terminals	O
which	O
can	O
appear	O
as	O
the	O
first	O
element	O
of	O
any	O
chain	O
of	O
rules	O
matching	O
nonterminal	B-Algorithm
A	O
.	O
</s>
<s>
FOLLOW(I )	O
of	O
an	O
Item	O
I	O
[	O
A	O
→	O
α	O
•	O
B	O
β	O
,	O
x ]	O
is	O
the	O
set	O
of	O
terminals	O
that	O
can	O
appear	O
immediately	O
after	O
nonterminal	B-Algorithm
B	O
,	O
where	O
α	O
,	O
β	O
are	O
arbitrary	O
symbol	O
strings	O
,	O
and	O
x	O
is	O
an	O
arbitrary	O
lookahead	O
terminal	O
.	O
</s>
<s>
FOLLOW(k,B )	O
of	O
an	O
item	O
set	O
k	O
and	O
a	O
nonterminal	B-Algorithm
B	O
is	O
the	O
union	O
of	O
the	O
follow	O
sets	O
of	O
all	O
items	O
in	O
k	O
where	O
'	O
•	O
 '	O
is	O
followed	O
by	O
B	O
.	O
</s>
<s>
The	O
FIRST	O
sets	O
can	O
be	O
determined	O
directly	O
from	O
the	O
closures	O
of	O
all	O
nonterminals	B-Algorithm
in	O
the	O
language	O
,	O
while	O
the	O
FOLLOW	O
sets	O
are	O
determined	O
from	O
the	O
items	O
under	O
usage	O
of	O
the	O
FIRST	O
sets	O
.	O
</s>
<s>
From	O
this	O
the	O
full	O
item	O
set	O
0	O
for	O
an	O
LR(1 )	O
parser	O
can	O
be	O
created	O
,	O
by	O
creating	O
for	O
each	O
item	O
in	O
the	O
LR(0 )	O
item	O
set	O
one	O
copy	O
for	O
each	O
terminal	O
in	O
the	O
follow	O
set	O
of	O
the	O
LHS	O
nonterminal	B-Algorithm
.	O
</s>
<s>
For	O
each	O
terminal	O
and	O
nonterminal	B-Algorithm
symbol	O
A	O
appearing	O
after	O
a	O
'	O
•	O
 '	O
in	O
each	O
already	O
existing	O
item	O
set	O
k	O
,	O
create	O
a	O
new	O
item	O
set	O
m	O
by	O
adding	O
to	O
m	O
all	O
the	O
rules	O
of	O
k	O
where	O
'	O
•	O
 '	O
is	O
followed	O
by	O
A	O
,	O
but	O
only	O
if	O
m	O
will	O
not	O
be	O
the	O
same	O
as	O
an	O
already	O
existing	O
item	O
set	O
after	O
step	O
3	O
.	O
</s>
<s>
In	O
the	O
example	O
we	O
get	O
5	O
more	O
sets	O
from	O
item	O
set	O
0	O
,	O
item	O
set	O
1	O
for	O
nonterminal	B-Algorithm
E	O
,	O
item	O
set	O
2	O
for	O
nonterminal	B-Algorithm
T	O
,	O
item	O
set	O
3	O
for	O
terminal	O
n	O
,	O
item	O
set	O
4	O
for	O
terminal	O
'	O
+	O
 '	O
and	O
item	O
set	O
5	O
for	O
'	O
( 	O
 '	O
.	O
</s>
