Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Today is the first day of the rest of your lossage.


devel / comp.compilers / Parsing repetitive tokens across multiple patterns

SubjectAuthor
* Parsing repetitive tokens across multiple patternsArchana Deshmukh
`- Re: Parsing repetitive tokens across multiple patternsKaz Kylheku

1
Parsing repetitive tokens across multiple patterns

<23-06-003@comp.compilers>

  copy mid

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

  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: Parsing repetitive tokens across multiple patterns
Date: Thu, 15 Jun 2023 06:57:33 -0700
Organization: Compilers Central
Sender: johnl@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-06-003@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="75614"; mail-complaints-to="abuse@iecc.com"
Keywords: parse, question, comment
Posted-Date: 15 Jun 2023 16:48:49 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 - Thu, 15 Jun 2023 13:57 UTC

I need to parse following patterns using bison and flex and retrieve the data and store to list.
There are total 9 patterns, so there will 9 lists to store the corresponding values. I am able to parse all patterns.
However, I need to add lots of flags as tokens are repetitive and used across patterns.
Also within patterns same token is repeated multiple times. I think there can be a better way to do this.

e.g. for token INTEGER, the code in bison parser file is

INTEGER:
if(pattern1)
{ if(flag1)
{
}
if(flag2)
{
}
.
.
.
}

if(flag3)
{

}

if(pattern2)
{

}

Sample Pattern
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]

Code:

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]

{
Pattern1
Pattern2
Pattern3
Pattern1
Pattern2
Pattern3
Pattern4
Pattern5
Pattern2
Pattern8
Pattern4
Pattern5
Pattern6
Pattern7
}

Pattern1 to Pattern8 are similar to Sample Pattern.
Any suggestions are welcome.

Best Regards,
Archana Deshmukh
[My inclination would be to write one set of productions that can match any of the
patterns and use code in the actions to check that it matches the specific pattern
needed. The action code can always call yyerror() to say there's a syntax error.
-John]

Re: Parsing repetitive tokens across multiple patterns

<23-06-005@comp.compilers>

  copy mid

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

  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: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.compilers
Subject: Re: Parsing repetitive tokens across multiple patterns
Date: Fri, 16 Jun 2023 00:31:40 -0000
Organization: Compilers Central
Sender: johnl@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-06-005@comp.compilers>
References: <23-06-003@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="84439"; mail-complaints-to="abuse@iecc.com"
Keywords: parse, design
Posted-Date: 15 Jun 2023 22:31:43 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Kaz Kylheku - Fri, 16 Jun 2023 00:31 UTC

On 2023-06-15, Archana Deshmukh <desharchana19@gmail.com> wrote:
> I need to parse following patterns using bison and flex and retrieve the data and store to list.
> There are total 9 patterns, so there will 9 lists to store the corresponding values. I am able to parse all patterns.
> However, I need to add lots of flags as tokens are repetitive and used across patterns.
> Also within patterns same token is repeated multiple times. I think there can be a better way to do this.

Your descriptions do not constitute a coherent problem statement.

What are the inputs to your system, and the corresponding, expected outputs?

What is the smallest input set? Next smallest? Corner cases?

Tokens are often repeated in programming and data languages. Why do you
believe this is significant in your problem?

> e.g. for token INTEGER, the code in bison parser file is
>
> INTEGER:
> if(pattern1)
> {
> if(flag1)
> {
> }
> if(flag2)
> {
> }
> .
> .
> .
> }

What does this mean? We are in the middle of parsing a pattern pattern,
and we already know which one due to earlier parsing actions, such that
the pattern1 variable (and others) inform us?

And so then when an INTEGER occurs and has to be treated differently
based on which pattern? Why and how?

There can be reasons to treat tokens in a context-sensitive way.
Usually that happens when there are multiple sub-languages integrated
into one language.

Your different patterns don't look like a different language;
why would a token like 5 have to be treated differently based
on which one of 9 similar patterns it occurs in.

I sense an X/Y problem here. The real problem being solved is some Y
that you have not revealed, and you have invested in some chosen
approach X that you're trying to debug into working, and asking
questions about. There may be a better way, but that way may be a
complete replacement for X to solve the Y.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor