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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:58:31+00:00 2026-06-13T11:58:31+00:00

A stripped down version of the grammar with the conflict: body: variable_list function_list; variable_list:

  • 0

A stripped down version of the grammar with the conflict:

body: variable_list function_list;
variable_list:
  variable_list variable | /* empty */
;
variable:
  TYPE identifiers ';'
;
identifiers:
  identifiers ',' IDENTIFIER | IDENTIFIER
;
function_list:
  function_list function | /* empty */
;
function:
  TYPE IDENTIFIER '(' argument_list ')' function_body
;

The problem is that variables and functions both start with TYPE and IDENTIFIER, e.g

int some_var;
int foo() { return 0; }

variables are always declared before functions in this language, but when a parse is attempted, it always gives

parse error: syntax error, unexpected ‘(‘, expecting ‘,’ or ‘;’ [after foo]

How can the variable_list be made to be less greedy, or have the parser realize that if the next token is a ‘(‘ instead of a ‘;’ or ‘,’ it is obviously a function and not a variable declaration?

The bison debug output for the conflict is

state 17

3 body: variable_list . function_list
27 variable_list: variable_list . variable

T_INT    shift, and go to state 27
T_BOOL   shift, and go to state 28
T_STR    shift, and go to state 29
T_VOID   shift, and go to state 30
T_TUPLE  shift, and go to state 31

T_INT     [reduce using rule 39 (function_list)]
T_BOOL    [reduce using rule 39 (function_list)]
T_STR     [reduce using rule 39 (function_list)]
T_VOID    [reduce using rule 39 (function_list)]
T_TUPLE   [reduce using rule 39 (function_list)]
$default  reduce using rule 39 (function_list)

variable       go to state 32
simpletype     go to state 33
type           go to state 34
function_list  go to state 35

I have tried all sorts of %prec statements to make it prefer reduce (although I am not sure what the difference would be in this case), with no success at making bison use reduce to resolve this, and I have also tried shuffling the rules around making new rules like non_empty_var_list and having body split up into function_list | non_empty_var_list function_list and none of the attempts would fix this issue. I’m new to this and I’ve run out of ideas of how to fix this, so I’m just completely baffled.

  • 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-13T11:58:32+00:00Added an answer on June 13, 2026 at 11:58 am

    the problem is in that variables and functions both start with TYPE and IDENTIFIER

    Not exactly. The problem is that function_list is left-recursive and possibly empty.

    When you reach the semi-colon terminating a variable with TYPE in the lookahead, the parser can reduce the variable into a variable_list, as per the first variable_list production. Now the next thing might be function_list, and function_list is allowed to be empty. So it could do an empty reduction to a function_list, which is what would be necessary to start parsing a function. It can’t know not to do that until it looks at the ‘(‘ which is the third next token. That’s far too far away to be relevant.

    Here’s an easy solution:

    function_list: function function_list
                 | /* EMPTY */
                 ;
    

    Another solution is to make function_list non-optional:

    body: variable_list function_list
        | variable_list
        ;
    
    function_list: function_list function
                 | function
                 ;
    

    If you do that, bison can shift the TYPE token without having to decide whether it’s the start of a variable or function definition.

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

Sidebar

Related Questions

I need to access a JavaScript variable with PHP . Here's a stripped-down version
I am using a very stripped down version of Linux, I want to create
Here's a version of the code I'm using, stripped down to just the parts
I have a simple ANTLR grammar, which I have stripped down to its bare
OK here is stripped down version of what I have in my app Artist
For simplicity this is a stripped down version of what I want to do:
I observed some strange behavior regarding injecting EntityManager. Following is stripped down version of
Sure there's something tiny wrong with my syntax... Here is stripped down version of
I have 2 tables. The following are just a stripped down version of these
So I made this super stripped down version of a html css jquery navigation

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.