bug-bison
[Top][All Lists]
Advanced

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

Re: bison-2.7 and MacOS 10.13


From: Akim Demaille
Subject: Re: bison-2.7 and MacOS 10.13
Date: Sat, 8 Sep 2018 09:28:47 +0200


> Le 7 sept. 2018 à 14:29, David Barto <address@hidden> a écrit :
> 
> Our code is very very old and doesn’t support the newer non - YYPARSE defined 
> version of bison.

I guess you mean YYPARSE_PARAM here?

It should not be too hard to migrate.


Previously, suppose you wanted to pass some struct named
parser_control.  You needed to define the type, and define the macro
YYPARSE_PARAM:

> %{
>   struct parser_control
>   {
>     int nastiness;
>     int randomness;
>   };
>   
>   #define YYPARSE_PARAM pcontrol
> %}

In your grammar actions, you had to cast to use the parse param
something like:

> exp: "number"
> {
>   $$ = $1 + ((struct parser_control *) pcontrol)->randomness;
> }

and call your parser this way:

> {
>   struct parser_control foo;
>   ...  /* Store proper data in foo.  */
>   res = yyparse ((void *) &foo);
>   ...
> }

To migrate to newer versions of Bison (perfectly valid with 2.7!):

> %{
>   struct parser_control
>   {
>     int nastiness;
>     int randomness;
>   };
> %}
> %parse-param {parser_control* pcontrol}

In your actions:

> exp: "number"
> {
>   $$ = $1 + pcontrol->randomness;
> }

and call your parser this way:

> {
>   struct parser_control foo;
>   ...  /* Store proper data in foo.  */
>   res = yyparse (&foo);
>   ...
> }

No more casts, not more limitations to a single param.

Does this help?




reply via email to

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