bison-patches
[Top][All Lists]
Advanced

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

Re: returning a symbol


From: Joel E. Denny
Subject: Re: returning a symbol
Date: Wed, 12 Jul 2006 15:58:02 -0400 (EDT)

On Wed, 12 Jul 2006, Akim Demaille wrote:

> >>> "Joel" == Joel E Denny <address@hidden> writes:
> 
>  > In order to strongly type the token-value parameter in languages like C, 
>  > maybe we should create a family of functions something like:
> 
>  >   return yy_symbol_BRACED_CODE (token-value, token-location);
>  >   return yy_symbol_INT (token-value, token-location);
> 
> That's another possibility, agreed.

As a macro, I guess the single yy_symbol would have a switch on 
token-value?  If so, the family of yy_symbol_TOKEN_NAME macros could 
reduce the size of the code generated by cpp.  I vaguely recall that it 
matters to some users.

>  > Then again, maybe I'm misunderstanding.  Are you thinking yy_symbol
>  > is a function that returns a struct/class containing the three
>  > parameters (type, value, and location)?  That's what I was
>  > thinking.
> 
> I was thinking about a (shame on me) macro to do that.  I don't know
> how to do that with functions.

The function approach would have to change the interface of yylex.  For 
this reason, I suppose macros would be the path of least resistance.  
However, since %type would be a new feature, maybe it's ok to change yylex 
when %type is used?

  typedef struct yytoken {
    yytokentype token_type;
    YYSTYPE value;
    YYLTYPE location;
  } yytoken;

  yytoken yylex (void);

  yytoken
  yy_symbol_INT (int value, YYLTYPE location)
  {
    Token token;
    token.token_type = INT;
    token.value.integer = value;
    token.location = location;
    return token;
  }

  yytoken
  yy_symbol_BRACED_CODE (const char *value, YYLTYPE location)
  {
    Token token;
    token.token_type = BRACED_CODE;
    token.value.string = value;
    token.location = location;
    return token;
  }

I'm not sure how much better that is.

Joel




reply via email to

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