help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reentrant Parser


From: Akim Demaille
Subject: Re: Reentrant Parser
Date: Sat, 01 Mar 2003 13:42:14 +0100
User-agent: Gnus/5.090015 (Oort Gnus v0.15) Emacs/21.2

Please, see this piece of hidden documentation.

@ifset documentparam
If you use a reentrant parser, you can optionally pass additional
parameter information to it in a reentrant way.  To do so, use the
declaration @code{%parse-param}:

@deffn {Directive} %parse-param @address@hidden@}
@findex %parse-param
Declare that an argument declared by @code{argument-declaration} is an
additional @code{yyparse} argument.
The @var{argument-declaration} is used when declaring
functions or prototypes.  The last identifier in
@var{argument-declaration} must be the argument name.
@end deffn

Here's an example.  Write this in the parser:

@example
%parse-param @{int address@hidden
%parse-param @{int address@hidden
@end example

@noindent
Then call the parser like this:

@example
@{
  int nastiness, randomness;
  @dots{}  /* @r{Store proper data in @code{nastiness} and @code{randomness}.}  
*/
  value = yyparse (&nastiness, &randomness);
  @dots{}
@}
@end example

@noindent
In the grammar actions, use expressions like this to refer to the data:

@example
exp: @dots{}    @{ @dots{}; *randomness += 1; @dots{} @}
@end example
@end ifset


If you wish to pass the additional parameter data to @code{yylex}, use
@code{%lex-param} just like @code{%parse-param} (@pxref{Parser
Function}).

@deffn {Directive} lex-param @address@hidden@}
@findex %lex-param
Declare that @code{argument-declaration} is an additional @code{yylex}
argument declaration.
@end deffn

For instance:

@example
%parse-param @{int address@hidden
%lex-param   @{int address@hidden
%parse-param @{int address@hidden
@end example

@noindent
results in the following signature:

@example
int yylex   (int *nastiness);
int yyparse (int *nastiness, int *randomness);
@end example

If @code{%pure-parser} is added:

@example
int yylex   (YYSTYPE *lvalp, int *nastiness);
int yyparse (int *nastiness, int *randomness);
@end example

@noindent
and finally, if both @code{%pure-parser} and @code{%locations} are used:

@example
int yylex   (YYSTYPE *lvalp, YYLTYPE *llocp, int *nastiness);
int yyparse (int *nastiness, int *randomness);
@end example




reply via email to

[Prev in Thread] Current Thread [Next in Thread]