Fields Summary |
---|
public static final int | STARTSTART token. |
public static final int | ENDEND token. |
public static final int | IDID token. |
public static final int | WHITESPACEWHITESPACE token. |
public static final int | DIGITDIGIT (numeric) token. |
public static final int | ALPHAALPHA (alphabetic) token. |
public static final int | BACKSLASHBACKSLASH (escaping) token. |
public static final int | QUOTESingle QUOTE token. |
public static final int | ATAT sign token. |
public static final int | SPSPACE token. |
public static final int | HTHT (Horizontal tab) token. |
public static final int | COLONCOLON token. |
public static final int | STARSTAR (asterisk) token. |
public static final int | DOLLARDOLLAR token. |
public static final int | PLUSPLUS token. |
public static final int | POUNDPOUND token. |
public static final int | MINUSMINUS token. |
public static final int | DOUBLEQUOTEDOUBLEQUOTE token. |
public static final int | TILDETILDE token. |
public static final int | BACK_QUOTEBACK_QUOTE token. |
public static final int | NULLNULL token. |
public static final int | EQUALSEQUALS (equals sign) token. |
public static final int | SEMICOLONSEMICOLON token. |
public static final int | SLASHForward SLASH token. |
public static final int | L_SQUARE_BRACKETL_SQUARE_BRACKET (left square bracket) token. |
public static final int | R_SQUARE_BRACKETR_SQUARE_BRACKET (right square bracket) token. |
public static final int | R_CURLYR_CURLY (right curly bracket) token. |
public static final int | L_CURLYL_CURLY (left curly bracket) token. |
public static final int | HATHAT (carot) token. |
public static final int | BARVeritcal BAR token. |
public static final int | DOTDOT (period) token. |
public static final int | EXCLAMATIONEXCLAMATION token. |
public static final int | LPARENLPAREN (left paren) token. |
public static final int | RPARENRPAREN (right paren) token. |
public static final int | GREATER_THANGREATER_THAN token. |
public static final int | LESS_THANLESS_THAN token. |
public static final int | PERCENTPERCENT token. |
public static final int | QUESTIONQUESTION mark token. |
public static final int | ANDAND (ampersand) token. |
public static final int | UNDERSCOREUNDERSCPRE token. |
protected static Hashtable | globalSymbolTableGlobal symbol table for intermediate elements. |
protected static Hashtable | lexerTablesLexical rules tables. |
protected Hashtable | currentLexerCurrent elements of current lexing operation. |
protected String | currentLexerNameName of the current Lexer. |
protected Token | currentMatchCurrent matched token. |
Methods Summary |
---|
public void | SPorHT()Checks for space or horiizontal tab.
The tokens are consumed if present.
All parsing errors are ignored.(if any)
try {
while (lookAhead(0) == ' " || lookAhead(0) == '\t")
consume(1);
} catch (ParseException ex) {
// Ignore
}
|
protected void | addKeyword(java.lang.String name, int value)Adds a new keyword and value pair.
globalSymbolTable = new Hashtable();
lexerTables = new Hashtable();
// System.out.println("addKeyword " + name + " value = " + value);
// new Exception().printStackTrace();
Integer val = new Integer(value);
currentLexer.put(name, val);
if (! globalSymbolTable.containsKey(val))
globalSymbolTable.put(val, name);
|
protected java.util.Hashtable | addLexer(java.lang.String lexerName)Adds a new Lexer. If the named lexer
does not exist anew hashtable is allocated.
currentLexer = (Hashtable) lexerTables.get(lexerName);
if (currentLexer == null) {
currentLexer = new Hashtable();
lexerTables.put(lexerName, currentLexer);
}
return currentLexer;
|
public java.lang.String | byteStringNoComma()Gets a token up to the next comma or end of line.
The end of line or terminating comma are not
consumed. If a parsing exception occurs, the consumed
characters are returned.
StringBuffer retval = new StringBuffer();
try {
char next;
while ((next = lookAhead(0)) != '\0") {
if (next == '\n" || next == ',") {
break;
} else {
consume(1);
retval.append(next);
}
}
} catch (ParseException ex) {
}
return retval.toString();
|
public java.lang.String | byteStringNoSemicolon()Gets a token up to the next semicolon or end of line.
The end of line or terminating semicolon are not
consumed. If a parsing exception occurs, the consumed
characters are returned.
StringBuffer retval = new StringBuffer();
try {
char next;
while ((next = lookAhead(0)) != '\0") {
if (next == '\n" || next == ';") {
break;
} else {
consume(1);
retval.append(next);
}
}
} catch (ParseException ex) {
return retval.toString();
}
return retval.toString();
|
public static java.lang.String | charAsString(char ch)Converts a character to a string.
return new Character(ch).toString();
|
public java.lang.String | charAsString(int nchars)Lookahead in the inputBuffer for n chars and return as a string.
Do not consume the input. In the event of a parsing
error return the characters that could be consumed.
StringBuffer retval = new StringBuffer();
try {
for (int i = 0; i < nchars; i++) {
retval.append(lookAhead(i));
}
return retval.toString();
} catch (ParseException ex) {
return retval.toString();
}
|
public java.lang.String | comment()Gets a comment string.
Consumes all characters between left and right
parens. Back slashed escaped characters are preserved.
StringBuffer retval = new StringBuffer();
if (lookAhead(0) != '(")
return null;
consume(1);
while (true) {
char next = getNextChar();
if (next == ')") {
break;
} else if (next == '\0") {
throw new ParseException(this.buffer + " :unexpected EOL",
this.ptr);
} else if (next == '\\") {
retval.append(next);
next = getNextChar();
if (next == '\0")
throw new ParseException(this.buffer +
" : unexpected EOL", this.ptr);
retval.append(next);
} else {
retval.append(next);
}
}
return retval.toString();
|
public ParseException | createParseException()Creates a parse exception.
return new ParseException(this.buffer, this.ptr);
|
public java.lang.String | getBuffer()Gets the buffer. return this.buffer;
|
public java.lang.String | getNextId()Gets the next id.
return ttoken();
|
public Token | getNextToken()Gets the next token.
return this.currentMatch;
|
public int | getPtr()Gets the read pointer. return this.ptr;
|
public java.lang.String | getRest()Gets the rest of the string buffer.
if (ptr >= buffer.length())
return null;
else
return buffer.substring(ptr);
|
public java.lang.String | getString(char c)Gets the sub-String until the requested character is
encountered.
int savedPtr = ptr;
StringBuffer retval = new StringBuffer();
while (true) {
char next = lookAhead(0);
if (next == '\0") {
ParseException exception = new ParseException
(this.buffer +
"unexpected EOL", this.ptr);
ptr = savedPtr;
throw exception;
} else if (next == c) {
consume(1);
break;
} else if (next == '\\") {
consume(1);
char nextchar = lookAhead(0);
if (nextchar == '\0") {
ParseException exception =
new ParseException(this.buffer +
"unexpected EOL", this.ptr);
ptr = savedPtr;
throw exception;
} else {
consume(1);
retval.append(nextchar);
}
} else {
consume(1);
retval.append(next);
}
}
return retval.toString();
|
public java.lang.String | lookupToken(int value)Looks up a requested token.
if (value > START) {
return (String) globalSymbolTable.get(new Integer(value));
} else {
Character ch = new Character((char)value);
return ch.toString();
}
|
public int | markInputPosition()Mark the position for backtracking.
return ptr;
|
public Token | match(int tok)Match the given token or throw an exception, if no such token
can be matched.
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"match " + tok);
}
if (tok > START && tok < END) {
if (tok == ID) {
// Generic ID sought.
if (!startsId())
throw new ParseException(buffer + "\nID expected", ptr);
String id = getNextId();
this.currentMatch = new Token();
this.currentMatch.tokenValue = id;
this.currentMatch.tokenType = ID;
} else {
String nexttok = getNextId();
Integer cur =
(Integer) currentLexer.get(nexttok.toUpperCase());
if (cur == null || cur.intValue() != tok)
throw new ParseException
(buffer + "\nUnexpected Token : "+
nexttok, ptr);
this.currentMatch = new Token();
this.currentMatch.tokenValue = nexttok;
this.currentMatch.tokenType = tok;
}
} else if (tok > END) {
// Character classes.
char next = lookAhead(0);
if (tok == DIGIT) {
if (! isDigit(next))
throw new
ParseException(buffer + "\nExpecting DIGIT", ptr);
this.currentMatch = new Token();
this.currentMatch.tokenValue =
new StringBuffer().append(next).toString();
this.currentMatch.tokenType = tok;
consume(1);
} else if (tok == ALPHA) {
if (! isAlpha(next))
throw new ParseException
(buffer + "\nExpecting ALPHA", ptr);
this.currentMatch = new Token();
this.currentMatch.tokenValue =
new StringBuffer().append(next).toString();
this.currentMatch.tokenType = tok;
consume(1);
}
} else {
// This is a direct character spec.
Character ch = new Character((char)tok);
char next = lookAhead(0);
if (next == ch.charValue()) {
this.currentMatch = new Token();
this.currentMatch.tokenValue =
new StringBuffer().append(ch.charValue()).toString();
this.currentMatch.tokenType = tok;
consume(1);
} else throw new
ParseException(buffer + "\nExpecting " +
ch.charValue(), ptr);
}
return this.currentMatch;
|
public java.lang.String | number()Gets and consumes the next number.
Only digits are included in the returned string.
StringBuffer retval = new StringBuffer();
if (! isDigit(lookAhead(0))) {
throw new ParseException
(buffer + ": Unexpected token at " +lookAhead(0), ptr);
}
retval.append(lookAhead(0));
consume(1);
while (true) {
char next = lookAhead(0);
if (isDigit(next)) {
retval.append(next);
consume(1);
} else
break;
}
return retval.toString();
|
public java.lang.String | peekNextId()Peeks at the next id, but doesn't move the buffer pointer forward.
int oldPtr = ptr;
String retval = ttoken();
savedPtr = ptr;
ptr = oldPtr;
return retval;
|
public Token | peekNextToken()Looks ahead for one token.
return (Token) peekNextToken(1).elementAt(0);
|
public java.util.Vector | peekNextToken(int ntokens)Peeks at the next token.
int old = ptr;
Vector retval = new Vector();
for (int i = 0; i < ntokens; i++) {
Token tok = new Token();
if (startsId()) {
String id = ttoken();
tok.tokenValue = id;
if (currentLexer.containsKey(id.toUpperCase())) {
Integer type = (Integer) currentLexer.get(id.toUpperCase());
tok.tokenType = type.intValue();
} else tok.tokenType = ID;
} else {
char nextChar = getNextChar();
tok.tokenValue =
new StringBuffer().append(nextChar).toString();
if (isAlpha(nextChar)) {
tok.tokenType = ALPHA;
} else if (isDigit(nextChar)) {
tok.tokenType = DIGIT;
} else tok.tokenType = (int) nextChar;
}
retval.addElement(tok);
}
savedPtr = ptr;
ptr = old;
return retval;
|
public java.lang.String | quotedString()Gets a quoted string.
Read all the characters between double
quotes into the next textual token.
Preserve all back slash escaped characters.
StringBuffer retval = new StringBuffer();
if (lookAhead(0) != '\"")
return null;
consume(1);
while (true) {
char next = getNextChar();
if (next == '\"")
break;
else if (next == '\\") {
retval.append(next);
next = getNextChar();
retval.append(next);
} else {
retval.append(next);
}
}
return retval.toString();
|
public void | rewindInputPosition(int position)Rewinds the input pointer to the marked position.
this.ptr = position;
|
public abstract void | selectLexer(java.lang.String lexerName)Selects a specific lexer by name.
|
public boolean | startsId()Checks for staring IDs.
try {
char nextChar = lookAhead(0);
return isValidChar(nextChar);
} catch (ParseException ex) {
return false;
}
|
public java.lang.String | ttoken()Gets the next textual token.
StringBuffer nextId = new StringBuffer();
try {
while (hasMoreChars()) {
char nextChar = lookAhead(0);
// println("nextChar = " + nextChar);
if (isValidChar(nextChar)) {
consume(1);
nextId.append(nextChar);
} else break;
}
return nextId.toString();
} catch (ParseException ex) {
return nextId.toString();
}
|
public java.lang.String | ttokenAllowSpace()Gets the next textual token including embedded
white space
StringBuffer nextId = new StringBuffer();
try {
while (hasMoreChars()) {
char nextChar = lookAhead(0);
// println("nextChar = " + nextChar);
if (isAlpha(nextChar) ||
isDigit(nextChar) ||
nextChar == '_" ||
nextChar == '+" ||
nextChar == '-" ||
nextChar == '!" ||
nextChar == '`" ||
nextChar == '\'" ||
nextChar == '~" ||
nextChar == '." ||
nextChar == ' " ||
nextChar == '\t" ||
nextChar == '*") {
nextId.append(nextChar);
consume(1);
} else break;
}
return nextId.toString();
} catch (ParseException ex) {
return nextId.toString();
}
|