Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Maybe Computer Science should be in the College of Theology. -- R. S. Barton


devel / comp.compilers / flex and bison grouping

SubjectAuthor
* flex and bison groupingArchana Deshmukh
`* Re: flex and bison groupingArchana Deshmukh
 `* Re: flex and bison groupinggah4
  `- Re: flex and bison groupingHans-Peter Diettrich

1
flex and bison grouping

<23-05-022@comp.compilers>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=810&group=comp.compilers#810

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: desharchana19@gmail.com (Archana Deshmukh)
Newsgroups: comp.compilers
Subject: flex and bison grouping
Date: Thu, 18 May 2023 22:54:13 -0700 (PDT)
Organization: Compilers Central
Sender: johnl@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-05-022@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="19871"; mail-complaints-to="abuse@iecc.com"
Keywords: lex, yacc, question
Posted-Date: 19 May 2023 15:56:05 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Archana Deshmukh - Fri, 19 May 2023 05:54 UTC

Hello,

I would like to parse following line using bison and flex.

Any help / suggestions are most welcome.

efg @main(%data: r[(1, 2, 4, 4), float32], %param_1: or[(2, 1, 5, 5),
float32], %param_2: or[(20), float32], %param_3: or[(5, 2, 5, 5), float32],
%param_4: or[(50), float32], %param_5: or[(50, 80), float32], %param_6:
Tensor[(50), float32], %param_7: or[(10, 50), float32], %param_8: or[(20),
float32]

Best Regards,
Archana Deshmukh
[This looks very straightforward. The Flex tokens are keywords, numbers,
and punctuation, the bison rules would be a %param or %data expression,
a list of such expressions, and so on. Is there some particular problem
you are encountering? -John
Cheap plug: there's always my book https://amzn.to/3IrtPFS ]

Re: flex and bison grouping

<23-05-032@comp.compilers>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=819&group=comp.compilers#819

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: desharchana19@gmail.com (Archana Deshmukh)
Newsgroups: comp.compilers
Subject: Re: flex and bison grouping
Date: Wed, 24 May 2023 23:20:22 -0700
Organization: Compilers Central
Sender: johnl@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-05-032@comp.compilers>
References: <23-05-022@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="33709"; mail-complaints-to="abuse@iecc.com"
Keywords: lex, yacc, design, comment
Posted-Date: 25 May 2023 08:47:53 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-05-022@comp.compilers>
 by: Archana Deshmukh - Thu, 25 May 2023 06:20 UTC

On Saturday, May 20, 2023 at 1:26:09 AM UTC+5:30, Archana Deshmukh wrote:
> Hello,
>
> I would like to parse following line using bison and flex.
>
> Any help / suggestions are most welcome.
>
> efg @main(%data: r[(1, 2, 4, 4), float32], %param_1: or[(2, 1, 5, 5),
> float32], %param_2: or[(20), float32], %param_3: or[(5, 2, 5, 5), float32],
> %param_4: or[(50), float32], %param_5: or[(50, 80), float32], %param_6:
> Tensor[(50), float32], %param_7: or[(10, 50), float32], %param_8: or[(20),
> float32]
>
> Best Regards,
> Archana Deshmukh
> [This looks very straightforward. The Flex tokens are keywords, numbers,
> and punctuation, the bison rules would be a %param or %data expression,
> a list of such expressions, and so on. Is there some particular problem
> you are encountering? -John
> Cheap plug: there's always my book https://amzn.to/3IrtPFS ]

Thanks John for response.
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.

The flex code has tokens and bison parser code understands these tokens correctly. Now, I need to put these values to list. I think I am missing something here. There is no context in bison code.

Best Regards,
Archana Deshmukh
[If it's not obvious from context what kind of nodes are in the list, add a tag field to the
node that tells you what kind of node it is. For nodes this small it doesn't really
matter, but we often use a union to use the same space for fields that appear in different
kinds of nodes. -John]

Re: flex and bison grouping

<23-05-033@comp.compilers>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=820&group=comp.compilers#820

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: gah4@u.washington.edu (gah4)
Newsgroups: comp.compilers
Subject: Re: flex and bison grouping
Date: Thu, 25 May 2023 17:08:55 -0700
Organization: Compilers Central
Sender: johnl@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-05-033@comp.compilers>
References: <23-05-022@comp.compilers> <23-05-032@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
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
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-05-032@comp.compilers>
 by: gah4 - Fri, 26 May 2023 00:08 UTC

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]

Re: flex and bison grouping

<23-05-034@comp.compilers>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=821&group=comp.compilers#821

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: DrDiettrich1@netscape.net (Hans-Peter Diettrich)
Newsgroups: comp.compilers
Subject: Re: flex and bison grouping
Date: Sat, 27 May 2023 02:08:39 +0200
Organization: Compilers Central
Sender: johnl@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-05-034@comp.compilers>
References: <23-05-022@comp.compilers> <23-05-032@comp.compilers> <23-05-033@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="92898"; mail-complaints-to="abuse@iecc.com"
Keywords: lex, storage
Posted-Date: 27 May 2023 12:34:14 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-05-033@comp.compilers>
 by: Hans-Peter Diettrich - Sat, 27 May 2023 00:08 UTC

On 5/26/23 2:08 AM, gah4 wrote:
> On Thursday, May 25, 2023 at 5:49:39 AM UTC-7, Archana Deshmukh wrote:

>> 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.

In a typical compiler strings go into lists of literals and identifiers
(types, variables, functions...). The string has to be stored (copied)
on the first occurence, later occurences mostly become references to the
already existing entry (depending on scope rules).

> [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]

DoDi

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor