Re: Problem with Flex/Bison and C/C++



Christoph asked:
So my question is if there is a simple way to have all the tokens as
strings and integers and have nonterminals with more complicated C++
data types.

Yes, put only pointers in your union. You can then use a "void *" (or
char *) pointer in your lexer and that will work in C. There are
other reasons why using only pointers in your union is a good
solution. However, let me just say that your union is to help hook you
resulting AST together, and as such you want to have a pointer to the
object being linked and not a copy of the object being linked.

There are also versions of "lex" that generate C++. I would recommend
finding one of them for the long run.

Hope this helps,
-Chris

*****************************************************************************
Chris Clark Internet : compres@xxxxxxxxxxxxx
Compiler Resources, Inc. Web Site : http://world.std.com/~compres
23 Bailey Rd voice : (508) 435-5016
Berlin, MA 01503 USA fax : (978) 838-0263 (24 hours)
------------------------------------------------------------------------------

.



Relevant Pages

  • Re: void *
    ... I want to adapt my linked list implementation to hold any data types. ... understand it's a good place to use 'void *'. ... struct list_node *next; ... it guarantees that you can supply pointers to the various data ...
    (comp.lang.c)
  • Re: Floats to chars and chars to floats
    ... >>The size of the union may be larger than the size of the float. ... No, padding can be put in for any reason, though it must preserve ... but realise that all union pointers ...
    (comp.lang.c)
  • Re: C examples and codes
    ... I don't know what you're talking about, but it's not standard ... Pointers are pointers. ... "1.13.10 union. ... You can store several values in a single memory location or a group ...
    (comp.lang.c)
  • Re: can this be achieved
    ... The standard version of strcmp expects pointers ... the union is currently in use. ... separate namespace, called "function". ...
    (comp.lang.cpp)
  • Re: [PATCH 2/3] fsstack: Generic get/set lower object functions
    ... The reason for the union is simple... ... I think the query was more about why you'd need a struct which contains only ... if you have a fanout stackable filesystem, your objects ... Since we don't want to hurt linear stacks by declaring arrays of pointers, ...
    (Linux-Kernel)