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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:28:17+00:00 2026-06-18T00:28:17+00:00

Suppose I need simple grammar that describes language like foo 2 bar 21 but

  • 0

Suppose I need simple grammar that describes language like

foo 2
bar 21

but not

foo1

Using jflex I wrote smt like

WORD=[a-zA-Z]+
NUMBER=[0-9]+
WHITE_SPACE_CHAR=[\ \n\r\t\f]

%state AFTER_WORD
%state AFTER_WORD_SEPARATOR

%%
<YYINITIAL>{WORD}               { yybegin(AFTER_WORD); return TokenType.WORD; }        
<AFTER_WORD>{WHITE_SPACE_CHAR}+ { yybegin(AFTER_WORD_SEPARATOR); return TokenType.WHITE_SPACE; }        
<AFTER_WORD_SEPARATOR>{NUMBER}  { yybegin(YYINITIAL); return TokenType.NUMBER; }        

{WHITE_SPACE_CHAR}+             { return TokenType.WHITE_SPACE; }

But I dont like extra states that used for saying that there should be whitespace between word and digit. How I can simplify my grammar?

  • 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-18T00:28:18+00:00Added an answer on June 18, 2026 at 12:28 am

    From what I know of JFlex, if you are recognizing whitespaces corectly (which seems to be the case), you don’t have to use extra states. Just make a rule for “identifiers”, and another one for “numbers”.

    %%
    {WORD}    { return TokenType.WORD; }
    {NUMBER}  { return TokenType.NUMBER; }
    

    If your language imposes each line to be consisted of exactly one identifier, one space and one number, this should be checked by syntactic analysis (i.e. by a parser), not lexical analysis.

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

Sidebar

Related Questions

Suppose I have a simple MySQL table that looks like this: CREATE TABLE `my_table`
I need to construct some rather simple SQL, I suppose, but as it's a
Suppose that I check-in a change in the wrong TFS branch. I need to
Suppose you need to create a 'top' of some sort and have code like
Suppose I have a simple table, like this: Smith | Select Jones | Select
Suppose you have a simple block of code like this: app.get('/', function(req, res){ res.send('Hello
Suppose that I need to implement at least 5 queues in one procedure, each
I need help understanding what the advantage of using an asynch framework is. Suppose
Suppose I need to set an opacity mask on a WPF control that highlights
Suppose i want something simple like the following: I have an core-algorithm, which randomly

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.