Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9112585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:46:14+00:00 2026-06-17T03:46:14+00:00

I have a lex file port_regex.l that contains the following code. DECIMAL_16bits [ \t]*[:digit:]{1,4}[

  • 0

I have a lex file port_regex.l that contains the following code.

DECIMAL_16bits [ \t]*[:digit:]{1,4}[ \t]*
SPACE [ \t]

%x S_rule S_dst_port

%%

%{
    BEGIN S_rule;
%}

<S_rule>(dst-port){SPACE}   {
           BEGIN(S_dst_port);
        }

<S_dst_port>\{{DECIMAL_16bits}\}  {
       printf("\n\nMATCH [%s]\n\n", yytext);
       BEGIN S_rule;
     }

. { ECHO; }

%%

int main(void)
{
    while (yylex() != 0)
        ;
    return(0);
}

int yywrap(void)
{
    return 1;
}

I create an executable from it as follows.

flex port_regex.l
gcc lex.yy.c -o port_regex

which creates an executable called port_regex.

I have a file that contains test data called port.file which is given below.

dst-port {234}
dst-port {236}
dst-port {233}
dst-port {2656}

How do I test the port.file using port_regex executable.

can I do something like

./port_regex < port.file

I tried the above and it doesn’t seem to work??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:46:15+00:00Added an answer on June 17, 2026 at 3:46 am

    So long as your application doesn’t become a lot more complex, I think using start conditions is a good way to go, instead of introducing a yacc-generated parser.

    A couple of thoughts:

    The examples I see sometimes use parentheses with BEGIN (BEGIN(comment)) and sometimes not (BEGIN comment). I doubt that it makes any difference, but you should be consistent.

    The book says that the default rule to echo unmatched characters is still in effect, even under exclusive start conditions, so you shouldn’t need

    . { ECHO; }
    

    and since your start conditions are exclusive, it wouldn’t fire anyway. Just to make sure, you might rewrite it as

    <*>.|\n     ECHO;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my tokenizer (.lex) file I want to match the following pattern : AaBC12/awD41/dfs21
I'm trying to write generic code that can lex any stream of characters (
i would like to use the code generated by lex in another code that
I have a lex pattern file (test.l) where I want to recognize a pattern
I have created a lex file test.l and create lex.yy.c from it, which I
I have a lex pattern file (test.l) where I want to recognize a pattern
I have a C header file that I have precompiled using the gcc -E
I have an experimental flex source file(lex.l): %option noyywrap %{ int chars = 0;
I have a relatively simple lex/flex file and have been running it with flex's
I have a simple code in lex language and i generate lex.yy.c with Flex.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.