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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:39:45+00:00 2026-06-14T04:39:45+00:00

I am writing a lexical analyzer here is the code: %{ #include <stdio.h> void

  • 0

I am writing a lexical analyzer here is the code:

%{
#include <stdio.h>
void showToken(char*);
%}

%%
int main(){
void showToken(char* name){
        printf("<%s,%s>",name,yytext);
}
return 0;
}
%%

I am getting the following :

~/hedor1>cc -c -o lexical.o lexical.c
lexical.l:40: error: expected identifier or â(â before â%â token

I cant find where is the problem and moreover in the CODE SECTION must I write :

int main(){}

what happens if I don’t write the main function above?

  • 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-14T04:39:46+00:00Added an answer on June 14, 2026 at 4:39 am

    Primary problem

    You can only have two %% lines in a Lex (Flex) analyzer.

    ...definitions...
    %%
    ...lexical patterns...
    %%
    ...everything else...
    

    The programs Lex and Flex simply copy the content of the file after the second %% verbatim into the generated C code. And C doesn’t like %% at any time.

    Nitpick

    You shouldn’t nest functions inside each other like you’re trying to with:

    int main(){
    void showToken(char* name){
            printf("<%s,%s>",name,yytext);
    }
    return 0;
    }
    

    You need to separate main() from showToken(). (There is a GCC-specific extension that does allow nested functions. Don’t use it.)


    Also, when you have a line number in an error message, it is helpful to insert a comment to identify the line in the source. Or describe the line that is identified. But we shouldn’t have to count the lines in your code, even if the error is in line 1…well, maybe lines 1-3 aren’t too critical, but there is a fuzzy breakpoint after which identifying the line is important. By the time is has reached the teens, it is close to essential; the first 5 lines probably aren’t crucial; in between (6-12) it’s generally better to indicate the line number.

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

Sidebar

Related Questions

//Writing a letter #include <iostream> using namespace std; int main() { string first_name; //Name
Alright so I am writing a function as part of a lexical analyzer that
Possible Duplicate: problem getting c-style comments in flex/lex I am writing a lexical analyzer
Writing Classic ASP code in JScript has a lot going for it: more humane
Writing documentation in html requires some code examples. What to do with characters that
When writing code, I often place debug messages in the code. The debug messages
I'm writing lexical specification for JFlex (it's like flex, but for Java). I have
I am writing some Python code to implement some of the concepts I have
I'm currently writing an expression parser. I've done the lexical and syntactic analysis and
Writing some drag&drop code, I'd like to cancel the click events in my mouseup

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.