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: bison parser : retrieving values from recursive pattern Date: Thu, 06 Jul 2023 02:12:38 -0700 Organization: Compilers Central Sender: johnl@iecc.com Approved: comp.compilers@iecc.com Message-ID: <23-07-001@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="57725"; mail-complaints-to="abuse@iecc.com" Keywords: parse, yacc, comment Posted-Date: 06 Jul 2023 16:08:55 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:3498 Hello, I have a following rule num : | integer comma num | integer closeroundbkt | integer closesquarebkt I need to parse data like 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] I also need to retrieve these values and store to a lsit. Retreiving and storing values for patterns like | integer closeroundbkt | integer closesquarebkt is simple. However, I am not able to find a way to retrieve and store recursive numbers from pattern | integer comma num Sometimes there can be 2 numbers (50, 80), sometimes there can be 4 numbers ((1, 2, 4, 4)). How to handle this? Any suggestions are welcome. Best Regards, Archana Deshmukh [For a list of numbers in parens I would do something like this: parennumlist: '(' numlist ')' ; numlist: integer | numlist ',' integer ; For the bracketed lists: bracketlist: '[' parennumlist ',' datatype ']': datatype: FLOAT32 | ... whatever other types there are ... ; The usual way you do a variable length list is to make a recursive rule with one item for a single item and another rule to add an item. Any book about compiler design should give advice on writing grammar rules or my "flex & bison" has example grammars that include lists. -John]