public class Lexer extends Object
A Lexer object reads characters from an input stream, generating a sequence of Token objects, which correspond to low level constructs of OCL (actually, a subset of OCL). For the definition of Token objects see class Token.
Token
Modifier and Type | Class and Description |
---|---|
static class |
Lexer.Checkpoint
A Checkpoint encapsulates a state of a Lexer object, which you can
capture and restore by means of the captureState and restoreState
methods.
|
Constructor and Description |
---|
Lexer(Readable inStream)
The Lexer object is created with a Readable to fetch the input characters
from.
|
Modifier and Type | Method and Description |
---|---|
Lexer.Checkpoint |
captureState()
This method returns the current state of Token delivery of the Lexer
encapsulated in a Checkpoint object.
|
de.interactive_instruments.ShapeChange.Ocl.Token |
fetchToken()
You fetch Tokens from the Lexer object one by one by means of the
fetchToken function.
|
void |
releaseState(Lexer.Checkpoint chp)
This method releases the checkpoint once captured by means of method
captureState().
|
void |
restoreState(Lexer.Checkpoint chp)
The restoreState method restores the state of Token delivery of the
Lexer to a former state once captured by means of the method
captureState().
|
void |
unfetchToken(de.interactive_instruments.ShapeChange.Ocl.Token token)
Tokens fetched in excess can be pushed back to the Lexer object by
means of the unfetchToken function.
|
public Lexer(Readable inStream)
The Lexer object is created with a Readable to fetch the input characters from. It is important that the input is delivered by the Readable in single character buffers reflecting lines of the original input. The Token stream returned from the Lexer will refer to line numbers and column on these, which are subsequently used in the parser to generate appropriate error messages.
inStream
- Readable to fetch the input from.public de.interactive_instruments.ShapeChange.Ocl.Token fetchToken()
You fetch Tokens from the Lexer object one by one by means of the fetchToken function. See the definition of the Token class to understand the nature of Tokens. The last Token conceptually received is an Operator token of Type END_OF_TEXT. All further invocations of fetchToken will result in this kind of Token object.
If there are "unfetched" Tokens, these will be returned prior to the ones recognized from the input stream. Unfetched Tokens come in a last-in-first-out sequence.
public void unfetchToken(de.interactive_instruments.ShapeChange.Ocl.Token token)
Tokens fetched in excess can be pushed back to the Lexer object by means of the unfetchToken function. An arbitrary number of tokens can be unfetched.
Warning: Generally, no check can be done, whether the Tokens pushed back are the same as previously delivered. Do not regard this to be a feature. If a Checkpoint is active, however, recording of delivered Tokens takes place. In this case an assert makes indeed sure that Tokens are unfetched exactly as delivered.
token
- Token to be unfetched.public Lexer.Checkpoint captureState()
This method returns the current state of Token delivery of the Lexer encapsulated in a Checkpoint object. You can later restore to this former state by means of the restoreState() method. If you do not restore you need to release the Checkpoint by calling releaseState().
public void releaseState(Lexer.Checkpoint chp)
This method releases the checkpoint once captured by means of method captureState().
chp
- public void restoreState(Lexer.Checkpoint chp)
The restoreState method restores the state of Token delivery of the Lexer to a former state once captured by means of the method captureState().
chp
- Former state given as a Checkpoint objectCopyright © 2017. All rights reserved.