gnu.text

Class Lexer

public class Lexer extends Reader

Framework for implementing lexical scanners and parsers.
Field Summary
protected booleaninteractive
protected intnesting
protected LineBufferedReaderport
char[]tokenBuffer
For building tokens of various kinds.
inttokenBufferLength
The number of chars of tokenBuffer that are used.
Constructor Summary
Lexer(LineBufferedReader port)
Lexer(LineBufferedReader port, SourceMessages messages)
Method Summary
booleancheckErrors(PrintWriter out, int max)
Returns true if any error were seen.
booleancheckNext(char ch)
Check if the next character matches a given character.
voidclearErrors()
voidclose()
voideofError(String msg)
voideofError(String message, int startLine, int startColumn)
voiderror(char severity, String filename, int line, int column, String message)
voiderror(char severity, String message)
voiderror(String message)
voidfatal(String message)
intgetColumnNumber()
SourceErrorgetErrors()
intgetLineNumber()
SourceMessagesgetMessages()
StringgetName()
LineBufferedReadergetPort()
booleanisInteractive()
voidmark()
Start tentative parsing.
intpeek()
voidpopNesting(char save)
Exit a nested expression, reversing pushNesting
charpushNesting(char promptChar)
Enter a nested expression.
intread()
intread(char[] buf, int offset, int length)
static longreadDigitsInBuffer(LineBufferedReader port, int radix)
Read digits, up to the first non-digit or the buffer limit
intreadOptionalExponent()
Read an optional signed integer.
voidreset()
Stop tentative parsing.
booleanseenErrors()
voidsetInteractive(boolean v)
voidsetMessages(SourceMessages messages)
voidskip()
protected voidskip_quick()
voidtokenBufferAppend(int ch)
Append one character to tokenBuffer, resizing it if need be.
voidunread(int ch)
protected voidunread()
protected voidunread_quick()

Field Detail

interactive

protected boolean interactive

nesting

protected int nesting

port

protected LineBufferedReader port

tokenBuffer

public char[] tokenBuffer
For building tokens of various kinds.

tokenBufferLength

public int tokenBufferLength
The number of chars of tokenBuffer that are used.

Constructor Detail

Lexer

public Lexer(LineBufferedReader port)

Lexer

public Lexer(LineBufferedReader port, SourceMessages messages)

Method Detail

checkErrors

public boolean checkErrors(PrintWriter out, int max)
Returns true if any error were seen. Prints and clears the errors.

Parameters: out where to write the error message to max maximum number of messages to print (can be 0)

checkNext

public boolean checkNext(char ch)
Check if the next character matches a given character.

Parameters: ch The character to match against.

Returns: if the character read matches On a match, the position is advanced following that character.

clearErrors

public void clearErrors()

close

public void close()

eofError

public void eofError(String msg)

eofError

public void eofError(String message, int startLine, int startColumn)

error

public void error(char severity, String filename, int line, int column, String message)

error

public void error(char severity, String message)

error

public void error(String message)

fatal

public void fatal(String message)

getColumnNumber

public int getColumnNumber()

getErrors

public SourceError getErrors()

getLineNumber

public int getLineNumber()

getMessages

public SourceMessages getMessages()

getName

public String getName()

getPort

public final LineBufferedReader getPort()

isInteractive

public boolean isInteractive()

mark

public void mark()
Start tentative parsing. Must be followed by a reset.

peek

public int peek()

popNesting

public void popNesting(char save)
Exit a nested expression, reversing pushNesting

Parameters: save Saved values return by prior pushNesting

pushNesting

public char pushNesting(char promptChar)
Enter a nested expression. This is used in interactive mode to control whether to continue past end of line, depending on whether the expression is incomplete.

Parameters: promptChar Used in prompt string to indicate type of nesting.

Returns: The previous value of promptChar, to be passed to popNesting.

read

public int read()

read

public int read(char[] buf, int offset, int length)

readDigitsInBuffer

public static long readDigitsInBuffer(LineBufferedReader port, int radix)
Read digits, up to the first non-digit or the buffer limit

Returns: the digits seen as a non-negative long, or -1 on overflow

readOptionalExponent

public int readOptionalExponent()
Read an optional signed integer. If there is no integer in the input stream, return 1. For excessively large exponents, return Integer.MIN_VALUE or Integer.MAX_VALUE.

reset

public void reset()
Stop tentative parsing. Return to position where we called mark.

seenErrors

public boolean seenErrors()

setInteractive

public void setInteractive(boolean v)

setMessages

public void setMessages(SourceMessages messages)

skip

public void skip()

skip_quick

protected void skip_quick()

tokenBufferAppend

public void tokenBufferAppend(int ch)
Append one character to tokenBuffer, resizing it if need be.

unread

public void unread(int ch)

unread

protected void unread()

unread_quick

protected void unread_quick()