flex icon indicating copy to clipboard operation
flex copied to clipboard

Use variable in flex rules section

Open sahil-ecosmob opened this issue 2 years ago • 1 comments

Hello Everyone. I am new to lexical analysis and flex. I am able to create a generator executable. Now I want to search for a specific string inside the source file that is being analysed. For example "func_test". I want to pass this string as a command line argument to the a.out file like $ ./a.out func_test and then use this string inside the rules section so that it is detected and I can take appropriate action. Can anyone help me on how to do it ?? Thanks in advance.

sahil-ecosmob avatar Jul 14 '22 05:07 sahil-ecosmob

If I understand correctly, you want to search for a string provided at runtime in the text of each token.

Your .l input's rules and actions are compiled into a.out before runtime so you can't change them at all.

However, your scanner returns each token it finds to the caller of yylex. You can get the token's text in yytext and compare it to the runtime argument before calling yylex again. Take a look at examples/manual/expr.lex to see the token return actions.

On Thu, Jul 14, 2022, 01:10 sahil-ecosmob @.***> wrote:

Hello Everyone. I am new to lexical analysis and flex. I am able to create a generator executable. Now I want to search for a specific string inside the source file that is being analysed. For example "func_test". I want to pass this string as a command line argument to the a.out file like $ ./a.out func_test and then use this string inside the rules section so that it is detected and I can take appropriate action. Can anyone help me on how to do it ?? Thanks in advance.

— Reply to this email directly, view it on GitHub https://github.com/westes/flex/issues/533, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVJXINSVLGG2W75G6TDTMLVT6OLDANCNFSM53Q5XJ2A . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Mightyjo avatar Jul 15 '22 14:07 Mightyjo