Package net.aifusion.asn
Class Tokenizer
java.lang.Object
net.aifusion.asn.Tokenizer
Class to break input into tokens
- Author:
- Sharad Singhal
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGet the lookAhead tokenlookAhead
(int offset) Get the token at a given offset (positive or negative) from the current positionboolean
Check if the lookAhead token is of a given typeboolean
lookAheadIs
(TokenType t, int offset) Check if the lookahead token at a given offset matches a given typeboolean
Check if a list of tokens matches the incoming tokensnext()
Get the next token from the tokenizer, and advance its positionvoid
pop()
Pop the stack to reset the tokenizer positionvoid
push()
Push the current position of the tokenizer onto a stackvoid
reset()
Reset the tokenizerScan forward for a given token type (advancing the cursor to the token if found)Scan forward for a sequence of tokensSkip over a given token, and move past it
-
Constructor Details
-
Tokenizer
Create a tokenizer and tokenize the input file- Parameters:
inputFile
- input file to use
-
Tokenizer
Create a tokenizer and tokenize the input string- Parameters:
inputString
- - string to use
-
-
Method Details
-
push
public void push()Push the current position of the tokenizer onto a stack -
pop
public void pop()Pop the stack to reset the tokenizer position -
next
Get the next token from the tokenizer, and advance its position- Returns:
- - next token.
-
lookAhead
Get the lookAhead token- Returns:
- - token to be retrieved at the next call to next()
-
lookAhead
Get the token at a given offset (positive or negative) from the current position- Parameters:
offset
- - offset from the current position- Returns:
- - token at the location. EOF is returned if the location is past the end or the beginning
-
lookAheadIs
Check if the lookAhead token is of a given type- Parameters:
t
- - expected token type- Returns:
- - true if the lookAheadToken matches the expected type, false otherwise
-
lookAheadIs
Check if the lookahead token at a given offset matches a given type- Parameters:
t
- - expected token typeoffset
- - offset from the current position- Returns:
- true if the token at the given offset matches the expected type, false otherwise
-
reset
public void reset()Reset the tokenizer -
skipOver
Skip over a given token, and move past it- Parameters:
expected
- - expected token- Returns:
- - token value of the expected token
-
matches
Check if a list of tokens matches the incoming tokens- Parameters:
expected
- - array containing list of tokens- Returns:
- - true if the look-ahead matches the list, false otherwise
-
scanFor
Scan forward for a given token type (advancing the cursor to the token if found)- Parameters:
expected
- - expected token type- Returns:
- - expected token. Null if end is reached (position is not changed)
-
scanFor
Scan forward for a sequence of tokens- Parameters:
expected
- - array containing the expected tokens- Returns:
- - first token in the sequence. Null returned if not found (position is not changed)
-