Advertisement
Guest User

Untitled

a guest
Aug 5th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. Have you experienced the %variant mode in Bison development version? It works well, and avoids this nasty POD issue. Have a look at http://www.lrde.epita.fr/~akim/download/bison-2.4.570-7a582.tar.bz2. Look for variant in the documentation. The following example shows what you can do. I need to polish and publish this :( Help would be most welcome.
  2.  
  3. %type <::std::string> item;
  4. %type <::std::list<std::string>> list;
  5.  
  6. %%
  7.  
  8. result:
  9. list { std::cout << $1 << std::endl; }
  10. ;
  11.  
  12. list:
  13. /* nothing */ { /* Generates an empty string list */ }
  14. | list item { std::swap ($$, $1); $$.push_back ($2); }
  15. ;
  16.  
  17. item:
  18. TEXT { std::swap ($$, $1); }
  19. | NUMBER { $$ = string_cast ($1); }
  20. ;
  21. %%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement