• Parsing repetitive tokens across multiple patterns

    From Archana Deshmukh@21:1/5 to All on Thu Jun 15 06:57:33 2023
    I need to parse following patterns using bison and flex and retrieve the data and store to list.
    There are total 9 patterns, so there will 9 lists to store the corresponding values. I am able to parse all patterns.
    However, I need to add lots of flags as tokens are repetitive and used across patterns.
    Also within patterns same token is repeated multiple times. I think there can be a better way to do this.


    e.g. for token INTEGER, the code in bison parser file is

    INTEGER:
    if(pattern1)
    {
    if(flag1)
    {
    }
    if(flag2)
    {
    }
    .
    .
    .
    }

    if(flag3)
    {

    }

    if(pattern2)
    {

    }

    Sample Pattern
    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]

    Code:

    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]

    {
    Pattern1
    Pattern2
    Pattern3
    Pattern1
    Pattern2
    Pattern3
    Pattern4
    Pattern5
    Pattern2
    Pattern8
    Pattern4
    Pattern5
    Pattern6
    Pattern7
    }

    Pattern1 to Pattern8 are similar to Sample Pattern.
    Any suggestions are welcome.

    Best Regards,
    Archana Deshmukh
    [My inclination would be to write one set of productions that can match any of the
    patterns and use code in the actions to check that it matches the specific pattern
    needed. The action code can always call yyerror() to say there's a syntax error.
    -John]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Archana Deshmukh on Fri Jun 16 00:31:40 2023
    On 2023-06-15, Archana Deshmukh <desharchana19@gmail.com> wrote:
    I need to parse following patterns using bison and flex and retrieve the data and store to list.
    There are total 9 patterns, so there will 9 lists to store the corresponding values. I am able to parse all patterns.
    However, I need to add lots of flags as tokens are repetitive and used across patterns.
    Also within patterns same token is repeated multiple times. I think there can be a better way to do this.

    Your descriptions do not constitute a coherent problem statement.

    What are the inputs to your system, and the corresponding, expected outputs?

    What is the smallest input set? Next smallest? Corner cases?

    Tokens are often repeated in programming and data languages. Why do you
    believe this is significant in your problem?

    e.g. for token INTEGER, the code in bison parser file is

    INTEGER:
    if(pattern1)
    {
    if(flag1)
    {
    }
    if(flag2)
    {
    }
    .
    .
    .
    }

    What does this mean? We are in the middle of parsing a pattern pattern,
    and we already know which one due to earlier parsing actions, such that
    the pattern1 variable (and others) inform us?

    And so then when an INTEGER occurs and has to be treated differently
    based on which pattern? Why and how?

    There can be reasons to treat tokens in a context-sensitive way.
    Usually that happens when there are multiple sub-languages integrated
    into one language.

    Your different patterns don't look like a different language;
    why would a token like 5 have to be treated differently based
    on which one of 9 similar patterns it occurs in.

    I sense an X/Y problem here. The real problem being solved is some Y
    that you have not revealed, and you have invested in some chosen
    approach X that you're trying to debug into working, and asking
    questions about. There may be a better way, but that way may be a
    complete replacement for X to solve the Y.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)