TreeProtocol

public class TreeProtocol

Manages a connection with an input stream that carries a tree, in agreement with our tree protocol. Operators may come as strings or coded as integers.

Constructors

TreeProtocol

public TreeProtocol(InputStream is)

Creates one TreeProtocol. Opens a reader on the stream “is”.

TreeProtocol

public TreeProtocol(BufferedReader reader)

Creates one TreeProtocol. Opens a reader on the stream “reader”.

TreeProtocol

public TreeProtocol(LibReader reader)

Methods

popTreeReader

public Tree popTreeReader()

position

public int position()
Returns

the index of the last thing (operator or value) read. This index starts at 0 (before the first thing is read).

pushTreeReader

public void pushTreeReader()

readOperator

public Operator readOperator()
Throws
  • IOException – when operator is incorrect or when stream is empty.

Returns

the next thing (assumed to be an Operator) on the InputStream. Does not keep it, so that next see or read will return next operator on the stream.

readPrefixTree

public Tree readPrefixTree()

Used by GeneralLibReader. Read an IL Tree written in prefix form with parentheses.

Throws
  • IOException – when operator is incorrect or when stream is empty.

readString

public String readString()

Assumes next thing on stack is a String.

Throws
  • IOException – when operator is incorrect or when stream is empty.

Returns

Pops it and returns it.

readTree

public Tree readTree(ToInt toLineNumber)

Same as readTree(), but returns into toLineNumber the smallest line number found while reading this Tree.

readTree

public Tree readTree()

Read a Tree with this protocol.

Throws
  • IOException – when operator is incorrect or when stream is empty.

Returns

the next incoming complete Tree on the InputStream. Advances the pointer in the InputStream to the next token immediately following this returned tree. Attaches to the top of the returned tree an annotation with the “position” in the protocol just after the top operator of this tree was read.

seeOperator

public Operator seeOperator()
Throws
  • IOException – when operator is incorrect or when stream is empty.

Returns

the next thing (assumed to be an Operator) on the InputStream. But keeps it, so that next see or read will return the same Operator.

setPosition

public void setPosition(int pos)

setTraceOn

public void setTraceOn(boolean traceOn)

When true, things arriving through the inputStream will be shown.