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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:35:08+00:00 2026-06-02T05:35:08+00:00

A somewhat vague question, I apologize in advance. I’m building the tokenizing portion of

  • 0

A somewhat vague question, I apologize in advance.

I’m building the tokenizing portion of a small parser with help of the book Building Parsers with Java. It uses PushbackReader and the String contained within as a way to first detect the first character of the given string then sends the PushbackReader to the appropriate state (the state then builds the token as a separate object containing a String).

PushbackReader seems to only be used if no other characters of use are found within the the stream. It then unreads the last character.

Is it possible to do the same thing with a CharBuffer’s append? Preferably something that doesn’t require the buffer to be predefined.

  • 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-02T05:35:09+00:00Added an answer on June 2, 2026 at 5:35 am

    Based on what I see, he chose PushbackReader for two reasons:

    1. He needed a reader that could handle individual characters.
    2. He needed to backup in the stream because when tokenizing he needed to see one character or more ahead to decide if the current char was part of the token.

    For example with the method WhitespaceState.nextToken he is skipping whitespace characters. He pulls off a character and looks at it. If it is a whitespace char he pulls the next char. When he finally pulls a character that is not whitespace, he puts it back into the stream so the next method that looks at the stream will be looking at the correct character.

    While you could replace it with something more simple that has just two methods, read(), and unread(), you have to remember that by doing so you will probably be

    1. Reading in the entire input, and then processing the input. So if you have a large file you will be eating up memory to store it.
    2. Reading the input once as a stream, but storing the char(s) from unread() and passing them around in a separate structure.

    With PushbackReader, he is reading and processing through the input once, he does not have to buffer the entire input, nor is he having to store the unread() characters and pass them around separately

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

Sidebar

Related Questions

I am going to apologize in advance for being extremely vague, but my knowledge
I'm sorry if my question is somewhat vague. It's been a few years since
Somewhat related to my earlier question. I'm making a simple html parser to play
This is a homework question, which is why it might be somewhat odd(also apologize
Somewhat related to this question , but in the absence of any answer about
Somewhat similar to this question , except we haven't decided that we're going with
I've a somewhat silly question, if i have a series of processes that are
I am somewhat new to LINQ and have a quick question regarding deleting. Say,
I noticed there was a question somewhat similar to mine, only with c#: link
Sorry for being somewhat vague but so is the project I'm leading now. I

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.