jeops.compiler.parser
Class Scanner

java.lang.Object
  |
  +--jeops.compiler.parser.Scanner

public class Scanner
extends java.lang.Object
implements TokenConstants

Class used in the parsing of the rules file. It's the first step in the converting of the rules into Java classes.

Version:
0.01 04.01.2000
Author:
Carlos Figueira Filho (csff@cin.ufpe.br)

Field Summary
private  java.lang.StringBuffer buffer
          The string buffer used in the scanning of the file.
private  int currentColumn
          The current column from the file.
private  int currentLine
          The current line from the file.
private  Token currentToken
          The current token.
private  char lastChar
          The last char read from the file.
private  Token lastNonWhiteSpaceToken
          The last non-whitespace token.
private  java.io.BufferedReader reader
          The reader used to get the characters from the rules file.
private static java.lang.String[] reservedWords
          The list of reserved words.
private  java.lang.String ruleFileName
          The name of the rules file.
private  int tokenColumn
          The column of the first character in the current token.
private  int tokenLine
          The line of the first character in the current token.
private static int[] typeReservedWords
          The token types of the reserved words.
 
Fields inherited from interface jeops.compiler.parser.TokenConstants
ACTIONS, ASTERISK, CLOSE_CURLY_BRACKET, COMMA, COMMENT, CONDITIONS, DECLARATIONS, DOT, EOF, EQUALS, ERROR, EXTENDS, IDENT, IMPLEMENTS, IMPORT, LOCALDECL, NONE_ABOVE, OPEN_CURLY_BRACKET, PACKAGE, PUBLIC, RULE, RULE_BASE, SEMICOLON, STRING, WHITE_SPACE
 
Constructor Summary
Scanner(java.lang.String ruleFileName)
          Class constructor.
 
Method Summary
private  int checkReserved(java.lang.String id)
          Checks whether a given identifier is a reserved word.
 int getCurrentColumn()
          Returns the current column from the file.
 int getCurrentLine()
          Returns the current line from the file.
 Token getLastNonWhiteSpaceToken()
          Returns the last non-whitespace token.
private  Token idOrReserved(java.lang.String str)
          Returns a token that can be an identifier or a reserved word.
static void main(java.lang.String[] args)
          Test method for this class.
 Token nextToken()
          Returns the next token from the file.
private  void readNextChar()
          Reads the next char in the file, storing it in "lastChar".
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

currentToken

private Token currentToken
The current token.

ruleFileName

private java.lang.String ruleFileName
The name of the rules file.

reader

private java.io.BufferedReader reader
The reader used to get the characters from the rules file.

buffer

private java.lang.StringBuffer buffer
The string buffer used in the scanning of the file.

lastChar

private char lastChar
The last char read from the file.

tokenLine

private int tokenLine
The line of the first character in the current token.

currentLine

private int currentLine
The current line from the file.

tokenColumn

private int tokenColumn
The column of the first character in the current token.

currentColumn

private int currentColumn
The current column from the file.

lastNonWhiteSpaceToken

private Token lastNonWhiteSpaceToken
The last non-whitespace token. A whitespace token is one of type COMMENT or WHITE_SPACE.

reservedWords

private static final java.lang.String[] reservedWords
The list of reserved words.

typeReservedWords

private static final int[] typeReservedWords
The token types of the reserved words.
Constructor Detail

Scanner

public Scanner(java.lang.String ruleFileName)
        throws java.io.IOException
Class constructor.
Parameters:
ruleFileName - the name of the rules file.
Throws:
java.io.IOException - if some IO error occurs.
Method Detail

checkReserved

private int checkReserved(java.lang.String id)
Checks whether a given identifier is a reserved word.
Parameters:
id - the identifier to be checked.
Returns:
the token type relative to the given word, if it's a reserved word, or -1 if it's not a reserved word.

getCurrentColumn

public int getCurrentColumn()
Returns the current column from the file.
Returns:
the current column from the file.

getCurrentLine

public int getCurrentLine()
Returns the current line from the file.
Returns:
the current line from the file.

getLastNonWhiteSpaceToken

public Token getLastNonWhiteSpaceToken()
Returns the last non-whitespace token. A whitespace token is one whose type is COMMENT or WHITE_SPACE.
Returns:
the last non-whitespace token.

idOrReserved

private Token idOrReserved(java.lang.String str)
Returns a token that can be an identifier or a reserved word.
Parameters:
str - the string that represents either an identifier or a reserved word.
Returns:
a token that can be an identifier or a reserved word.

main

public static void main(java.lang.String[] args)
Test method for this class.
Parameters:
args - command-line arguments. None is needed, but one can pass the rule file name for the scanning.

nextToken

public Token nextToken()
                throws java.io.IOException
Returns the next token from the file.
Returns:
the next token from the file.
Throws:
java.io.IOException - if some IO error occurs.

readNextChar

private void readNextChar()
                   throws java.io.IOException
Reads the next char in the file, storing it in "lastChar".
Throws:
java.io.IOException - if some IO error occurs.