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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:34:07+00:00 2026-06-12T06:34:07+00:00

I currently have a reduction in bison which is meant to match a comma-separated

  • 0

I currently have a reduction in bison which is meant to match a comma-separated list with several optional different rules:

arg_list
    :
    | expr_list
    | assignment_list
    | expr_list ',' assignment_list
    | varargs
    | expr_list ',' varargs
    | assignment_list ',' varargs
    | expr_list ',' assignment_list ',' varargs
    | varkwdargs
    | expr_list ',' varkwdargs
    | assignment_list ',' varkwdargs
    | expr_list ',' assignment_list ',' varkwdargs
    | varargs ',' varkwdargs
    | expr_list ',' varargs ',' varkwdargs
    | assignment_list ',' varargs ',' varkwdargs
    | expr_list ',' assignment_list ',' varargs ',' varkwdargs
    ;

In case it is unclear, this is meant to implement (in pseudocode):

arg_list
    :
    | expr_list [',' assignment_list] [',' varargs] [',' varkwdargs]
    | assignment_list [',' varargs] [',' varkwdargs]
    | varargs [',' varkwdargs]
    | varkwdargs
    ;

The way to do this would be to implement, for example:

optional_assignment_list:
    :
    | ',' assignment_list
    ;

However, the latter formulation is not LALR(1), since at each step where Bison sees a comma, it has to decide whether to, for example, shift and look for an *assignment_list* or reduce an empty *optional_assignment_list* and move on to look for an *optional_varargs*.

I am trying to find if there is a better way to represent this. I have been able to decrease the number of alternatives by introducing *optional_varkwdargs*, but that still leaves nine alternatives to the reduction, which I guess is better than 16:

optional_varkwdargs
    :
    | ',' varkwdargs
    ;

arg_list
    :
    | expr_list optional_varkwdargs
    | assignment_list optional_varkwdargs
    | expr_list ',' assignment_list optional_varkwdargs
    | varargs optional_varkwdargs
    | expr_list ',' varargs optional_varkwdargs
    | assignment_list ',' varargs optional_varkwdargs
    | expr_list ',' assignment_list ',' varargs optional_varkwdargs
    | varkwdargs
    ;

Any ideas would be appreciated.

  • 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-12T06:34:08+00:00Added an answer on June 12, 2026 at 6:34 am

    Well, one possibility is to have a more general arglist parser that allows lists of any of these things in any order:

    arg_list: arg_item 
              { $$ = CreateSingletonArgList($1); }
            | arg_list ',' arg_item
              { if (CheckArgListOrdering($1, $3))
                    $$ = AppendArgList($1, $3);
                else
                    $$ = $1; }
            ;
    
    arg_item: expr
            | assignment
            | vararg
            | varkwarg
            ;
    

    You then have a post-parse check on an arg_list to ensure that things don’t come in the wrong order. This has the advantage that you can give better error messages for these cases (“kwarg must be after vararg” or some such) rather than just a generic “syntax error”

    edit

    With the above actions in the rules, the CheckArgListOrdering function checks to make sure an arg_item can go after all of those in an existing arg_list and issue an appropriate error message if not. The return value tells the parser whether to accept the new arg_item or throw it away. The Create/Append functions just manage arg_lists as any kind of ordered collection data structure (might be a linked list, or an array, or anything else appropriate).

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

Sidebar

Related Questions

I currently have a table of concentrations, which are linked to a table of
Currently have a list of images in an unordered list. <ul id=sponsors><li><img src=.../></li> <li><img
Currently have a drop down menu that is activated on a hover (from display:none
Currently have password protection on my main and sub directories, however I'd like to
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty
I currently have one project that currently contains multiple packages. These packages make up
I currently have 4 tables. Product, Category, SubCategory, ProductSubCategory. Category has a OneToMany SubCategory
I currently have a form with inputs and name attributes. I'm able to get
I currently have a deployed app (fortworth.herokuapp.com) that I am attempting to sort movies
I currently have a MySQL table like: id | friend 1 | 2 1

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.