Archana Deshmukh
2023-07-06 09:12:38 UTC
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]
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]