Package org.openjdk.asmtools.jasm
Class Scanner
- java.lang.Object
-
- org.openjdk.asmtools.jasm.ParseBase
-
- org.openjdk.asmtools.jasm.Scanner
-
public class Scanner extends ParseBase
A Scanner for Jasm tokens. Errors are reported to the environment object.The scanner keeps track of the current token, the value of the current token (if any), and the start position of the current token.
The scan() method advances the scanner to the next token in the input.
The match() method is used to quickly match opening brackets (ie: '(', '{', or '[') with their closing counter part. This is useful during error recovery.
The compiler treats either "\n", "\r" or "\r\n" as the end of a line.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classScanner.SyntaxErrorSyntaxError is the generic error thrown for parsing problems.
-
Field Summary
Fields Modifier and Type Field Description private char[]bufferprotected intchThe current characterprotected charcharValueprivate intcountprotected java.lang.StringdocCommentprotected doubledoubleValueprivate java.util.function.Predicate<java.lang.Integer>escapingAllowedprotected floatfloatValueprotected java.lang.StringidValueprotected EnvironmentinInput streamprotected booleaninBitsprotected intintValueprotected longlongValueprivate java.util.function.Predicate<java.lang.Integer>noFuncprotected intposThe position of the current tokenprotected intprevPosThe position of the previous tokenprotected intradixprotected intsignprotected java.lang.StringstringValueprotected JasmTokens.TokentokenCurrent tokenprivate java.util.function.Predicate<java.lang.Integer>yesAndProcessFunc
-
Constructor Summary
Constructors Modifier Constructor Description protectedScanner(Environment env)main constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.StringbufferString()protected voidcheck(JasmTokens.Token t)Checks a token, throws an exception if not the sameprotected booleancheckTokenIdent()Check the token may be identifierprotected voiddebugScan(java.lang.String dbstr)protected voidexpect(JasmTokens.Token t)Expects a token, scans the next token or throws an exception.static booleanisUCDigit(int ch)Returns true if the character is a unicode digit.static booleanisUCLetter(int ch)Returns true if the character is a Unicode letter.private voidputCh(int ch)(package private) static java.lang.StringreadableConstant(int t)protected voidscan()scan Scan the next token.private voidscanCPRef()Scan a decimal at this pointprivate java.lang.StringscanDocComment()Scan a doc comment.private intscanEscapeChar()Scan an escape character.private voidscanIdentifier(char[] prefix)Scan an Identifier.protected voidscanModuleStatement()private voidscanNumber()Scan a number.private voidscanReal()Scan a float.private voidscanString()Scan a string.private voidskipComment()Scan a comment.protected voidxscan()-
Methods inherited from class org.openjdk.asmtools.jasm.ParseBase
debugStr, enableDebug, init
-
-
-
-
Field Detail
-
in
protected Environment in
Input stream
-
ch
protected int ch
The current character
-
token
protected JasmTokens.Token token
Current token
-
pos
protected int pos
The position of the current token
-
charValue
protected char charValue
-
intValue
protected int intValue
-
longValue
protected long longValue
-
floatValue
protected float floatValue
-
doubleValue
protected double doubleValue
-
stringValue
protected java.lang.String stringValue
-
idValue
protected java.lang.String idValue
-
radix
protected int radix
-
docComment
protected java.lang.String docComment
-
count
private int count
-
buffer
private char[] buffer
-
escapingAllowed
private java.util.function.Predicate<java.lang.Integer> escapingAllowed
-
prevPos
protected int prevPos
The position of the previous token
-
sign
protected int sign
-
inBits
protected boolean inBits
-
noFunc
private java.util.function.Predicate<java.lang.Integer> noFunc
-
yesAndProcessFunc
private java.util.function.Predicate<java.lang.Integer> yesAndProcessFunc
-
-
Constructor Detail
-
Scanner
protected Scanner(Environment env) throws java.io.IOException
main constructor. Create a scanner to scan an input stream.- Throws:
java.io.IOException
-
-
Method Detail
-
scanModuleStatement
protected void scanModuleStatement() throws java.io.IOException- Throws:
java.io.IOException
-
scan
protected void scan() throws java.io.IOExceptionscan Scan the next token.- Throws:
java.io.IOException
-
checkTokenIdent
protected final boolean checkTokenIdent()
Check the token may be identifier
-
readableConstant
static java.lang.String readableConstant(int t)
-
expect
protected final void expect(JasmTokens.Token t) throws Scanner.SyntaxError, java.io.IOException
Expects a token, scans the next token or throws an exception.- Throws:
Scanner.SyntaxErrorjava.io.IOException
-
check
protected final void check(JasmTokens.Token t) throws Scanner.SyntaxError, java.io.IOException
Checks a token, throws an exception if not the same- Throws:
Scanner.SyntaxErrorjava.io.IOException
-
putCh
private void putCh(int ch)
-
bufferString
private java.lang.String bufferString()
-
isUCDigit
public static boolean isUCDigit(int ch)
Returns true if the character is a unicode digit.- Parameters:
ch- the character to be checked
-
isUCLetter
public static boolean isUCLetter(int ch)
Returns true if the character is a Unicode letter.- Parameters:
ch- the character to be checked
-
skipComment
private void skipComment() throws java.io.IOExceptionScan a comment. This method should be called once the initial /, * and the next character have been read.- Throws:
java.io.IOException
-
scanDocComment
private java.lang.String scanDocComment() throws java.io.IOExceptionScan a doc comment. This method should be called once the initial /, * and * have been read. It gathers the content of the comment (without leading spaces and '*'s) in the string buffer.- Throws:
java.io.IOException
-
scanCPRef
private void scanCPRef() throws java.io.IOExceptionScan a decimal at this point- Throws:
java.io.IOException
-
scanNumber
private void scanNumber() throws java.io.IOExceptionScan a number. The first digit of the number should be the current character. We may be scanning hex, decimal, or octal at this point- Throws:
java.io.IOException
-
scanReal
private void scanReal() throws java.io.IOExceptionScan a float. We are either looking at the decimal, or we have already seen it and put it into the buffer. We haven't seen an exponent. Scan a float. Should be called with the current character is either the 'e', 'E' or '.'- Throws:
java.io.IOException
-
scanEscapeChar
private int scanEscapeChar() throws java.io.IOExceptionScan an escape character.- Returns:
- the character or '\\'
- Throws:
java.io.IOException
-
scanString
private void scanString() throws java.io.IOExceptionScan a string. The current character should be the opening " of the string.- Throws:
java.io.IOException
-
scanIdentifier
private void scanIdentifier(char[] prefix) throws java.io.IOExceptionScan an Identifier. The current character should be the first character of the identifier.- Throws:
java.io.IOException
-
xscan
protected final void xscan() throws java.io.IOException- Throws:
java.io.IOException
-
-