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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:08:28+00:00 2026-06-03T08:08:28+00:00

I am rewriting Jack Crenshaw’s let’s build a compiler from Turbo Pascal 4.0 to

  • 0

I am rewriting Jack Crenshaw’s “let’s build a compiler” from Turbo Pascal 4.0 to JAVA. This is motivating because the classic book does not have yet an O-O version

Is there a more modern, OO version of "Let's Build a Compiler"?

The book contains 15 chapters. The compiler is presented in an incremental manner: Chapter I provides the boilerplate codes for the whole compiler, then each chapter adds some lines to the Pascal procedures of the precedent chapter.

I have already translated the first 2 chapters, each chapter as a package, each Pascal procedure as a static protected method in JAVA, the procedures of one chapter are gathered in a single class that extends the class translated from its precedent chapter.

package td1;
public class Cradle {
    protected final static char TAB='\t';
    protected static char look;

    protected static void getChar() throws IOException {
        look=(char) System.in.read();
        }       
 ...
}

package td2;

public class Cradle extends td1.Cradle{

    protected static void factor() throws IOException {
    ...
    }

...
}

However, when I come to td3, I have to update the factor() of td2.Cradle, but I do not want to change in td2.Cradle the factor(), because that will make the factor() in td2 do more than it should have presented in td2. I thought of “extend” td2.Cradle(), however, it seems impossible to extend a static class.

My related question here

Maybe should I change every static method to non-static one?

I certainly need some design pattern here, any one can help? I hope I was clear. In summary, this project incrementally presents more and more instructions for each procedure and I do hope to record the intermediate steps using some JAVA mechanism like inheritance.

The Pascal code is the classic book is here LBC. I feel attempted to use inheritance because

  1. Each chapter calls/adds a bit more lines to the procedures defined in precedent chapters
  2. I hope to make my JAVA source code usable to everyone who wants to follow LBC step by step. So it is not appropriate to use a single class to put in the final source code of the author’s compiler. It is essential to split the codes by chapters and increment them gradually as Crenshaw did.

My actual solution is to keep the methods of tp1.Cradle as static. The methods in tp2.Cradle, tp3.Cradle, … , until tp15.Cradle will be non-static, and they all statically import tp1.Cradle.* . Furthermore, for every integer i greater than 2, tp[i].Cradle extends tp[i-1].Cradle.

Don’t hesitate to tell me better solution.

  • 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-03T08:08:30+00:00Added an answer on June 3, 2026 at 8:08 am

    It sounds like you are on the right track. In order to be able to override these methods, they should be instance methods. And so you should move away from a model that relies on these “global methods”, to an instance based model, where you create an instance of the Cradle class and call the appropriate methods on that instance.

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

Sidebar

Related Questions

Im rewriting application from .NET to PHP. I need to create class like this:
We are rewriting an old site for a client, from Classic ASP to ASP.NET
I typically use URL rewriting to pass content IDs to my website, so this
I'm rewriting an LOB application whose architecture is like this: Silverlight && Windows Mobile
I am working on rewriting my application from YUI 2 to YUI 3. Sometimes
I'm rewriting everything and moving away from absolute positions and instead using floats to
I'm doing url rewriting (Wildcards) for a sigle web site based on this blog
While rewriting an assembly if I were to instruct a compiler to generate a
Hi I'm rewriting a script from MATLAB to C++ using armadillo library for linear
This rewriting rule is not working (the id is empty after redirecting): RewriteRule ^album/([0-9]+)$

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.