Parsing repetitive tokens across multiple patterns

Archana Deshmukh <desharchana19@gmail.com>
Thu, 15 Jun 2023 06:57:33 -0700

          From comp.compilers

Related articles
Parsing repetitive tokens across multiple patterns desharchana19@gmail.com (Archana Deshmukh) (2023-06-15)
Re: Parsing repetitive tokens across multiple patterns 864-117-4973@kylheku.com (Kaz Kylheku) (2023-06-16)
| List of all articles for this month |
From: Archana Deshmukh <desharchana19@gmail.com>
Newsgroups: comp.compilers
Date: Thu, 15 Jun 2023 06:57:33 -0700
Organization: Compilers Central
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

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]


Post a followup to this message

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