Groups | Search | Server Info | Login | Register


Groups > comp.compilers > #3492

Parsing repetitive tokens across multiple patterns

From Archana Deshmukh <desharchana19@gmail.com>
Newsgroups comp.compilers
Subject Parsing repetitive tokens across multiple patterns
Date 2023-06-15 06:57 -0700
Organization Compilers Central
Message-ID <23-06-003@comp.compilers> (permalink)

Show all headers | View raw


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]

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


Thread

Parsing repetitive tokens across multiple patterns Archana Deshmukh <desharchana19@gmail.com> - 2023-06-15 06:57 -0700
  Re: Parsing repetitive tokens across multiple patterns Kaz Kylheku <864-117-4973@kylheku.com> - 2023-06-16 00:31 +0000

csiph-web