Re: flex and bison grouping

gah4 <gah4@u.washington.edu>
Thu, 25 May 2023 17:08:55 -0700

          From comp.compilers

Related articles
flex and bison grouping desharchana19@gmail.com (Archana Deshmukh) (2023-05-18)
Re: flex and bison grouping desharchana19@gmail.com (Archana Deshmukh) (2023-05-24)
Re: flex and bison grouping gah4@u.washington.edu (gah4) (2023-05-25)
Re: flex and bison grouping DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2023-05-27)
| List of all articles for this month |
From: gah4 <gah4@u.washington.edu>
Newsgroups: comp.compilers
Date: Thu, 25 May 2023 17:08:55 -0700
Organization: Compilers Central
References: 23-05-022 23-05-032
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="24916"; mail-complaints-to="abuse@iecc.com"
Keywords: lex, debug, comment
Posted-Date: 25 May 2023 20:39:43 EDT
In-Reply-To: 23-05-032

On Thursday, May 25, 2023 at 5:49:39 AM UTC-7, Archana Deshmukh wrote:


(snip)


> I am able to write flex tokens and bison parser and able to retrieve tokens
> and values. Now, I want to put these values to a list. I implemented with C linked list
> with simple structure
> struct node{
> char* name;
> int dimensions[4];
> char* type;
> struct node *next;
> };
> I am able to populate the list for "name" parameter. The type is also of type char*.
> How, I can differentiate between parameter "char* name" or "char* type" when I populate list.


One that you have to be careful about with C in general, and I suspect in this case,
is that you might have a pointer to some buffer that is reused. Saving the pointer
returned by flex might not help. (I suspect John will tell me if this is wrong.)


You often need to allocate new space, and make a copy to save.
[You are right -- you need to make a copy of the yytext string in a
flex action if you want to keep it. Otherwise it'll be overwritten the
next time the lexer reads a block of input text. This is a very common
bug. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.