de.interactive_instruments.ShapeChange.Ocl
Class Lexer

java.lang.Object
  extended by de.interactive_instruments.ShapeChange.Ocl.Lexer

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.

Version:
0.1
Author:
Reinhard Erstling (c) interactive instruments GmbH, Bonn, Germany
See Also:
Token

Nested Class Summary
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 Summary
Lexer(Readable inStream)
          The Lexer object is created with a Readable to fetch the input characters from.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Lexer

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.

Parameters:
inStream - Readable to fetch the input from.
Method Detail

fetchToken

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.

Returns:
Next Token

unfetchToken

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.

Parameters:
token - Token to be unfetched.

captureState

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().

Returns:
Checkpoint object

releaseState

public void releaseState(Lexer.Checkpoint chp)

This method releases the checkpoint once captured by means of method captureState().

Parameters:
chp -

restoreState

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().

Parameters:
chp - Former state given as a Checkpoint object


Copyright © 2015. All rights reserved.