help-bison
[Top][All Lists]
Advanced

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

Re: Return from recursive processing is incomplete


From: Evan Carew
Subject: Re: Return from recursive processing is incomplete
Date: Mon, 07 Sep 2009 11:43:16 -0400
User-agent: Mozilla Thunderbird 1.0.8-1.1.fc4 (X11/20060501)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Phil,

Thanks for the assist. I have a feeling that this will allow me to
continue my research with bison.

Philip Herron wrote:

> Took me a few times to read your mail to see what you meant :P. So let
> me know if i am wrong i but, you want to understand a way of
> representing syntax like:
>
> enum foo { bla, bla, bla, bla };
>
> So take a look at your toplevel for an enum:
>
> enum_specifier: ENUM '{' enumerator_list '}'
>
> enumerator_list
> : enumerator
> | enumerator_list ',' enumerator
> ;
>
> enumerator
> : IDENTIFIER
> | IDENTIFIER '=' constant_expression
> ;
>
> This looks fine its a standard way of expressing lists, but you have
> to think about how should each rule represent what you want? You said
> " what I get back is [enum blah {one };]"
>
> What i would do for now is to be very basic for keep a sanity check :)
> So only return char* for enumerator:
>
> %type<string> enumerator
>
> So an enumerator rule would be simply:
>
> enumerator : IDENTIFIER
> {
> $$= $1;
> }
>
> Then it gets a little more fiddly you have to think how do you handle
> a list and could be n length? In a language i have a list does this:
>
> list_type: '{' item_list '}'
> {
> $$= tmp_table;
> tmp_table= NULL;
> }
> ;
>
> item_list: item_list ',' item
> {
> if( tmp_table )
> append_element( $3, &tmp_table );
> else
> fatal("NULL list table in list construction!\n");
> }
> | item
> {
> if( tmp_table )
> append_element( $1, &tmp_table );
> else
> {
> tmp_table= (struct hash_table*)
> xmalloc(sizeof(struct hash_table));
>
> init_hash_table( tmp_table );
> append_element( $1, &tmp_table );
> }
> }
> ;
>
> What i have is a tmp_table which is a hash table and i just keep
> appending to that structure and my list is a hash_table but this
> affects what is an item.
>
> item: IDENTIFIER
> {
> struct symtab *sym= (struct symtab*)
> xmalloc(sizeof(struct symtab));
>
> ....
> $$= sym;
> }
> | INTEGER
> {
> struct symtab *sym= (struct symtab*)
> xmalloc(sizeof(struct symtab));
>
> ...
> }
> | DOUBLE
> {
> ....
> }
>
> //.....
>
> Thats quick extract, everything is a symbol in my language a little
> like python everything is a python object and so i just append symbols
> to a table. This is a very linear way but its ok because i dont accept
> lists defined inside lists but you can have another variable that is a
> list and just add that item into a new list so its a list of lists.
>
> This is one way of doing it you could keep a stack or something and
> return that or list. You could have an array of buffers or something
> it depends how you want it to work.
>
> You just have to think if i had this is 'a' structure what would it do
> and why and how would it work then maybe you might find what you need
> to do. Remember bison will simply parses the tokens but you have to
> act on the rules in a way thats useful for you.
>
> --Phil


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFKpSoUpxCQXwV2bJARAhxbAJ9+i52w/+lrHsAchHGD0RW/baTH0gCgmNpJ
kRtmxC3ijPN4PT8gWgVHgfc=
=jdBm
-----END PGP SIGNATURE-----





reply via email to

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