<s>
A	O
syntactic	B-Application
predicate	I-Application
specifies	O
the	O
syntactic	O
validity	O
of	O
applying	O
a	O
production	O
in	O
a	O
formal	O
grammar	O
and	O
is	O
analogous	O
to	O
a	O
semantic	O
predicate	O
that	O
specifies	O
the	O
semantic	O
validity	O
of	O
applying	O
a	O
production	O
.	O
</s>
<s>
It	O
is	O
a	O
simple	O
and	O
effective	O
means	O
of	O
dramatically	O
improving	O
the	O
recognition	O
strength	O
of	O
an	O
LL	B-Language
parser	I-Language
by	O
providing	O
arbitrary	O
lookahead	O
.	O
</s>
<s>
In	O
their	O
original	O
implementation	O
,	O
syntactic	B-Application
predicates	I-Application
had	O
the	O
form	O
“	O
(	O
α	O
)	O
?	O
”	O
and	O
could	O
only	O
appear	O
on	O
the	O
left	O
edge	O
of	O
a	O
production	O
.	O
</s>
<s>
More	O
formally	O
,	O
a	O
syntactic	B-Application
predicate	I-Application
is	O
a	O
form	O
of	O
production	O
intersection	O
,	O
used	O
in	O
parser	B-Language
specifications	O
or	O
in	O
formal	O
grammars	O
.	O
</s>
<s>
As	O
typically	O
defined	O
or	O
implemented	O
,	O
syntactic	B-Application
predicates	I-Application
implicitly	O
order	O
the	O
productions	O
so	O
that	O
predicated	O
productions	O
specified	O
earlier	O
have	O
higher	O
precedence	O
than	O
predicated	O
productions	O
specified	O
later	O
within	O
the	O
same	O
decision	O
.	O
</s>
<s>
Parsing	B-Language
expression	O
grammars	O
(	O
PEGs	O
)	O
,	O
invented	O
by	O
Bryan	O
Ford	O
,	O
extend	O
these	O
simple	O
predicates	O
by	O
allowing	O
"	O
not	O
predicates	O
"	O
and	O
permitting	O
a	O
predicate	O
to	O
appear	O
anywhere	O
within	O
a	O
production	O
.	O
</s>
<s>
Moreover	O
,	O
Ford	O
invented	O
packrat	O
parsing	B-Language
to	O
handle	O
these	O
grammars	O
in	O
linear	O
time	O
by	O
employing	O
memoization	O
,	O
at	O
the	O
cost	O
of	O
heap	O
space	O
.	O
</s>
<s>
It	O
is	O
possible	O
to	O
support	O
linear-time	O
parsing	B-Language
of	O
predicates	O
as	O
general	O
as	O
those	O
allowed	O
by	O
PEGs	O
,	O
but	O
reduce	O
the	O
memory	O
cost	O
associated	O
with	O
memoization	O
by	O
avoiding	O
backtracking	O
where	O
some	O
more	O
efficient	O
implementation	O
of	O
lookahead	O
suffices	O
.	O
</s>
<s>
This	O
approach	O
is	O
implemented	O
by	O
ANTLR	B-Application
version	O
3	O
,	O
which	O
uses	O
Deterministic	B-General_Concept
finite	I-General_Concept
automata	I-General_Concept
for	O
lookahead	O
;	O
this	O
may	O
require	O
testing	O
a	O
predicate	O
in	O
order	O
to	O
choose	O
between	O
transitions	O
of	O
the	O
DFA	B-General_Concept
(	O
called	O
"	O
pred-LL	O
( *	O
)	O
"	O
parsing	B-Language
)	O
.	O
</s>
<s>
The	O
term	O
syntactic	B-Application
predicate	I-Application
was	O
coined	O
by	O
Parr	O
&	O
Quong	O
and	O
differentiates	O
this	O
form	O
of	O
predicate	O
from	O
semantic	O
predicates	O
(	O
also	O
discussed	O
)	O
.	O
</s>
<s>
Syntactic	B-Application
predicates	I-Application
have	O
been	O
called	O
multi-step	O
matching	O
,	O
parse	B-Language
constraints	O
,	O
and	O
simply	O
predicates	O
in	O
various	O
literature	O
.	O
</s>
<s>
This	O
article	O
uses	O
the	O
term	O
syntactic	B-Application
predicate	I-Application
throughout	O
for	O
consistency	O
and	O
to	O
distinguish	O
them	O
from	O
semantic	O
predicates	O
.	O
</s>
<s>
show	O
that	O
the	O
intersection	O
of	O
two	O
regular	B-General_Concept
languages	I-General_Concept
is	O
also	O
a	O
regular	B-General_Concept
language	I-General_Concept
,	O
which	O
is	O
to	O
say	O
that	O
the	O
regular	B-General_Concept
languages	I-General_Concept
are	O
closed	O
under	O
intersection	O
.	O
</s>
<s>
The	O
intersection	O
of	O
a	O
regular	B-General_Concept
language	I-General_Concept
and	O
a	O
context-free	O
language	O
is	O
also	O
closed	O
,	O
and	O
it	O
has	O
been	O
known	O
at	O
least	O
since	O
Hartmanis	O
that	O
the	O
intersection	O
of	O
two	O
context-free	O
languages	O
is	O
not	O
necessarily	O
a	O
context-free	O
language	O
(	O
and	O
is	O
thus	O
not	O
closed	O
)	O
.	O
</s>
<s>
In	O
most	O
formalisms	O
that	O
use	O
syntactic	B-Application
predicates	I-Application
,	O
the	O
syntax	O
of	O
the	O
predicate	O
is	O
noncommutative	O
,	O
which	O
is	O
to	O
say	O
that	O
the	O
operation	O
of	O
predication	O
is	O
ordered	O
.	O
</s>
<s>
Moreover	O
,	O
if	O
either	O
Y	O
or	O
Z	O
(	O
or	O
both	O
)	O
specify	O
any	O
action	O
to	O
be	O
taken	O
upon	O
reduction	O
(	O
as	O
would	O
be	O
the	O
case	O
in	O
many	O
parsers	B-Language
)	O
,	O
the	O
order	O
that	O
these	O
productions	O
match	O
determines	O
the	O
order	O
in	O
which	O
those	O
side-effects	O
occur	O
.	O
</s>
<s>
Parr	O
&	O
Quong	O
give	O
this	O
example	O
of	O
a	O
syntactic	B-Application
predicate	I-Application
:	O
</s>
<s>
which	O
is	O
intended	O
to	O
satisfy	O
the	O
following	O
informally	O
stated	O
constraints	O
of	O
C++	B-Language
:	O
</s>
<s>
In	O
the	O
first	O
production	O
of	O
rule	O
stat	O
,	O
the	O
syntactic	B-Application
predicate	I-Application
(	O
declaration	O
)	O
?	O
</s>
<s>
recognized	O
twice	O
—	O
once	O
as	O
syntactic	B-Application
predicate	I-Application
and	O
once	O
during	O
the	O
actual	O
parse	B-Language
to	O
execute	O
semantic	O
actions	O
.	O
</s>
<s>
Although	O
by	O
no	O
means	O
an	O
exhaustive	O
list	O
,	O
the	O
following	O
parsers	B-Language
and	O
grammar	O
formalisms	O
employ	O
syntactic	B-Application
predicates	I-Application
:	O
</s>
<s>
As	O
originally	O
implemented	O
,	O
syntactic	B-Application
predicates	I-Application
sit	O
on	O
the	O
leftmost	O
edge	O
of	O
a	O
production	O
such	O
that	O
the	O
production	O
to	O
the	O
right	O
of	O
the	O
predicate	O
is	O
attempted	O
if	O
and	O
only	O
if	O
the	O
syntactic	B-Application
predicate	I-Application
first	O
accepts	O
the	O
next	O
portion	O
of	O
the	O
input	O
stream	O
.	O
</s>
<s>
Although	O
ordered	O
,	O
the	O
predicates	O
are	O
checked	O
first	O
,	O
with	O
parsing	B-Language
of	O
a	O
clause	O
continuing	O
if	O
and	O
only	O
if	O
the	O
predicate	O
is	O
satisfied	O
,	O
and	O
semantic	O
actions	O
only	O
occurring	O
in	O
non-predicates	O
.	O
</s>
<s>
Balmas	O
refers	O
to	O
syntactic	B-Application
predicates	I-Application
as	O
"	O
multi-step	O
matching	O
"	O
in	O
her	O
paper	O
on	O
APM	O
.	O
</s>
<s>
As	O
an	O
APM	O
parser	B-Language
parses	B-Language
,	O
it	O
can	O
bind	O
substrings	O
to	O
a	O
variable	O
,	O
and	O
later	O
check	O
this	O
variable	O
against	O
other	O
rules	O
,	O
continuing	O
to	O
parse	B-Language
if	O
and	O
only	O
if	O
that	O
substring	O
is	O
acceptable	O
to	O
further	O
rules	O
.	O
</s>
<s>
Ford	O
's	O
PEGs	O
have	O
syntactic	B-Application
predicates	I-Application
expressed	O
as	O
the	O
and-predicate	O
and	O
the	O
not-predicate	O
.	O
</s>
<s>
In	O
the	O
§	O
-Calculus	O
,	O
syntactic	B-Application
predicates	I-Application
are	O
originally	O
called	O
simply	O
predicates	O
,	O
but	O
are	O
later	O
divided	O
into	O
bound	O
and	O
free	O
forms	O
,	O
each	O
with	O
different	O
input	O
properties	O
.	O
</s>
<s>
Raku	B-Application
introduces	O
a	O
generalized	O
tool	O
for	O
describing	O
a	O
grammar	O
called	O
rules	O
,	O
which	O
are	O
an	O
extension	O
of	O
Perl	B-Language
5	O
's	O
regular	O
expression	O
syntax	O
.	O
</s>
<s>
Perl	B-Language
5	O
also	O
has	O
such	O
lookahead	O
,	O
but	O
it	O
can	O
only	O
encapsulate	O
Perl	B-Language
5	O
's	O
more	O
limited	O
regexp	O
features	O
.	O
</s>
<s>
ProGrammar	O
's	O
GDL	O
(	O
Grammar	O
Definition	O
Language	O
)	O
makes	O
use	O
of	O
syntactic	B-Application
predicates	I-Application
in	O
a	O
form	O
called	O
parse	B-Language
constraints	O
.	O
</s>
