public class lexer extends Object
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 token) this class provides simple error and warning routines and keeps a count of errors and warnings that is publicly accessible. It also provides basic preprocessing facilties, i.e. it does handle preprocessor directives such as #define, #undef, #include, etc. although it does not provide full C++ preprocessing This class is "static" (i.e., it has only static members and methods).
Modifier and Type | Field and Description |
---|---|
protected static Hashtable |
char_symbols
Table of single character symbols.
|
protected static boolean |
conditionalCompilation |
protected static int |
current_line
Current line number for use in error messages.
|
protected static int |
current_position
Character position in current line.
|
static String |
currentFile
current file name
|
static String |
currentPragmaPrefix
currently active pragma prefix
|
protected static Hashtable |
defines
Defined symbols (preprocessor)
|
protected static int |
EOF_CHAR
EOF constant.
|
protected static boolean |
in_string
Have we already read a '"' ?
|
protected static Hashtable |
java_keywords
Table of Java reserved names.
|
protected static Hashtable |
keywords
Table of keywords.
|
protected static Hashtable |
keywords_lower_case
Table of keywords, stored in lower case.
|
protected static StringBuffer |
line
Current line for use in error messages.
|
protected static int |
next_char
First and second character of lookahead.
|
protected static int |
next_char2 |
static int |
warning_count
Count of warnings issued so far
|
protected static boolean |
wide
Are we processing a wide char or string ?
|
Constructor and Description |
---|
lexer() |
Modifier and Type | Method and Description |
---|---|
protected static void |
advance()
Advance the scanner one character in the input stream.
|
static String |
checkIdentifier(String str)
Checks whether Identifier str is legal and returns it.
|
static int |
currentLine()
record information about the last lexical scope so that it can be
restored later
|
static void |
define(String symbol,
String value) |
static String |
defined(String symbol) |
protected static token |
do_symbol()
Process an identifier.
|
static void |
emit_error(String message)
Emit an error message.
|
static void |
emit_error(String message,
str_token t) |
static void |
emit_warn(String message)
Emit a warning message.
|
static void |
emit_warn(String message,
str_token t) |
protected static int |
find_single_char(int ch)
Try to look up a single character symbol, returns -1 for not found.
|
static PositionInfo |
getPosition()
return the current reading position
|
protected static boolean |
id_char(int ch)
Determine if a character is ok for the middle of an id.
|
protected static boolean |
id_start_char(int ch)
Determine if a character is ok to start an id.
|
static void |
init()
Initialize the scanner.
|
static boolean |
needsJavaEscape(Module m) |
static token |
next_token()
Return one token.
|
protected static void |
preprocess()
Preprocessor directives are handled here.
|
protected static token |
real_next_token()
The actual routine to return one token.
|
static void |
reset()
reset the scanner state
|
static void |
restorePosition(PositionInfo p) |
static boolean |
strictJavaEscapeCheck(String s)
called during the parse phase to catch clashes with
Java reserved words.
|
protected static void |
swallow_comment()
Handle swallowing up a comment.
|
static void |
undefine(String symbol) |
protected static int next_char
protected static int next_char2
protected static final int EOF_CHAR
protected static Hashtable keywords
protected static Hashtable keywords_lower_case
protected static Hashtable java_keywords
protected static Hashtable char_symbols
protected static Hashtable defines
protected static boolean conditionalCompilation
protected static int current_line
protected static StringBuffer line
protected static int current_position
protected static boolean in_string
protected static boolean wide
public static int warning_count
public static String currentPragmaPrefix
public static String currentFile
public static void reset()
public static void init() throws IOException
IOException
public static void undefine(String symbol)
public static int currentLine()
public static PositionInfo getPosition()
public static void restorePosition(PositionInfo p)
protected static void advance() throws IOException
IOException
public static void emit_error(String message)
message
- the message to print.public static void emit_warn(String message)
message
- the message to print.protected static boolean id_start_char(int ch)
ch
- the character in question.protected static boolean id_char(int ch)
ch
- the character in question.protected static int find_single_char(int ch)
ch
- the character in question.protected static void swallow_comment() throws IOException
IOException
protected static void preprocess() throws IOException
IOException
protected static token do_symbol() throws IOException
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 a str_token suitable for return by the scanner or null, if the string that was read expanded to a symbol that was #defined. In this case, the symbol is expanded in place
IOException
public static String checkIdentifier(String str)
str
- - the IDL identifier public static boolean strictJavaEscapeCheck(String s)
public static boolean needsJavaEscape(Module m)
public static token next_token() throws IOException
IOException
protected static token real_next_token() throws IOException
IOException
Copyright © 2017 JacORB. All rights reserved.