Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #3498

bison parser : retrieving values from recursive pattern

From Archana Deshmukh <desharchana19@gmail.com>
Newsgroups comp.compilers
Subject bison parser : retrieving values from recursive pattern
Date 2023-07-06 02:12 -0700
Organization Compilers Central
Message-ID <23-07-001@comp.compilers> (permalink)

Show all headers | View raw


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]

Back to comp.compilers | Previous | NextNext in thread | Find similar


Thread

bison parser : retrieving values from recursive pattern Archana Deshmukh <desharchana19@gmail.com> - 2023-07-06 02:12 -0700
  Re: bison parser : retrieving values from recursive pattern Kaz Kylheku <864-117-4973@kylheku.com> - 2023-07-07 01:14 +0000

csiph-web