Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: 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 Xref: csiph.com comp.compilers:3492 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]