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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:23:26+00:00 2026-06-13T04:23:26+00:00

I’m trying to make my own LR(0) parser, and I’m running into trouble with

  • 0

I’m trying to make my own LR(0) parser, and I’m running into trouble with some grammars.

Basically, for the grammar

exp:  mexp
mexp: '1'
mexp: mexp '*' '1'

my parser is outputting

State 0: • 1
       | • mexp
       | • exp
       | • mexp * 1
State 1: 1 •
State 2: exp •
State 3: mexp • * 1
       | mexp •
State 4: mexp * • 1
State 5: mexp * 1 •

with the warning

(state 3, *) already has reduction:  exp: mexp

The LR(0) table my program derived for this grammar is:

         '1' exp mexp '*'    $
State 0:  s1  s2   s3         
State 1:  r3           r3   r3
State 2:                   acc
State 3:  r2           s4   r2
State 4:  s5                 
State 5:  r4           r4   r4

where $ denotes the end of file.

The warning stems from the fact that state 3 — which corresponds to mexp • * 1 | mexp • — has both a reduction r2 and a state transition s4 for the input *.

But it seems like according to Wikipedia, this should not be happening — I should only have reductions:

If an item set i contains an item of the form A → w • and A → w is rule m with m > 0 then the row for state i in the action table is completely filled with the reduce action rm.

The funny thing is, when I remove the rule exp: mexp, I don’t get any such conflicts.

So what I’m having trouble figuring out is, is this indeed a genuine problem in the grammar?
(In other words, is this grammar not, in fact, LR(0)?)
I don’t believe this to be the case but I’m not sure.

If so, why? And if not, then what’s wrong? (Is my table wrong, or am I doing something else incorrectly?)

  • 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-13T04:23:27+00:00Added an answer on June 13, 2026 at 4:23 am

    (After reading that Wikipedia page more carefully.)

    The Wikipeda quote is (emphasis added):

    If an item set i contains an item of the form A → w • and A → w is rule m with m > 0 then the row for state i in the action table is completely filled with the reduce action rm.

    Rule 0 is the augmented start rule, which in your case should be:

    start : mexp '$'
    

    (Personally, I prefer adding the EOF token explicitly; there are fewer exceptions that way.)

    However, what you’ve got, I think, is:

    start : exp '$'
    exp   : mexp
    

    which actually isn’t LR(0), because the unit reduction rule ( exp → mexp ) leads to the shift-reduce conflict you discovered.

    The Wikipedia article’s exception for m = 0 would be unnecessary if the rule were written with an explicit end-marker; in this case, the action acc is generated according to modified action 3:

    1. An extra column for ‘$’ (end of input) is added to the action table that contains acc for every item set that contains S → E • ‘$’.

    (Actually, you don’t need the “extra column” part; with an explicit end-marker you should already have a column for it. The point is to override the shift action with an acc action.)

    • 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
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.