All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class parse.Scanner

java.lang.Object
   |
   +----parse.Scanner

public class Scanner
extends Object
A Scanner breaks a text file up into tokens. It is initialized with a filename, a string representing the next token each time get() is called, and closes the file when close() is called, or when it is finalized. The string returned by get() is empty if there are no more tokens in the file, the file is empty, or the file doesn't exist. whitespace is ignored, as are comments which start with // and go to the end of the line, or start and end with /* and * / and can be nested. A token starting with a digit,".","+",or "-" is treated like a C number. A token starting with a letter or "_" is treated like a C identifier. Everything else, such as "++" is broken up into one-character tokens. A // causes the rest of the line to be ignored, including any /* or * / that might be on that line. Comment symbols within double-quoted strings are considered part of the string. An end of line will also end a string, but not put the quote mark at the end. a /* can also be terminated by the end of the file. Within a comment block starting with /* the comment symbol // is not ignored. A string starts with a quote and ends with either a quote or end of line. Strings are returned without the enclosing quotes. Identifiers are case sensitive and include "abc", "abc.def.ghi", "true".

This code is (c) 1996 Leemon Baird <leemon@cs.cmu.edu>, http://www.cs.cmu.edu/~baird
The source and object code may be redistributed freely. If the code is modified, please state so in the comments.

Version:
1.0, 28 March 96
Author:
Leemon Baird

Variable Index

 o buf
 o c
 o clev
 o CR
 o i
 o infile
 o languageMode
 o lastC
 o LF
 o line
 o PCR
 o pos
 o s
 o streamEmpty

Constructor Index

 o Scanner(InputStream)

Method Index

 o close()
close the file if it isn't already closed
 o finalize()
finalize closes the file if it isn't already closed
 o get(Parser)
Get a token and place it in the appropriate variables in the parser.
 o getScannerMode()
Get the scanner mode, 0=C, 1=HTML, 2=LISP.
 o nextStateC(Parser)
Perform the state transition for scanning C++-like code with nested comments, and dots allowed as part of identifiers.
 o nextStateHTML(Parser)
Perform the state transition for scanning HTML
 o nextStateLISP(Parser)
Perform the state transition for scanning LISP
 o setScannerMode(int)
Set the scanner mode, 0=C, 1=HTML, 2=LISP.

Variables

 o CR
 protected final char CR
 o LF
 protected final char LF
 o PCR
 protected final char PCR
 o streamEmpty
 protected boolean streamEmpty
 o c
 protected char c
 o lastC
 protected char lastC
 o infile
 protected InputStream infile
 o line
 protected int line
 o pos
 protected int pos
 o buf
 protected StringBuffer buf
 o clev
 protected int clev
 o s
 protected int s
 o i
 protected int i
 o languageMode
 protected int languageMode

Constructors

 o Scanner
 public Scanner(InputStream stream)

Methods

 o close
 public void close()
close the file if it isn't already closed

 o finalize
 public void finalize() throws Throwable
finalize closes the file if it isn't already closed

Throws: Throwable
an error happened during finalization.
Overrides:
finalize in class Object
 o setScannerMode
 public void setScannerMode(int mode)
Set the scanner mode, 0=C, 1=HTML, 2=LISP.

 o getScannerMode
 public int getScannerMode()
Get the scanner mode, 0=C, 1=HTML, 2=LISP.

 o get
 public void get(Parser p)
Get a token and place it in the appropriate variables in the parser.

 o nextStateC
 protected void nextStateC(Parser p)
Perform the state transition for scanning C++-like code with nested comments, and dots allowed as part of identifiers.

 o nextStateLISP
 protected void nextStateLISP(Parser p)
Perform the state transition for scanning LISP

 o nextStateHTML
 protected void nextStateHTML(Parser p)
Perform the state transition for scanning HTML


All Packages  Class Hierarchy  This Package  Previous  Next  Index