java_cup
Class lexer

java.lang.Object
  extended by java_cup.lexer

public class lexer
extends java.lang.Object

This class implements a small scanner (aka lexical analyzer or lexer) for the JavaCup specification. This scanner reads characters from standard input (System.in) and returns integers corresponding to the terminal number of the next Symbol. Once end of input is reached the EOF Symbol is returned on every subsequent call.

Symbols currently returned include:

    Symbol        Constant Returned     Symbol        Constant Returned
    ------        -----------------     ------        -----------------
    "package"     PACKAGE               "import"      IMPORT 
    "code"        CODE                  "action"      ACTION 
    "parser"      PARSER                "terminal"    TERMINAL
    "non"         NON                   "init"        INIT 
    "scan"        SCAN                  "with"        WITH
    "start"       START                 "precedence"  PRECEDENCE
    "left"        LEFT            "right"       RIGHT
    "nonassoc"    NONASSOC                "%prec        PRECENT_PREC  
      [           LBRACK                  ]           RBRACK
      ;           SEMI 
      ,           COMMA                   *           STAR 
      .           DOT                     :           COLON
      ::=         COLON_COLON_EQUALS      |           BAR
    identifier    ID                    {:...:}       CODE_STRING
    "nonterminal" NONTERMINAL
  
All symbol constants are defined in sym.java which is generated by JavaCup from parser.cup.

In addition to the scanner proper (called first via init() then with next_token() to get each Symbol) this class provides simple error and warning routines and keeps a count of errors and warnings that is publicly accessible.

This class is "static" (i.e., it has only static members and methods).

Version:
last updated: 7/3/96
Author:
Frank Flannery

Field Summary
static int error_count
          Count of total errors detected so far.
static int warning_count
          Count of warnings issued so far
 
Method Summary
static Symbol debug_next_token()
          Debugging version of next_token().
static void emit_error(java.lang.String message)
          Emit an error message.
static void emit_warn(java.lang.String message)
          Emit a warning message.
static void init()
          Initialize the scanner.
static Symbol next_token()
          Return one Symbol.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

error_count

public static int error_count
Count of total errors detected so far.


warning_count

public static int warning_count
Count of warnings issued so far

Method Detail

init

public static void init()
                 throws java.io.IOException
Initialize the scanner. This sets up the keywords and char_symbols tables and reads the first two characters of lookahead.

Throws:
java.io.IOException

emit_error

public static 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 standard error (System.err).

Parameters:
message - the message to print.

emit_warn

public static 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 standard error (System.err).

Parameters:
message - the message to print.

next_token

public static Symbol next_token()
                         throws java.io.IOException
Return one Symbol. This is the main external interface to the scanner. It consumes sufficient characters to determine the next input Symbol and returns it. To help with debugging, this routine actually calls real_next_token() which does the work. If you need to debug the parser, this can be changed to call debug_next_token() which prints a debugging message before returning the Symbol.

Throws:
java.io.IOException

debug_next_token

public static Symbol debug_next_token()
                               throws java.io.IOException
Debugging version of next_token(). This routine calls the real scanning routine, prints a message on System.out indicating what the Symbol is, then returns it.

Throws:
java.io.IOException