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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:18:46+00:00 2026-05-20T22:18:46+00:00

I’m trying to read Compiler Construction by Niklaus Wirth. On page 23 he starts

  • 0

I’m trying to read Compiler Construction by Niklaus Wirth. On page 23 he starts to describe how LALR would parse the expression x*(y+z) given the following grammar:

E  = T  | E "+" T. expression 
T  = F  | T "*" F. term 
F  = id | "(" E ")". factor

He goes on to show the reduction as:

     Action   Stack     Remaining
1             x         * (y + z) 
2    S        x         * (y + z) 
3    R        F         * (y + z) 
4    R        T         * (y + z) 
6    S        T*          (y + z) 
7    S        T*(          y + z) 
8    S        T*(y           + z) 
9    R        T*(F           + z) 
10   R        T*(T           + z) 
11   R        T*(E           + z) 
12   S        T*(E+            z) 
13   S        T*(E + z          ) 
14   R        T*(E + F          ) 
15   R        T*(E + T          ) 
16   R        T*(E              ) 
17   S        T*(E) 
18   R        T*F 
19   R        T 
20   R        E

Where the action is S (for shift) or R (for reduction … I added the line numbers for clarity). So I think I understand how to go from steps 1 to 4 and from 4 to 20, but I don’t understand 4 itself. For example, step 1 pushes x onto the stack. x represents the RHS of rule ‘F’, so a reduction occurs -> F. F represents the 1st “OR” of rule ‘T’ and so another reduction can occur -> T. If that is right (which I’m not sure it is?), then why wouldn’t T also be replaced with E as T represents the first “OR” of the RHS of rule ‘E’. Is it because rule E has an implied “EOF” so to speak (and since we haven’t reached EOF it can’t reduce)? Or is it because it’s ambiguous at this point (T also represents the 1st part of the 2nd “OR” of the RHS of rule T … ie, T “*” F)? Or is it something else entirely?

Thanks!

  • 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-20T22:18:46+00:00Added an answer on May 20, 2026 at 10:18 pm

    The parser uses two criteria to decide what action (shift or reduce) to take next. The first is when the tokens on the stack match the right hand side of a production. After step 4, the T on the stack matches the E = T production, so if that were the only criterion, it could reduce at that point. However, the parser is also looking at the lookahead (ie, first token in “remaining”) to decide what action to take. There’s no rule which has E “*” as a prefix, so that reduction is not valid, and the only action is a shift. After step 20, the E = T production is valid, because (as you guessed) the lookahead token there is effectively an EOF, which does match.

    Note that some ambiguous grammars can result in both a shift and a reduce action being valid. In these cases, Bison resolves in favor of “shift”. See the Bison docs for more detail. However, the grammar given above is not ambiguous; one token of lookahead is enough to make it unambiguous.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
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
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
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.