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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:29:34+00:00 2026-05-20T13:29:34+00:00

Working through this for fun: http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/ Example calculation of nullable and first uses a

  • 0

Working through this for fun: http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/

Example calculation of nullable and first uses a fixed-point calculation. (see section 3.8)

I’m doing things in Scheme and relying a lot on recursion.

If you try to implement nullable or first via recursion, it should be clear you’ll recur infinitely on a production like

N -> N a b

where N is a non-terminal and a,b are terminals.

Could this be solved, recursively, by maintaining a set of non-terminals seen on the left hand side of production rules, and ignoring them after we have accounted for them once?

This seems to work for nullable. What about for first?

EDIT: This is what I have learned from playing around. Source code link at bottom.

Non terminals cannot be ignored in the calculation of first unless they are nullable.

Consider:

N -> N a
N -> X
N -> 

Here we can ignore N in N a because N is nullable. We can replace N -> N a with N -> a and deduce that a is a member of first(N).

Here we cannot ignore N:

N -> N a
N -> M
M -> b

If we ignored the N in N -> N a we would deduce that a is in first(N) which is false. Instead, we see that N is not nullable, and hence when calculating first, we can omit any production where N is found as the first symbol in the RHS.

This yields:

N -> M
M -> b

which tells us b is in first(N).

Source Code: http://gist.github.com/287069

So … does this sound OK?

  • 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-20T13:29:35+00:00Added an answer on May 20, 2026 at 1:29 pm

    I suggest to keep on reading 🙂

    3.13 Rewriting a grammar for LL(1) parsing and especially 3.13.1 Eliminating left-recursion.

    Just to note you can run into indirect left recursion as well:

    A -> Bac
    B -> A
    B -> _also something else_
    

    But the solution here is quite similar to eliminating the direct left recursion as in your first example.

    You might want to check this paper which explains it in a little bit more straight-forward way. Less theory 🙂

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

Sidebar

Related Questions

So, I'm a total nuby working through http://www.rubykoans.com/ and I'm stuck on about_scoring_project.rb. This
I'm working my way through K&R's 2nd edition, and I've been stumped with this
I'm working through SICP. Currently, in the first chapter, I'm having problems getting Racket
I am working through this extJS tutorial where you type in code into Firebug,
I'm working through some sample code and then this appeared: public abstract class RandomPool<T>
I am working through the project euler problems in Python 3 as a fun
I'm working through this build-a-JavaScript-framework tutorial . Why in the following code is $super
This is I guess a question in a few parts. I'm working through the
I've been working through Practical Common Lisp and as an exercise decided to write
I'm working through previous years ACM Programming Competition problems trying to get better at

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.