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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:52:29+00:00 2026-06-16T11:52:29+00:00

Updated … i know, my grammar is ambiguous but how can I rewrite this

  • 0

Updated …
i know, my grammar is ambiguous but how can I rewrite this grammar to eliminate this ambiguity? ………………

I have a grammar just like this:

Bison file

%left equal nEqual
%left gre less greOrEqual lessOrEqual
%left plus sub
%left DIV mult exp mod
%left not
%left leftB rightB
%%


S :
var "=" A ";"  
;


A:
 Aexp   
|Rexp   
;

Aexp :
Num                                     
| leftB Aexp  rightB               
| Aexp  plus    Aexp            
| Aexp  sub     Aexp            
| Aexp  DIV     Aexp            
| Aexp  mult    Aexp            
;


Rexp :
Aexp                            
| Rexp  gre Rexp                
| Rexp  less Rexp               
| Rexp  greOrEqual  Rexp                
| Rexp  lessOrEqual Rexp            
| Rexp  equal Rexp              
| Rexp  nEqual Rexp             
;

I get 1 shift/reduce and 1 reduce/reduce conflicts doing this, how can I change the grammar to eliminate Conflicts ?

  • 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-16T11:52:31+00:00Added an answer on June 16, 2026 at 11:52 am

    Your grammar is ambiguous. An A can be an Aexp or an Rexp. But an Rexp can also be an Aexp. This leads to a reduce/reduce conflict.

    Let’s say you give your parser this token sequence as input:

    var = Num ;

    The start symbol S expands to var = A ;

    The non-terminal A has to match the token Num. But should that be an A that expands to and Aexp which then expands to Num, or should it be an A that expands to and Rexp, which then expands to Aexp, which then expands to Num?

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

Sidebar

Related Questions

UPDATED: I have some table with sync_numbers, like this: --------------------- id | sync_number ---------------------
UPDATED QUESTION Ok, so I have a file with lines like this: 44:) 2.884E-02
Updated: This may be an easy or a complex question, but in wpf, I
UPDATED I know padding make distance from border but Why we must use padding
Updated-2 I have interesting combination of warnings & errors. Firstly, when debugging, i get
Updated Example: http://jsfiddle.net/7Cwbn/62/ You can click on the markers Hold Ctrl to select multiple
Updated question, see below I'm starting a new project and I would like to
Updated below . The following is the entire code I have in my main.cpp:
Updated: please see this other thread instead, all this COM stuff is not part
Updated This is kind of an interesting problem I am experiencing. I need to

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.