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

  • Home
  • SEARCH
  • 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 7847811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:00:35+00:00 2026-06-02T18:00:35+00:00

How do I customize the default action for flex. I found something like <*>

  • 0

How do I customize the default action for flex. I found something like <*> but when I run it it says “flex scanner jammed”? Also the . rule only adds a rule so it does not work either. What I want is

comment               "/*"[^"*/"]*"*/"

%%
{comment}             return 1;
{default}             return 0; 
<<EOF>>               return -1;

Is it possible to change the behavior of matching longest to match first? If so I would do something like this

default               (.|\n)*

but because this almost always gives a longer match it will hide the comment rule.

EDIT

I found the {-} operator in the manual, however this example straight from the manual gives me “unrecogized rule”:

[a-c]{-}[b-z]

  • 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-02T18:00:36+00:00Added an answer on June 2, 2026 at 6:00 pm

    The flex default rule matches a single character and prints it on standard output. If you don’t want that action, write an explicit rule which matches a single character and does something else.

    The pattern (.|\n)* matches the entire input file as a single token, so that is a very bad idea. You’re thinking that the default should be a long match, but in fact you want that to be as short as possible (but not empty).

    The purpose of the default rule is to do something when there is no match for any of the tokens in the input language. When lex is used for tokenizing a language, such a situation is almost always erroneous because it means that the input begins with a character which is not the start of any valid token of the language.

    Thus, a “catch any character” rule is coded as a form of error recovery. The idea is to discard the bad character (just one) and try tokenizing from the character after that one. This is only a guess, but it’s a good guess because it’s based on what is known: namely that there is one bad character in the input.

    The recovery rule can be wrong. For instance suppose that no token of the language begins with @, and the programmer wanted to write the string literal "@abc". Only, she forgot the opening " and wrote @abc". The right fix is to insert the missing ", not to discard the @. But that would require a much more clever set of rules in the lexer.

    Anyway, usually when discarding a bad character, you want to issue an error message for this case like “skipping invalid character ‘~` in line 42, column 3”.

    The default rule/action of copying the unmatched character to standard output is useful when lex is used for text filtering. The default rule then brings about the semantics of a regex search (as opposed to a regex match): the idea is to search the input for matches of the lexer’s token-recognizing state machine, while printing all material that is skipped by that search.

    So for instance, a lex specification containing just the rule:

     "foo" { printf("bar"); }
    

    will implement the equivalent of

     sed -e 's/foo/bar/g'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I customize the softkeyboard, but when we run it on emulator then it run
I need to customize the default roles as I need only 3 roles -
Is there a way to customize the default message for an invalid rule in
I would like to find a way to customize the default error html <div
By default, eclipse only puts items in the toolbar I never use. With customize
Does any one have tried to customize default section index displayed in UITableView. I
In Firefox, we can customize the default values for HTTP headers, let's say for
I want to customize a .NET build process so that I can run an
What's the easiest solution to customize default buttons in the web pages ? I
I am wondering if it is possible to customize the default InfoWindow that pops

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.