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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:49:54+00:00 2026-06-14T02:49:54+00:00

In the following code which is a lexical recognizer in C language: %{ #include

  • 0

In the following code which is a lexical recognizer in C language:

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

%option yylineno
%option noyywrap
digit ([0-9])
letter ([a-zA-Z])
%%

letter(letter | digit)*             showToken("id");
(digit)(digit)*(.(digit)(digit)*)?      showToken("num");
[(),:;.]                printf("%c",yytext[0]); 
[ \n]
(==|<>|<|<=|>|>=)       showToken("relop");
(+|-)                   showToken("addop");
(*|/)                   showToken("mulop");
(=)                 showToken("assign");
(&&)                    showToken("and");
(||)                    showToken("or");
(!)                 showToken("not");
.                   {   
                    printf("Lexical Error");
                    exit(0);
                    }

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

I get the following errors, why is that happening I think I wrote the code correctly!
I have done too many changes in the code but it doesn’t compile.

~/hedor>lex -t lexical.l > lexical.c
lexical.l:13: unrecognized rule
lexical.l:17: unrecognized rule
lexical.l:17: unrecognized rule
lexical.l:17: unrecognized rule
lexical.l:17: unrecognized rule
lexical.l:17: unrecognized rule
lexical.l:18: unrecognized rule
lexical.l:18: unrecognized rule
lexical.l:18: unrecognized rule
lexical.l:18: unrecognized rule
lexical.l:18: unrecognized rule
lexical.l:21: unrecognized rule
lexical.l:21: unrecognized rule
lexical.l:21: unrecognized rule
lexical.l:21: unrecognized rule
  • 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-14T02:49:56+00:00Added an answer on June 14, 2026 at 2:49 am

    There are several issues in your regular expressions:

    Line 13, actually the error is in the 12, do not add blanks in the RE, it breaks the expression and does not work as expected:

    letter(letter|digit)*             showToken("id");
    

    Line 17, the + is a special character, so escape it with \:

    (\+|-)                   showToken("addop");
    

    Line 18, the same with characters * and /:

    (\*|\/)                   showToken("mulop");
    

    Line 21, the same with |:

    (\|\|)                    showToken("or");
    

    That should fix the compilation errors, but note the comment by @JameySharp below, you likely want to write the digit and letter references using curly braces: {digit} and {letter}.

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

Sidebar

Related Questions

I compiled the following code which is declared with #include <strsafe.h> in my C
I have the following code which definitely returns a proper data result if I
I have the following code which is working, I was wondering if this can
I have the following code which is used to upload large files (~6MB) to
i have the following code which switches some fullscreen-background-images (fadeOut, fadeIn). setInterval(function() { var
I have the following code which is fine if I give invalid parameters (though,
I have the following code which will generate two pdf files containing plots to
I have the following code which utilises Guava's Files.readLines() method: List<String> strings = Lists.newArrayList();
I have the following code which takes List of boolean as a parameter then
I have the following code which creates a simple window with two buttons which

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.