bison parser : retrieving values from recursive pattern

Archana Deshmukh <>
Thu, 06 Jul 2023 02:12:38 -0700

          From comp.compilers

Related articles
bison parser : retrieving values from recursive pattern (Archana Deshmukh) (2023-07-06)
Re: bison parser : retrieving values from recursive pattern (Kaz Kylheku) (2023-07-07)
| List of all articles for this month |

From: Archana Deshmukh <>
Newsgroups: comp.compilers
Date: Thu, 06 Jul 2023 02:12:38 -0700
Organization: Compilers Central
Injection-Info:; posting-host=""; logging-data="57725"; mail-complaints-to=""
Keywords: parse, yacc, comment
Posted-Date: 06 Jul 2023 16:08:55 EDT


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]

Post a followup to this message

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