Hello,
I would like to parse following line using bison and flex.
Any help / suggestions are most welcome.
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]
Best Regards,
Archana Deshmukh
[This looks very straightforward. The Flex tokens are keywords, numbers,
and punctuation, the bison rules would be a %param or %data expression,
a list of such expressions, and so on. Is there some particular problem
you are encountering? -John
Cheap plug: there's always my book https://amzn.to/3IrtPFS ]
I am able to write flex tokens and bison parser and able to retrieve tokens
and values. Now, I want to put these values to a list. I implemented with C linked list
with simple structure
struct node{
char* name;
int dimensions[4];
char* type;
struct node *next;
};
I am able to populate the list for "name" parameter. The type is also of type char*.
How, I can differentiate between parameter "char* name" or "char* type" when I populate list.
On Thursday, May 25, 2023 at 5:49:39 AM UTC-7, Archana Deshmukh wrote:
I am able to populate the list for "name" parameter. The type is also of type char*.
How, I can differentiate between parameter "char* name" or "char* type" when I populate list.
One that you have to be careful about with C in general, and I suspect in this case,
is that you might have a pointer to some buffer that is reused. Saving the pointer
returned by flex might not help. (I suspect John will tell me if this is wrong.)
You often need to allocate new space, and make a copy to save.
[You are right -- you need to make a copy of the yytext string in a
flex action if you want to keep it. Otherwise it'll be overwritten the
next time the lexer reads a block of input text. This is a very common
bug. -John]
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 65:10:50 |
Calls: | 6,712 |
Files: | 12,244 |
Messages: | 5,356,203 |