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
-
buf
-
-
c
-
-
clev
-
-
CR
-
-
i
-
-
infile
-
-
languageMode
-
-
lastC
-
-
LF
-
-
line
-
-
PCR
-
-
pos
-
-
s
-
-
streamEmpty
-
-
Scanner(InputStream)
-
-
close()
- close the file if it isn't already closed
-
finalize()
- finalize closes the file if it isn't already closed
-
get(Parser)
- Get a token and place it in the appropriate variables in the parser.
-
getScannerMode()
- Get the scanner mode, 0=C, 1=HTML, 2=LISP.
-
nextStateC(Parser)
- Perform the state transition for scanning C++-like code
with nested comments, and dots allowed as part of identifiers.
-
nextStateHTML(Parser)
- Perform the state transition for scanning HTML
-
nextStateLISP(Parser)
- Perform the state transition for scanning LISP
-
setScannerMode(int)
- Set the scanner mode, 0=C, 1=HTML, 2=LISP.
CR
protected final char CR
LF
protected final char LF
PCR
protected final char PCR
streamEmpty
protected boolean streamEmpty
c
protected char c
lastC
protected char lastC
infile
protected InputStream infile
line
protected int line
pos
protected int pos
buf
protected StringBuffer buf
clev
protected int clev
s
protected int s
i
protected int i
languageMode
protected int languageMode
Scanner
public Scanner(InputStream stream)
close
public void close()
- close the file if it isn't already closed
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
setScannerMode
public void setScannerMode(int mode)
- Set the scanner mode, 0=C, 1=HTML, 2=LISP.
getScannerMode
public int getScannerMode()
- Get the scanner mode, 0=C, 1=HTML, 2=LISP.
get
public void get(Parser p)
- Get a token and place it in the appropriate variables in the parser.
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.
nextStateLISP
protected void nextStateLISP(Parser p)
- Perform the state transition for scanning LISP
nextStateHTML
protected void nextStateHTML(Parser p)
- Perform the state transition for scanning HTML
All Packages Class Hierarchy This Package Previous Next Index