Re: glib, flex and bison
- From: John Cupitt ng-london org uk
- To: p dirac org
- Cc: gtk-list gnome org
- Subject: Re: glib, flex and bison
- Date: Wed, 2 Jan 2002 14:39:22 -0000
Peter Jay Salzman wrote:
> currently, my code is kind of ugly because i need to convert back and
> forth between standard and glib data types. i'm using flex/bison to
> handle user input (i'm a flex/bison newbie). basically, yytext is put
> into a union depending on the data type:
>
> %union
> {
> int number;
> char *string;
> char character;
> }
>
> %token <number> NUMBER
> %token <character> LETTER
> %token <string> WORD
> %%
> commands:
> | commands command
> ;
> command:
> TOK_SAVE WORD TOK_END { SaveState($2); }
>
>
> it would be sweet beyond belief if i could somehow get bison/yacc to
> pass a GString rather than a char *. this would save me alot of
> "conversion code".
Hi Peter, I think this is pretty easy. You just need to change your
lexer as well. Something like (untested):
Parser:
----------
%union {
...
GString *gstring;
...
}
%type <gstring> TK_IDENTIFIER
%%
command:
TK_IDENTIFIER
{
Symbol *sym = symbol_new( $1 );
}
----------
Lexer:
----------
[a-zA-Z_]*
{
yylval.gstring = g_string_new( yytext );
return( TK_IDENTIFIER );
}
----------
C:
----------
Symbol *
symbol_new( GString *name )
{
.....
}
----------
John
==========================================================
Renaissance Autumn at the National Gallery
A season of exhibitions, displays and events with a Renaissance theme.
Pisanello: Painter to the Renaissance Court (24 October - 13 January 2002)
For information and tickets:
http://www.nationalgallery.org.uk/what/news/ren_autumn.htm
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]