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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:31:26+00:00 2026-06-02T08:31:26+00:00

Is there a well-known parser description language (like Backus-Naur) that allows for repetitions where

  • 0

Is there a well-known parser description language (like Backus-Naur) that allows for repetitions where the number of repetitions is extracted from the token stream? For bonus points, are there any C++ libraries that support this syntax?

Example:

Lets call the “meta-token” #, then I’m looking for a description language that would treat a production rule of the following form:

RULE = # EXPRESSION

As:

RULE = '1' EXPRESSION
     | '2' EXPRESSION EXPRESSION
     | '3' EXPRESSION EXPRESSION EXPRESSION
     | '4' EXPRESSION EXPRESSION EXPRESSION EXPRESSION
     | ...

Note that the counts are actual character literals. This is in contrast to augmented Backus-Naur form, where we can have rules of the form:

RULE = 2*3EXPRESSION

Which are equivalent to:

RULE = EXPRESSION EXPRESSION
     | EXPRESSION EXPRESSION EXPRESSION

Response to dgarant:

I’m not sure that’s quite what I want. I’m thinking something along the following lines:

int i;

bool r = phrase_parse(first, last,
     (
       int_[ phoenix::ref(i) = _1] >> repeat(i)[/*EXPRESSION*/]
     )
     space );

More importantly though I was hoping for some formalized schema that could describe this idea. On a side node, Spirit does take some getting use to, but is pretty awesome. I’m a fan.

  • 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-02T08:31:31+00:00Added an answer on June 2, 2026 at 8:31 am

    I can’t think of a formal language which allows rule = # EXPRESSION to specify repetition where # is a character literal. In my opinion, it shouldn’t be a problem to abuse the formal language specification provided you make a comment to clarify what you mean. If you really want to stick to standards, you could do the following in ABNF:

    rule = '3' 3EXPRESSION
         | '4' 4EXPRESSION
         | '5' 5EXPRESSION
    

    It doesn’t look exactly like what you want but it gets the job done.

    I believe boost::spirit::qi can suit your needs for parsing. Have a look at the repeat directive.

    Spirit would allow you to write rules such as

    rule = char_("'") >> int_[qi::_a = qi::_1] >> char_("'") >> repeat(qi::_a)[EXPRESSION]
    

    If you’re interested in determining the number of repetitions that were parsed, you can append another action to the rule: [phoenix::ref(pCt) = qi::_a]

    std::vector<double>& v;
    int pCt;
    
    bool r = phrase_parse(first, last,
             (
               // to parse a collection of double expressions
               char_("'") >> int_[qi::_a = qi::_1] >> char_("'") >> repeat(qi::_a)[double_[push_back(phoenix::ref(v), _1)]]
               [phoenix::ref(pCt) = qi::_a]
             )
             space);
    // assuming the parse was successful
    std::cout << "Parsed " << pCt << " elements" << std::endl;
    

    The style of Spirit::Qi parsers takes a while to get used to, but they’re very powerful since you can integrate them directly into your code.

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

Sidebar

Related Questions

There are well-known algorithms for cryptography to compute modular exponentiation (a^b)%c (like Right-to-left binary
Is there any well-known algorithm (or obvious solution) for transforming a list from order
Is there a well-designed method that can run my ruby program from anywhere? I
It there a well known way, how to implement in Coco/R tokenizing indents like
For each of the modern browsers are there well known hooks I can tie
Is there a well-known, portable, good library for C++ process management? I found a
There is a well known issue when it comes to using .NET value types
It seems to be well-known there is a bug when using JMenuItem.getRootPane(). I read
Are there any parser combinators library that gives performance comparable to Happy/Alex ? I
java serializes objects in a well-known and published manner (there's a spec ). what

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.