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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:00:00+00:00 2026-05-29T15:00:00+00:00

I’ve written following bison grammar file: %left ‘+’ ‘-‘ %left ‘*’ ‘/’ %token NUMBER

  • 0

I’ve written following bison grammar file:

%left '+' '-'
%left '*' '/'

%token NUMBER

%%

expr
: NUMBER
| expr '+' expr
| expr '-' expr
| expr '*' expr
| expr '/' expr
| expr     expr %prec '*' /* implicit multiplication */
;

Now bison reports shift/reduce conflict regarding expr : expr expr. I’ve extracted problem to following minimal set:

%left OP

%%

expr
: 'a'
| expr expr %prec OP
;

I can’t get why is bison still complains about shift/reduce conflict. I’ve found some old mail archive: Re: bison/yacc: shift/reduce conflict using %prec for composition, but I don’t understand author’s explanations either.

Could someone clarify why this grammar is ambiguous, and how to resolve conflict?

EDIT: by NUMBER NUMBER I mean NUMBER * NUMBER, i.e. product of this two numbers.

  • 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-29T15:00:01+00:00Added an answer on May 29, 2026 at 3:00 pm

    The problem here is that the token NUMBER doesn’t have a precedence. So when there’s a state that can either shift a NUMBER or reduce a rule (regardless of whether that rule has a precedence) it can’t decide which to do.

    Now you can fix it for this grammar by adding a precedence for NUMBER (make it the same as *), but it will come back if you add any rules for expression that start with any token other than NUMBER — for example if you add expr: '(' expr ')', you’ll get shift/reduce conflicts on '('.

    An even bigger problem is if you add unary prefix operators, such as expr: '-' expr. In this case, you won’t get a conflict as ‘-‘ already has a precedence, but an input like NUMBER - NUMBER will get parsed as NUMBER ( - NUMBER ), which is probably not at all what you want. There’s no good way of dealing with this issue with precedence rules.

    The underlying cause of this confusion is that bison’s precedence rules don’t resolve precedence by comparing two rules as you might naively expect based on using the word “precedence”. Instead they work by comparing the “precedence” of a rule to be reduced with that of a token to be shifted and base the decision to shift or reduce based on that. At the point in the parse where this happens, the second rule hasn’t yet been recognized; instead bison is just guessing what it might be based on the token.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.