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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:15:40+00:00 2026-05-17T02:15:40+00:00

I have a generated scanner from flex which the output from is not consumed

  • 0

I have a generated scanner from flex which the output from is not consumed by yacc or bison. yylex() needs to returns a pointer to a token-like structure memory instead of an int indicating the token-type.

// example definition from foo.l
[A-Za-z_][A-Za-z0-9_]* { return scanner_token(T_IDENTIFIER); }

// example implementation of scanner_token
token *scanner_token(name) {
    token *t = (token *)calloc(1, sizeof(token));
    t->name = name;
    t->lexeme = (char *)calloc(yyleng + 1, 1);
    if (t->lexeme == NULL) {
        perror_exit("calloc");
    }
    memmove(t->lexeme, yytext, yyleng);
    return t;
}

// example invocation of yylex
token *t;
t = (token *)yylex();

Of course, the compilation warns me return makes integer from pointer without a cast.

I read in the flex man pages that YY_DECL controls how the scanning routine is declared:

YY_DECL controls how the scanning
routine is declared. By default, it
is “int yylex()“, or, if
prototypes are being used, “int
yylex(void)
“. This definition may be
changed by redefining the “YY_DECL”
macro.

When I try re-defining YY_DECL, the resulting C file fails to compile.

#undef YY_DECL
#define YY_DECL (token *)yylex()

What is the proper way to accomplish what I am trying to?

  • 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-17T02:15:41+00:00Added an answer on May 17, 2026 at 2:15 am

    The normal syntax would be:

    #define YY_DECL token *yylex(void)
    

    This minimal Flex source file shows how:

    %{
    typedef struct token { int tok; } token;
    #define YY_DECL token *yylex(void)
    token t;
    %}
    %%
    . { t.tok = 1; return &t; }
    %%
    

    It compiles for me.

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

Sidebar

Related Questions

I have generated an excel file from xml. But i can not open it
I have generated using openssl mycert.pem which contents the certificate. And I converted the
I have used the same way of Zxing Intent to open scanner from my
I have generated XAML file from Windows Forms, and with the process calculated right
I have generated JPG image, saved to Documents folder, that not comes with bundle.
I have generated a class from a schema via the xsd.exe tool Now when
I have a project for school where we need to use flex and bison.
I'm using Bison and Flex to make a reentrant scanner/parser pair but can't wrap
i have generated a Linq to Sql class which looks like this. so i
I have generated a java code from matlab and while executing the java code

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.