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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:20:10+00:00 2026-05-28T19:20:10+00:00

I am working on learning lex and the turtle language I am having problems

  • 0

I am working on learning lex and the turtle language
I am having problems getting lex to recognize operators as tokens + , < , =

I have them stored in a file
I have tried doing it this way

\+ or "+" or '+' or [+]

I don’t get any errors using single quotes but it doesnt match it either or would i need to do that in the file?.

Here is my file

fd 3x00
bk
setc 100
int xy3 fd 10 rt 90
rt
lt
setxy
setx
sety
home
seth
pd
pu
ht
st
color
xcor
ycor
heading
random
:=
+
<

and here is the program

%{

 #include <stdio.h>
 #include <stdlib.h>
int number;

%}
%%

fd                    {printf("Keyword %s\n", yytext);}
[^\t\n\r]             {}
[0-9]+[a-z]+[0-9]+   {printf("Illegal: 3x00\n");}
[\r\t\n]+               {}
bk                    {printf("Keyword: %s\n", yytext);}
setc                  {printf("Keyword: %s\n", yytext);}
[0-9]+               {printf("Number: %s\n", yytext);}

int                   {printf(" Keyword: %s\n", yytext);}
xy3                   {printf("ID: %s\n", yytext);}
fd[0-9]+              {printf("Keyword: %s\n", yytext);
                  printf("Number %s\n", yytext);}
rt                    {printf("Keyword: %s\n", yytext);}
lt                    {printf("Keyword: %s\n",yytext);}
setxy                 {printf("Keyword: %s\n", yytext);}
setx                  {printf("Keyword: %s\n", yytext);}
sety                  {printf("Keyword: %s\n", yytext);}
home                  {printf("Keyword: %s\n", yytext);}
seth                  {printf("Keyword: %s\n", yytext);}
pd                    {printf("Keyword: %s\n", yytext);}
pu                    {printf("Keyword: %s\n", yytext);}
ht                    {printf("Keyword: %s\n", yytext);}
st                    {printf("Keyword: %s\n", yytext);}
color                 {printf("Keyword: %s\n", yytext);}
xcor                  {printf("Keyword: %s\n", yytext);}
ycor                  {printf("Keyword: %s\n", yytext);}
heading               {printf("Keyword: %s\n", yytext);}
random                {printf("Keyword: %s\n", yytext);}
:=                    {printf("Keyword: =\n"  );}
\+                    {printf("Keyword: + \n" );}
\<                     {printf("Keyword: < \n");}
%%

main( int argc,char** argv)

{
    if(argc > 1)
    {

        FILE *file;
        file = fopen(argv[1], "r");
        if(!file)
        {
           fprintf(stderr, "Could not open %s \n", argv[1]);
           exit(1);
           }

           yyin = file;

           }

           yylex();

}

Error i get is Warning, rule cannot be matched.

What am i doing wrong?

Thank you

  • 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-28T19:20:11+00:00Added an answer on May 28, 2026 at 7:20 pm

    I think I see the problem

    [^\t\n\r]             {}
    ...
    [\r\t\n]+               {}
    ...
    \+                    {printf("Keyword: + \n" );}
    \<                     {printf("Keyword: < \n");}
    

    The + and < characters will match both the top rule ([^\t\n\r]) and the \+/\< rule. Since they are the same length, the lexer will take the first match, [^\t\n\r], so it will do nothing ({}) and it can never match the \+/\< rule, as it says. Take the [^\t\n\r] rule out and replace it with . {} at the very end of the token list.

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

Sidebar

Related Questions

I'm working on learning Objective-C/Coaoa, but I've seem to have gotten a bit stuck
I'm working on learning GWT (total newb) and have a question regarding the Visualiztion
I am working on learning C and am using some practice problems from the
I have been working on learning ANTLR in order to create a domain specific
I have been working on learning C++ and Qt4 recently, but I have hit
I am working on learning Android. From the documents I have read so far
I'm new to C# and have been working on learning database's. Currently I'm trying
I'm learning C# and working on my first ASP.Net e-commerce website. I have the
I'm working on learning TDD while writing some small ruby programs. I have the
Im working on a project in MVC and have enjoyed learning about it. There

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.