att.grappa
Class Lexer

java.lang.Object
  extended by att.grappa.Lexer

public class Lexer
extends java.lang.Object

A class for doing lexical analysis of dot formatted input.

Version:
1.2, 21 Aug 2005; Copyright 1996 - 2005 by AT&T Corp.
Author:
John Mocenigo, Research @ AT&T Labs

Field Summary
private  java.util.Hashtable char_symbols
           
private  java.lang.StringBuffer cmnstrbuf
          common StringBuffer (suggested by Ginny Travers (bbn.com))
private  int current_line
          Current line number for use in error messages.
private  int current_position
          Character position in current line.
private static int EOF_CHAR
          EOF constant.
private  int error_count
          Count of total errors detected so far.
private  java.io.PrintWriter errWriter
           
private  boolean haveId
          needed to handle anonymous subgraphs since parser has no precedence
private  java.io.Reader inReader
           
private  java.util.Hashtable keywords
          hash tables to hold symbols
private  int next_char
          First character of lookahead.
private  int next_char2
          Second character of lookahead.
private  int old_char
          needed for retreating
private  int old_position
           
(package private)  boolean retreated
           
private  int warning_count
          Count of warnings issued so far
 
Constructor Summary
Lexer(java.io.Reader input, java.io.PrintWriter error)
          Create an instance of Lexer that reads from input and sends error messages to error.
 
Method Summary
 void advance()
          Advance the scanner one character in the input stream.
private  Symbol do_html_string()
          Swallow up an html-like string.
private  Symbol do_id()
          Process an identifier.
private  Symbol do_quote_string()
          Swallow up a quote string.
private  void emit_error(java.lang.String message)
          Emit an error message.
private  void emit_warn(java.lang.String message)
          Emit a warning message.
private  int find_single_char(int ch)
          Try to look up a single character symbol, returns -1 for not found.
 java.lang.String getLocation()
          Get the current location in the form "[line_number(character_offser)]".
static boolean id_char(char ch)
          Check if character is a valid id character;
static boolean id_char(int ch)
          Check if character is a valid id character;
 void init()
          Initialize internal tables and read two characters of input for look-ahead purposes.
 Symbol next_token(int debugLevel)
          Return one Symbol.
private  Symbol real_next_token()
          The actual routine to return one Symbol.
private  void retreat()
           
private  void swallow_comment()
          Handle swallowing up a comment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

next_char

private int next_char
First character of lookahead. Set to '\n' initially (needed for initial 2 calls to advance())


next_char2

private int next_char2
Second character of lookahead. Set to '\n' initially (needed for initial 2 calls to advance())


current_line

private int current_line
Current line number for use in error messages. Set to -1 to account for next_char/next_char2 initialization


current_position

private int current_position
Character position in current line.


EOF_CHAR

private static final int EOF_CHAR
EOF constant.

See Also:
Constant Field Values

haveId

private boolean haveId
needed to handle anonymous subgraphs since parser has no precedence


old_char

private int old_char
needed for retreating


old_position

private int old_position

retreated

boolean retreated

error_count

private int error_count
Count of total errors detected so far.


warning_count

private int warning_count
Count of warnings issued so far


keywords

private java.util.Hashtable keywords
hash tables to hold symbols


char_symbols

private java.util.Hashtable char_symbols

inReader

private java.io.Reader inReader

errWriter

private java.io.PrintWriter errWriter

cmnstrbuf

private java.lang.StringBuffer cmnstrbuf
common StringBuffer (suggested by Ginny Travers (bbn.com))

Constructor Detail

Lexer

public Lexer(java.io.Reader input,
             java.io.PrintWriter error)
      throws java.lang.IllegalArgumentException
Create an instance of Lexer that reads from input and sends error messages to error.

Parameters:
input - input Reader object
error - error output Writer object
Throws:
java.lang.IllegalArgumentException - whenever input is null
Method Detail

init

public void init()
          throws java.io.IOException
Initialize internal tables and read two characters of input for look-ahead purposes.

Throws:
java.io.IOException - if advance() does
See Also:
advance()

advance

public void advance()
             throws java.io.IOException
Advance the scanner one character in the input stream. This moves next_char2 to next_char and then reads a new next_char2.

Throws:
java.io.IOException - whenever a problem reading from input is encountered

retreat

private void retreat()

emit_error

private void emit_error(java.lang.String message)
Emit an error message. The message will be marked with both the current line number and the position in the line. Error messages are printed on print stream passed to Lexer (if any) and a GraphParserException is thrown.

Parameters:
message - the message to print.

getLocation

public java.lang.String getLocation()
Get the current location in the form "[line_number(character_offser)]".

Returns:
info about the current position in the input

emit_warn

private void emit_warn(java.lang.String message)
Emit a warning message. The message will be marked with both the current line number and the position in the line. Messages are printed on print stream passed to Lexer (if any).

Parameters:
message - the message to print.

id_char

public static boolean id_char(int ch)
Check if character is a valid id character;

Parameters:
ch - the character in question.

id_char

public static boolean id_char(char ch)
Check if character is a valid id character;

Parameters:
ch - the character in question.

find_single_char

private int find_single_char(int ch)
Try to look up a single character symbol, returns -1 for not found.

Parameters:
ch - the character in question.

swallow_comment

private void swallow_comment()
                      throws java.io.IOException
Handle swallowing up a comment. Both old style C and new style C++ comments are handled.

Throws:
java.io.IOException

do_quote_string

private Symbol do_quote_string()
                        throws java.io.IOException
Swallow up a quote string. Quote strings begin with a double quote and include all characters up to the first occurrence of another double quote (there is no way to include a double quote inside a quote string). The routine returns a Symbol object suitable for return by the scanner.

Throws:
java.io.IOException

do_html_string

private Symbol do_html_string()
                       throws java.io.IOException
Swallow up an html-like string. Html-like strings begin with a '<' and include all characters up to the first matching occurrence of a '>' The routine returns a Symbol object suitable for return by the scanner.

Throws:
java.io.IOException

do_id

private Symbol do_id()
              throws java.io.IOException
Process an identifier. Identifiers begin with a letter, underscore, or dollar sign, which is followed by zero or more letters, numbers, underscores or dollar signs. This routine returns an Symbol suitable for return by the scanner.

Throws:
java.io.IOException

real_next_token

private Symbol real_next_token()
                        throws java.io.IOException
The actual routine to return one Symbol. This is normally called from next_token(), but for debugging purposes can be called indirectly from debug_next_token().

Throws:
java.io.IOException

next_token

public Symbol next_token(int debugLevel)
                  throws java.io.IOException
Return one Symbol. This method is the main external interface to the scanner. It consumes sufficient characters to determine the next input Symbol and returns it.

Throws:
java.io.IOException - if advance() does