de.upb.swt.mcie.parser
Class Scanner

java.lang.Object
  extended by de.upb.swt.mcie.parser.Scanner

public class Scanner
extends java.lang.Object

This class implements the scanner. The patterns for the different tokens are partly defined as regular expressions in order to make changes as easy as possible. Only tokens consisting of characters that are no letters or digits are explicitly checked in the code.

The symbol # indicates a line comment, which extends to the end of this line. The text starting at # up to the end of the line will be ignored by the scanner.

Author:
Ekkart Kindler, kindler@upb.de

Field Summary
private static java.util.regex.Pattern AF
          The Pattern for the AF operator.
private static java.util.regex.Pattern AG
          The Pattern for the AG operator.
private static java.util.regex.Pattern AND
          The Pattern for the AND operation.
private static java.util.regex.Pattern AR
          The Pattern for the AR operator.
private static java.util.regex.Pattern AU
          The Pattern for the AU operator.
private static java.util.regex.Pattern AX
          The Pattern for the AX operator.
private  int column
          The column number of the current position in the reader.
private  Token current
          The current token.
private  char currentChar
          The character at the current position in the reader.
private static java.util.regex.Pattern EF
          The Pattern for the EF operator.
private static java.util.regex.Pattern EG
          The Pattern for the EG operator.
private static java.util.regex.Pattern ER
          The Pattern for the ER operator.
private static java.util.regex.Pattern EU
          The Pattern for the EU operator.
private static java.util.regex.Pattern EX
          The Pattern for the EX operator.
private static java.util.regex.Pattern FALSE
          The Pattern for the constant false.
private  int line
          The line number of the current position in the reader.
private static char LINE_SEPARATOR
          Defines the character that is used for separating lines.
private static java.util.regex.Pattern NOT
          The Pattern for the NOT operation.
private static java.util.regex.Pattern OR
          The Pattern for the OR operation.
private  Token previous
          The previous token.
private  java.io.Reader reader
          The reader with the text on which the scanner works.
private static java.util.regex.Pattern TRUE
          The Pattern for the constant true.
 
Constructor Summary
Scanner(java.io.Reader reader)
          Constructs a scanner for the given Reader.
 
Method Summary
private  char getNextChar()
          Returns the next character of the character sequence and increments the position.
 Token getNextToken()
          Returns the next token.
private  char getNextTrueChar()
          Returns the first character of the text in the reader that is not a white space.
 void revert()
          Reverts to the previously read token.
private  char skipLineComment()
          Moves on to the next non-white space character after a line comment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_SEPARATOR

private static final char LINE_SEPARATOR
Defines the character that is used for separating lines. This character could be read from the system properties. But '\n' works fine for Windows, Unix and Linux (there might be problems with older MAC OS versions). TODO read the line separator from the system properties.

See Also:
Constant Field Values

NOT

private static final java.util.regex.Pattern NOT
The Pattern for the NOT operation. Note that this defines the pattern for the textual representation of the not operation only. In addition the scanner accepts ! as the symbol for not.


AND

private static final java.util.regex.Pattern AND
The Pattern for the AND operation. Note that this defines the pattern for the textual representation of the and operation only. In addition the scanner accepts & as the symbol for and.


OR

private static final java.util.regex.Pattern OR
The Pattern for the OR operation. Note that this defines the pattern for the textual representation of the or operation only. In addition the scanner accepts | as the symbol for or.


EX

private static final java.util.regex.Pattern EX
The Pattern for the EX operator.


AX

private static final java.util.regex.Pattern AX
The Pattern for the AX operator.


EG

private static final java.util.regex.Pattern EG
The Pattern for the EG operator.


AG

private static final java.util.regex.Pattern AG
The Pattern for the AG operator.


EF

private static final java.util.regex.Pattern EF
The Pattern for the EF operator.


AF

private static final java.util.regex.Pattern AF
The Pattern for the AF operator.


EU

private static final java.util.regex.Pattern EU
The Pattern for the EU operator.


AU

private static final java.util.regex.Pattern AU
The Pattern for the AU operator.


ER

private static final java.util.regex.Pattern ER
The Pattern for the ER operator.


AR

private static final java.util.regex.Pattern AR
The Pattern for the AR operator.


TRUE

private static final java.util.regex.Pattern TRUE
The Pattern for the constant true.


FALSE

private static final java.util.regex.Pattern FALSE
The Pattern for the constant false.


reader

private java.io.Reader reader
The reader with the text on which the scanner works.


currentChar

private char currentChar
The character at the current position in the reader.


line

private int line
The line number of the current position in the reader.


column

private int column
The column number of the current position in the reader.


previous

private Token previous
The previous token. Storing this token is necessary to implement a one token look ahead.


current

private Token current
The current token.

Constructor Detail

Scanner

public Scanner(java.io.Reader reader)
        throws java.io.IOException
Constructs a scanner for the given Reader.

Parameters:
reader - the reader with the text to be scanned
Throws:
java.io.IOException - if an IO problem occurs
Method Detail

getNextChar

private char getNextChar()
                  throws java.io.IOException
Returns the next character of the character sequence and increments the position. If the end of the text is reached, it returns Character.MIN_VALUE.

Returns:
the next character
Throws:
java.io.IOException - if an IO problem occurs

getNextTrueChar

private char getNextTrueChar()
                      throws java.io.IOException
Returns the first character of the text in the reader that is not a white space. If there is a non white space character at the current position, this character is returned without advancing the position. If the end of the text is reached, it returns Character.MIN_VALUE.

Returns:
the first non white space character, starting from the current position
Throws:
java.io.IOException - if an IO problem occurs

skipLineComment

private char skipLineComment()
                      throws java.io.IOException
Moves on to the next non-white space character after a line comment. If there is no such character, because the end of the buffer is reached, the method returns Character.MIN_VALUE.

Returns:
next non-white space character after a line comment
Throws:
java.io.IOException - if an IO problem occurs

revert

public void revert()
Reverts to the previously read token. Note that calling this method has an effect only once. The scanner can not revert by several steps (the scanner has look-ahead one only).


getNextToken

public Token getNextToken()
                   throws java.io.IOException
Returns the next token.

Returns:
the next token
Throws:
java.io.IOException - if an IO problem occurs