protected String getIdentifier() { final int startPosition = fCurrentPosition - 1; getChar(); if (fCurrentChar == '$') { getChar(); } while (((fCurrentChar >= 'a') && (fCurrentChar <= 'z')) || ((fCurrentChar >= 'A') && (fCurrentChar <= 'Z')) || ((fCurrentChar >= '0') && (fCurrentChar <= '9'))) { getChar(); } int endPosition = fCurrentPosition--; final int length = (--endPosition) - startPosition; if (length == 1) { return optimizedCurrentTokenSource1(startPosition, endPosition); } if (length == 2 && fInputString.charAt(startPosition) == '$') { return optimizedCurrentTokenSource2(startPosition, endPosition); } return fInputString.substring(startPosition, endPosition); }
protected void initialize(final String s) throws SyntaxError { initializeNullScanner(); fInputString = s; if (s != null) { getNextToken(); } }
/** * Parse a Java <code>int</code> value. * * @return * @throws SyntaxError */ protected int getInteger() throws SyntaxError { final String number = getIntegerString(); int intValue = 0; try { intValue = Integer.parseInt(number, 10); } catch (final NumberFormatException e) { throwSyntaxError("Number format error (not an int type): " + number, number.length()); } getNextToken(); return intValue; }
/** * Verify the length of the input string and get the next character from the input string. If the current position * is greater than the input length, set current character to SPACE and token to TT_EOF. * */ protected void getChar() { if (isValidPosition()) { getNextChar(); return; } fCurrentPosition = fInputString.length + 1; fCurrentChar = ' '; fToken = TT_EOF; }
while (isValidPosition()) { getNextChar(); fToken = TT_EOF; if (isOperatorCharacters()) { fOperList = getOperator(); fToken = TT_OPERATOR; return; if (isValidPosition()) { if (charAtPosition() == '*') { getComment(); continue; case '[': fToken = TT_ARGUMENTS_OPEN; skipWhitespace(); if (isValidPosition()) { if (charAtPosition() == '[') { fCurrentPosition++; fToken = TT_PARTOPEN; case '_': fToken = TT_BLANK; if (isValidPosition()) { if (charAtPosition() == '_') { fCurrentPosition++; if (isValidPosition()) { if (charAtPosition() == '_') {
protected StringBuffer getStringBuffer() throws SyntaxError { final StringBuffer ident = new StringBuffer(); getChar(); throwSyntaxError("string -" + ident.toString() + "- contains no character."); getChar(); throwSyntaxError("string - unknown character after back-slash."); getChar(); } else { throwSyntaxError("string -" + ident.toString() + "- not closed."); getChar();
getNextChar(); fToken = TT_EOF; fOperList = getOperator(); fToken = TT_OPERATOR; return; if (fInputString.length() > fCurrentPosition) { if (fInputString.charAt(fCurrentPosition) == '*') { getComment(); continue; throwSyntaxError("unexpected character: '" + fCurrentChar + "'"); throwSyntaxError("token not found");
/** * Throw syntax error. * * @param error the error * @param errorLength the error length * @throws org.matheclipse.parser.client.SyntaxError the syntax error */ protected void throwSyntaxError( final String error, final int errorLength ) throws SyntaxError { throw new SyntaxError( fCurrentPosition - errorLength, rowCount, fCurrentPosition - fCurrentColumnStartPosition, getErrorLine(), error, errorLength ); }
fOperList = getOperator(); fToken = TT_OPERATOR; return; throwSyntaxError( "Comment doesn't end with '*)' (open multiline comment)" ); throwSyntaxError( "unexpected character: '" + fCurrentChar + "'" ); throwSyntaxError( "token not found" );
/** * Parse a Java <code>string</code> from the digits <code>0,1,2,3,4,5,6,7,8,9</code>. * * @return */ protected String getIntegerString() { int startPosition = fCurrentPosition - 1; getChar(); while (Character.isDigit(fCurrentChar)) { getChar(); } int endPosition = fCurrentPosition--; return new String(fInputString, startPosition, (--endPosition) - startPosition); }
try { while (true) { if (charAtPosition() == '*' && fInputString[fCurrentPosition + 1] == ')') { fCurrentPosition++; fCurrentPosition++; } else if (charAtPosition() == '(' && fInputString[fCurrentPosition + 1] == '*') { fCurrentPosition++; fCurrentPosition++; level++; continue; } else if (charAtPosition() == '\n') { fCurrentPosition++; fRowCounter++; throwSyntaxError("Comment doesn't end with '*)' (open multiline comment)");
/** * Initialize Scanner without a math-expression. */ public Scanner() { initializeNullScanner(); }
if (isValidPosition()) { fCurrentChar = fInputString[fCurrentPosition++]; } else { throwSyntaxError("string - end of string not reached."); throwSyntaxError("string -" + ident.toString() + "- contains no character."); while (fCurrentChar != '"' && isValidPosition()) { if (isValidPosition()) { fCurrentChar = fInputString[fCurrentPosition++]; if (isValidPosition() && fInputString[fCurrentPosition] == '\n') { throwSyntaxError("string - unknown character after back-slash."); default: throwSyntaxError("string - unknown character after back-slash."); throwSyntaxError("string - unknown character after back-slash."); if (isValidPosition()) { fCurrentChar = fInputString[fCurrentPosition++]; } else { throwSyntaxError("string - end of string not reached."); throwSyntaxError("string -" + ident.toString() + "- not closed."); if (isValidPosition()) { fCurrentChar = fInputString[fCurrentPosition++];
private void getComment() { int startPosition = fCurrentPosition; int level = 0; fCurrentPosition++; // read multiline comment until end of file: try { while (true) { if (fInputString.charAt(fCurrentPosition) == '*' && fInputString.charAt(fCurrentPosition + 1) == ')') { fCurrentPosition++; fCurrentPosition++; if (level == 0) { break; } level--; continue; } else if (fInputString.charAt(fCurrentPosition) == '(' && fInputString.charAt(fCurrentPosition + 1) == '*') { fCurrentPosition++; fCurrentPosition++; level++; continue; } fCurrentPosition++; } } catch (IndexOutOfBoundsException ioobe) { fCurrentPosition = startPosition; throwSyntaxError("Comment doesn't end with '*)' (open multiline comment)"); } }
/** * Verify the length of the input string and get the next character from the * input string. If the current position is greater than the input length, set * current character to SPACE and token to TT_EOF. * */ private void getChar() { if (fInputString.length() > fCurrentPosition) { getNextChar(); return; } fCurrentPosition = fInputString.length() + 1; fCurrentChar = ' '; fToken = TT_EOF; }
final StringBuffer ident = new StringBuffer(); getChar(); throwSyntaxError( "string -" + ident.toString() + "- contains no character." ); getChar(); throwSyntaxError( "string - unknown character after back-slash." ); getChar(); throwSyntaxError( "string -" + ident.toString() + "- not closed." ); getChar();
/** * Throw syntax error. * * @param error the error * @throws org.matheclipse.parser.client.SyntaxError the syntax error */ protected void throwSyntaxError( final String error ) throws SyntaxError { throw new SyntaxError( fCurrentPosition - 1, rowCount, fCurrentPosition - fCurrentColumnStartPosition, getErrorLine(), error, 1 ); }
getChar(); if (firstCh == '0') { switch (fCurrentChar) { numFormat = 2; startPosition = fCurrentPosition; getChar(); break; case 'B': // binary format numFormat = 2; startPosition = fCurrentPosition; getChar(); break; case 'o': // octal format numFormat = 8; startPosition = fCurrentPosition; getChar(); break; case 'O': // octal format numFormat = 8; startPosition = fCurrentPosition; getChar(); break; case 'x': // hexadecimal format numFormat = 16; startPosition = fCurrentPosition; getChar(); break; case 'X': // hexadecimal format
/** * Initialize Scanner without a math-expression * */ public Scanner() { initializeNullScanner(); }
/** * Gets the identifier. * * @return the identifier */ protected String getIdentifier() { final int startPosition = fCurrentPosition - 1; getChar(); if ( fCurrentChar == '$' ) { getChar(); } while ( ((fCurrentChar >= 'a') && (fCurrentChar <= 'z')) || ((fCurrentChar >= 'A') && (fCurrentChar <= 'Z')) || ((fCurrentChar >= '0') && (fCurrentChar <= '9')) ) { getChar(); } int endPosition = fCurrentPosition--; final int length = (--endPosition) - startPosition; if ( length == 1 ) { return optimizedCurrentTokenSource1( startPosition, endPosition ); } if ( length == 2 && fInputString.charAt( startPosition ) == '$' ) { return optimizedCurrentTokenSource2( startPosition, endPosition ); } return fInputString.substring( startPosition, endPosition ); }