public abstract class ForthReader
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected int |
bufferSize
Number of characters in the buffer.
|
protected java.lang.String |
description
Description of the Reader type, used to identify the input
source when reporting an error.
|
protected int |
lineNumber
The current line number.
|
protected int |
position
Current read position within the buffer.
|
Constructor and Description |
---|
ForthReader(java.lang.String title)
Initialise the reader with the given description.
|
Modifier and Type | Method and Description |
---|---|
void |
backup()
Backup one position in the input buffer if possible.
|
protected abstract int |
charAt(int off)
Return the character at the given offset into the buffer or -1
if the character is unavailable.
|
abstract void |
close()
Close the input stream.
|
int |
getBase()
Return the location of the first character in the input stream.
|
java.lang.String |
getDescription()
Return the string description of the input source.
|
int |
getLineNumber()
Return the current line number within the input stream.
|
protected int |
getPosition()
Return the current character position within the input buffer.
|
boolean |
isEmpty()
Determines whether the input buffer is empty or not, without
regard to the underlying character stream.
|
abstract int |
read()
Reads a single character.
|
boolean |
ready()
Determines whether this stream is ready to be read.
|
abstract boolean |
refill()
Attempt to fill the input buffer from the input source, and
return true if successful.
|
abstract ForthReader |
restoreInput(VM vm)
Restore the current input environment from the system stack.
|
abstract void |
saveInput(VM vm)
Save the current input parameters on the system stack.
|
void |
setLineNumber(int value)
Set the current line number to the given value.
|
protected void |
setPosition(int value)
Set the current character position, such that the next
character read will return the character at this position.
|
int |
size()
Returns the number of characters in the current line buffer.
|
protected java.lang.String description
protected int position
protected int bufferSize
protected int lineNumber
public ForthReader(java.lang.String title)
title
- the title for the input source to be used in
error reports.public void backup()
public abstract int read() throws java.io.IOException
java.io.IOException
- when there is a problem reading the input
stream.public boolean isEmpty()
public boolean ready() throws java.io.IOException
java.io.IOException
- If an I/O error occurspublic abstract void close() throws java.io.IOException
java.io.IOException
protected int getPosition()
protected void setPosition(int value)
value
- the character offset to read the next character from.protected abstract int charAt(int off)
off
- the offset from the start of the buffer to obtain
a character.public abstract void saveInput(VM vm)
save-input
function.
Place all of the parameters on the data stack followed by the
number of parameters.vm
- the virtual machine to use when saving the current
input environment.public abstract ForthReader restoreInput(VM vm)
restore-input
function.
This is the counter part to the saveInput()
method.
The top of the stack holds the number of parameters saved.vm
- the virtual machine to recover input parameters
form.null
if the input environment could not
be recovered.public abstract boolean refill() throws java.io.IOException
position
to zero,
set bufferSize
to the number of bytes read,
and return true.
Receipt of a line containing no characters is considered
successful. If there is no input available return false.
This method is called by the Forth function refill
.java.io.IOException
- if there is an error when reading the line.public int getLineNumber()
public void setLineNumber(int value)
value
- the value of the new line number.public int size()
public java.lang.String getDescription()
public int getBase()