<s>
GNU	B-Application
Bison	I-Application
,	O
commonly	O
known	O
as	O
Bison	B-Application
,	O
is	O
a	O
parser	B-Language
generator	I-Language
that	O
is	O
part	O
of	O
the	B-Application
GNU	I-Application
Project	I-Application
.	O
</s>
<s>
Bison	B-Application
reads	O
a	O
specification	O
in	O
the	O
BNF	O
notation	O
(	O
a	O
context-free	O
language	O
)	O
,	O
warns	O
about	O
any	O
parsing	B-Language
ambiguities	O
,	O
and	O
generates	O
a	O
parser	O
that	O
reads	O
sequences	O
of	O
tokens	O
and	O
decides	O
whether	O
the	O
sequence	O
conforms	O
to	O
the	O
syntax	O
specified	O
by	O
the	O
grammar	O
.	O
</s>
<s>
The	O
generated	O
parsers	B-Language
are	O
portable	O
:	O
they	O
do	O
not	O
require	O
any	O
specific	O
compilers	O
.	O
</s>
<s>
Bison	B-Application
by	O
default	O
generates	O
LALR(1 )	O
parsers	B-Language
but	O
it	O
can	O
also	O
generate	O
canonical	B-Application
LR	I-Application
,	O
IELR(1 )	O
and	O
GLR	B-Application
parsers	I-Application
.	O
</s>
<s>
Flex	B-General_Concept
,	O
an	O
automatic	O
lexical	B-Application
analyser	I-Application
,	O
is	O
often	O
used	O
with	O
Bison	B-Application
,	O
to	O
tokenise	O
input	O
data	O
and	O
provide	O
Bison	B-Application
with	O
tokens	O
.	O
</s>
<s>
Bison	B-Application
was	O
originally	O
written	O
by	O
Robert	O
Corbett	O
in	O
1985	O
.	O
</s>
<s>
Later	O
,	O
in	O
1989	O
,	O
Robert	O
Corbett	O
released	O
another	O
parser	B-Language
generator	I-Language
named	O
Berkeley	B-Language
Yacc	I-Language
.	O
</s>
<s>
Bison	B-Application
was	O
made	O
Yacc-compatible	O
by	O
Richard	O
Stallman	O
.	O
</s>
<s>
Bison	B-Application
is	O
free	B-Application
software	I-Application
and	O
is	O
available	O
under	O
the	O
GNU	B-License
General	I-License
Public	I-License
License	I-License
,	O
with	O
an	O
exception	O
(	O
discussed	O
below	O
)	O
allowing	O
its	O
generated	O
code	O
to	O
be	O
used	O
without	O
triggering	O
the	O
copyleft	B-License
requirements	O
of	O
the	O
licence	O
.	O
</s>
<s>
One	O
delicate	O
issue	O
with	O
LR	O
parser	B-Language
generators	I-Language
is	O
the	O
resolution	O
of	O
conflicts	O
(	O
shift/reduce	O
and	O
reduce/reduce	O
conflicts	O
)	O
.	O
</s>
<s>
With	O
many	O
LR	O
parser	B-Language
generators	I-Language
,	O
resolving	O
conflicts	O
requires	O
the	O
analysis	O
of	O
the	O
parser	O
automaton	O
,	O
which	O
demands	O
some	O
expertise	O
from	O
the	O
user	O
.	O
</s>
<s>
To	O
aid	O
the	O
user	O
in	O
understanding	O
conflicts	O
more	O
intuitively	O
,	O
Bison	B-Application
can	O
instead	O
automatically	O
generate	O
counterexamples	O
.	O
</s>
<s>
For	O
ambiguous	O
grammars	O
,	O
Bison	B-Application
often	O
can	O
even	O
produce	O
counterexamples	O
that	O
show	O
the	O
grammar	O
is	O
ambiguous	O
.	O
</s>
<s>
Reentrancy	B-Operating_System
is	O
a	O
feature	O
which	O
has	O
been	O
added	O
to	O
Bison	B-Application
and	O
does	O
not	O
exist	O
in	O
Yacc	B-Application
.	O
</s>
<s>
Normally	O
,	O
Bison	B-Application
generates	O
a	O
parser	O
which	O
is	O
not	O
reentrant	B-Operating_System
.	O
</s>
<s>
In	O
order	O
to	O
achieve	O
reentrancy	B-Operating_System
the	O
declaration	O
%define	O
api.pure	O
must	O
be	O
used	O
.	O
</s>
<s>
More	O
details	O
on	O
Bison	B-Application
reentrancy	B-Operating_System
can	O
be	O
found	O
in	O
the	O
Bison	B-Application
manual	O
.	O
</s>
<s>
Bison	B-Application
can	O
generate	O
code	O
for	O
C	B-Language
,	O
C++	B-Language
,	O
D	B-Application
and	O
Java	B-Language
.	O
</s>
<s>
For	O
using	O
the	O
Bison-generated	O
parser	O
from	O
other	O
languages	O
a	O
language	B-Application
binding	I-Application
tool	O
such	O
as	O
SWIG	B-Application
can	O
be	O
used	O
.	O
</s>
<s>
Because	O
Bison	B-Application
generates	O
source	O
code	O
that	O
in	O
turn	O
gets	O
added	O
to	O
the	O
source	O
code	O
of	O
other	O
software	O
projects	O
,	O
it	O
raises	O
some	O
simple	O
but	O
interesting	O
copyright	O
questions	O
.	O
</s>
<s>
The	O
code	O
generated	O
by	O
Bison	B-Application
includes	O
significant	O
amounts	O
of	O
code	O
from	O
the	O
Bison	B-Application
project	O
itself	O
.	O
</s>
<s>
The	O
Bison	B-Application
package	O
is	O
distributed	O
under	O
the	O
terms	O
of	O
the	O
GNU	B-License
General	I-License
Public	I-License
License	I-License
(	O
GPL	B-License
)	O
but	O
an	O
exception	O
has	O
been	O
added	O
so	O
that	O
the	O
GPL	B-License
does	O
not	O
apply	O
to	O
output	O
.	O
</s>
<s>
Earlier	O
releases	O
of	O
Bison	B-Application
stipulated	O
that	O
parts	O
of	O
its	O
output	O
were	O
also	O
licensed	O
under	O
the	O
GPL	B-License
,	O
due	O
to	O
the	O
inclusion	O
of	O
the	O
yyparse( )	O
function	O
from	O
the	O
original	O
source	O
code	O
in	O
the	O
output	O
.	O
</s>
<s>
Free	B-Application
software	I-Application
projects	O
that	O
use	O
Bison	B-Application
may	O
have	O
a	O
choice	O
of	O
whether	O
to	O
distribute	O
the	O
source	O
code	O
which	O
their	O
project	O
feeds	O
into	O
Bison	B-Application
,	O
or	O
the	O
resulting	O
C	B-Language
code	O
made	O
output	O
by	O
Bison	B-Application
.	O
</s>
<s>
However	O
,	O
distributing	O
only	O
the	O
input	O
carries	O
the	O
minor	O
inconvenience	O
that	O
the	O
recipients	O
must	O
have	O
a	O
compatible	O
copy	O
of	O
Bison	B-Application
installed	O
so	O
that	O
they	O
can	O
generate	O
the	O
necessary	O
C	B-Language
code	O
when	O
compiling	O
the	O
project	O
.	O
</s>
<s>
And	O
distributing	O
only	O
the	O
C	B-Language
code	O
in	O
output	O
,	O
creates	O
the	O
problem	O
of	O
making	O
it	O
very	O
difficult	O
for	O
the	O
recipients	O
to	O
modify	O
the	O
parser	O
since	O
this	O
code	O
was	O
written	O
neither	O
by	O
a	O
human	O
nor	O
for	O
humans	O
-	O
its	O
purpose	O
is	O
to	O
be	O
fed	O
directly	O
into	O
a	O
C	B-Language
compiler	O
.	O
</s>
<s>
Projects	O
distributing	O
both	O
usually	O
do	O
not	O
have	O
the	O
generated	O
files	O
in	O
their	O
revision	B-Architecture
control	I-Architecture
systems	I-Architecture
.	O
</s>
<s>
Some	O
licenses	O
,	O
such	O
as	O
the	O
GPL	B-License
,	O
require	O
that	O
the	O
source	O
code	O
be	O
in	O
"	O
the	O
preferred	O
form	O
of	O
the	O
work	O
for	O
making	O
modifications	O
to	O
it	O
"	O
.	O
</s>
<s>
GPL	B-License
'd	O
projects	O
using	O
Bison	B-Application
must	O
thus	O
distribute	O
the	O
files	O
which	O
are	O
the	O
input	O
for	O
Bison	B-Application
.	O
</s>
<s>
Because	O
Bison	B-Application
was	O
written	O
as	O
a	O
replacement	O
for	O
Yacc	B-Application
,	O
and	O
is	O
largely	O
compatible	O
,	O
the	O
code	O
from	O
a	O
lot	O
of	O
projects	O
using	O
Bison	B-Application
could	O
equally	O
be	O
fed	O
into	O
Yacc	B-Application
.	O
</s>
<s>
This	O
makes	O
it	O
difficult	O
to	O
determine	O
if	O
a	O
project	O
"	O
uses	O
"	O
Bison-specific	O
source	O
code	O
or	O
not	O
.	O
</s>
<s>
In	O
many	O
cases	O
,	O
the	O
"	O
use	O
"	O
of	O
Bison	B-Application
could	O
be	O
trivially	O
replaced	O
by	O
the	O
equivalent	O
use	O
of	O
Yacc	B-Application
or	O
one	O
of	O
its	O
other	O
derivatives	O
.	O
</s>
<s>
Bison	B-Application
has	O
features	O
not	O
found	O
in	O
Yacc	B-Application
,	O
so	O
some	O
projects	O
can	O
be	O
truly	O
said	O
to	O
"	O
use	O
"	O
Bison	B-Application
,	O
since	O
Yacc	B-Application
would	O
not	O
suffice	O
.	O
</s>
<s>
The	O
following	O
list	O
is	O
of	O
projects	O
which	O
are	O
known	O
to	O
"	O
use	O
"	O
Bison	B-Application
in	O
the	O
looser	O
sense	O
,	O
that	O
they	O
use	O
free	B-Application
software	I-Application
development	I-Application
tools	O
and	O
distribute	O
code	O
which	O
is	O
intended	O
to	O
be	O
fed	O
into	O
Bison	B-Application
or	O
a	O
Bison-compatible	O
package	O
.	O
</s>
<s>
Bash	B-Operating_System
shell	I-Operating_System
uses	O
a	O
yacc	B-Application
grammar	O
for	O
parsing	B-Language
the	O
command	O
input	O
.	O
</s>
<s>
Bison	B-Application
's	O
own	O
grammar	B-Language
parser	I-Language
is	O
generated	O
by	O
Bison	B-Application
.	O
</s>
<s>
CMake	B-Language
uses	O
several	O
Bison	B-Application
grammars	O
.	O
</s>
<s>
The	O
Go	B-Application
programming	I-Application
language	I-Application
(	O
GC	O
)	O
used	O
Bison	B-Application
,	O
but	O
switched	O
to	O
a	O
hand-written	O
scanner	B-Application
and	O
parser	O
in	O
version	O
1.5	O
.	O
</s>
<s>
LilyPond	B-Application
requires	O
Bison	B-Application
to	O
generate	O
its	O
parser	O
.	O
</s>
<s>
GNU	B-Language
Octave	I-Language
uses	O
a	O
Bison-generated	O
parser	O
.	O
</s>
<s>
Perl	O
5	O
uses	O
a	O
Bison-generated	O
parser	O
starting	O
in	O
5.10	O
.	O
</s>
<s>
The	O
PHP	B-Application
programming	I-Application
language	I-Application
(	O
Zend	O
Parser	O
)	O
.	O
</s>
<s>
Ruby	B-Language
MRI	I-Language
,	O
the	O
reference	O
implementation	O
of	O
the	O
Ruby	B-Language
programming	I-Language
language	I-Language
,	O
relies	O
on	O
a	O
Bison	B-Application
grammar	O
.	O
</s>
<s>
syslog-ng	B-Protocol
uses	O
several	O
Bison	B-Application
grammars	O
assembled	O
together	O
.	O
</s>
<s>
The	O
following	O
example	O
shows	O
how	O
to	O
use	O
Bison	B-Application
and	O
flex	B-General_Concept
to	O
write	O
a	O
simple	O
calculator	O
program	O
(	O
only	O
addition	O
and	O
multiplication	O
)	O
and	O
a	O
program	O
for	O
creating	O
an	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
The	O
tokens	O
needed	O
by	O
the	O
Bison	B-Application
parser	O
will	O
be	O
generated	O
using	O
flex	B-General_Concept
.	O
</s>
<s>
In	O
a	O
language	O
such	O
as	O
C	B-Language
,	O
"	O
int	O
*	O
ptr	O
"	O
denotes	O
the	O
definition	O
of	O
a	O
pointer	O
,	O
not	O
a	O
product	O
:	O
it	O
would	O
be	O
wrong	O
to	O
name	O
this	O
"	O
*	O
"	O
"	O
TOKEN_MULTIPLY	O
"	O
.	O
</s>
<s>
Since	O
the	O
tokens	O
are	O
provided	O
by	O
flex	B-General_Concept
we	O
must	O
provide	O
the	O
means	O
to	O
communicate	O
between	O
the	O
parser	B-Application
and	I-Application
the	I-Application
lexer	I-Application
.	O
</s>
<s>
The	O
data	O
type	O
used	O
for	O
communication	O
,	O
YYSTYPE	O
,	O
is	O
set	O
using	O
Bison	B-Application
%union	O
declaration	O
.	O
</s>
<s>
Since	O
in	O
this	O
sample	O
we	O
use	O
the	O
reentrant	B-Operating_System
version	O
of	O
both	O
flex	B-General_Concept
and	O
yacc	B-Application
we	O
are	O
forced	O
to	O
provide	O
parameters	O
for	O
the	O
yylex	O
function	O
,	O
when	O
called	O
from	O
yyparse	O
.	O
</s>
<s>
This	O
is	O
done	O
through	O
Bison	B-Application
%	O
lex-param	O
and	O
%	O
parse-param	O
declarations	O
.	O
</s>
<s>
The	O
code	O
needed	O
to	O
obtain	O
the	O
syntax	O
tree	O
using	O
the	O
parser	O
generated	O
by	O
Bison	B-Application
and	O
the	O
scanner	B-Application
generated	O
by	O
flex	B-General_Concept
is	O
the	O
following	O
.	O
</s>
