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 616681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:21:11+00:00 2026-05-13T18:21:11+00:00

I have a relatively simple lex/flex file and have been running it with flex’s

  • 0

I have a relatively simple lex/flex file and have been running it with flex’s debug flag to make sure it’s tokenizing properly. Unfortunately, I’m always running into one of two problems – either the program the flex generates stops just gives up silently after a couple of tokens, or the rule I’m using to recognize characters and strings isn’t called and the default rule is called instead.

Can someone point me in the right direction? I’ve attached my flex file and sample input / output.

Edit: I’ve found that the generated lexer stops after a specific rule: “cdr”. This is more detailed, but also much more confusing. I’ve posted a shorted modified lex file.

/* lex file*/
%option noyywrap
%option nodefault

%{
       enum tokens{
                CDR,
                CHARACTER,
                SET
        };
%}

%%

"cdr"                                               { return CDR; }
"set"                                               { return SET; }

[ \t\r\n]                                           /*Nothing*/
[a-zA-Z0-9\\!@#$%^&*()\-_+=~`:;"'?<>,\.]      { return CHARACTER; }

%%

Sample input:

set c cdra + cdr b + () ;

Complete output from running the input through the generated parser:

--(end of buffer or a NUL)
--accepting rule at line 16 ("set")
--accepting rule at line 18 (" ")
--accepting rule at line 19 ("c")
--accepting rule at line 18 (" ")
--accepting rule at line 15 ("cdr")

Any thoughts? The generated program is giving up after half of the input! (for reference, I’m doing input by redirecting the contents of a file to the generated program).

  • 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-05-13T18:21:11+00:00Added an answer on May 13, 2026 at 6:21 pm

    When generating a lexer that’s standalone (that is, not one with tokens that are defined in bison/yacc, you typically write an enum at the top of the file defining your tokens. However, the main loop of a lex program, including the main loop generated by default, looks something like this:

    while( token = yylex() ){
        ...
    

    This is fine, until your lexer matches the rule that appears first in the enum – in this specific case CDR. Since enums by default start at zero, this causes the while loop to end. Renumbering your enum – will solve the issue.

    enum tokens{
                CDR = 1,
                CHARACTER,
                SET
        };
    

    Short version: when defining tokens by hand for a lexer, start with 1 not 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively simple question. Say I have a file but I only
I have a relatively simple site that I'm working up for an intranet environment.
We have are relatively simple Reporting Services report that our users commonly export to
I have a relatively simple form which asks a variety of questions. One of
I have a relatively simple select statement in a VB6 program that I have
I'm relatively new to the Component Object Model specification - I have a simple
I have a relatively complex .htaccess file to control page requests, this currently redirects
I have a relatively simple Continuous Form. There is an invisible Check Box, let's
I have a relatively simple Lucene index, being served by Solr. The index consists
I have a relatively simple design that is puzzling me. It has 4 large

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.