Java Code Examples for java.io.StreamTokenizer#TT_NUMBER

The following examples show how to use java.io.StreamTokenizer#TT_NUMBER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileSourceBase.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Read a word, a symbol or EOF, or generate a parse error. If this is EOF, the string "EOF" is returned.
 */
protected String getWordOrSymbolOrEof() throws IOException {
	final int tok = st.nextToken();

	if (tok == StreamTokenizer.TT_NUMBER || tok == QUOTE_CHAR) {
		parseError("expecting a word or symbol, " + gotWhat(tok));
	}

	if (tok == StreamTokenizer.TT_WORD) {
		return st.sval;
	} else if (tok == StreamTokenizer.TT_EOF) {
		return "EOF";
	} else {
		return Character.toString((char) tok);
	}
}
 
Example 2
Source File: FileSourceBase.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Read a word or symbol or string or generate a parse error.
 */
protected String getWordOrSymbolOrString() throws IOException {
	final int tok = st.nextToken();

	if (tok == StreamTokenizer.TT_NUMBER || tok == StreamTokenizer.TT_EOF) {
		parseError("expecting a word, symbol or string, " + gotWhat(tok));
	}

	if (tok == QUOTE_CHAR) { return st.sval; }

	if (tok == StreamTokenizer.TT_WORD) {
		return st.sval;
	} else {
		return Character.toString((char) tok);
	}
}
 
Example 3
Source File: FunctionParameterBeginExpressionState.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
public ComputedAttributeParserState parse(StreamTokenizer st) throws IOException, ParseException
{
    ComputedAttributeParserState nextState = null;
    while(nextState == null && st.ttype != StreamTokenizer.TT_EOF)
    {
        int nextToken = st.nextToken();
        if (nextToken != StreamTokenizer.TT_EOL && nextToken != StreamTokenizer.TT_EOF)
        {
            switch(nextToken)
            {
                case '(':
                    nextState = new ExpressionBeginState(this.getParser());
                    break;
                case StreamTokenizer.TT_NUMBER:
                    throw new ParseException("unexpected number "+st.nval+" in expression "+this.getParser().getFormula()+" in "+this.getParser().getDiagnosticMessage());
                case StreamTokenizer.TT_WORD:
                    throw new ParseException("unexpected word "+st.sval+" in expression "+this.getParser().getFormula()+" in "+this.getParser().getDiagnosticMessage());
                default:
                    char ch = (char)st.ttype;
                    throw createUnexpectedCharacterException(ch, "(");
            }
        }
    }
    return nextState;
}
 
Example 4
Source File: Token.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public String toMessage() {
    switch(ttype) {
    case StreamTokenizer.TT_EOL:
        return "\"EOL\"";
    case StreamTokenizer.TT_EOF:
        return "\"EOF\"";
    case StreamTokenizer.TT_NUMBER:
        return "NUMBER";
    case StreamTokenizer.TT_WORD:
        if (sval == null) {
            return "IDENTIFIER";
        } else {
            return "IDENTIFIER " + sval;
        }
    default:
        if (ttype == (int)'"') {
            String msg = "QUOTED STRING";
            if (sval != null)
                msg = msg + " \"" + sval + "\"";
            return msg;
        } else {
            return "CHARACTER \'" + (char)ttype + "\'";
        }
    }
}
 
Example 5
Source File: Token.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public String toMessage() {
    switch(ttype) {
    case StreamTokenizer.TT_EOL:
        return "\"EOL\"";
    case StreamTokenizer.TT_EOF:
        return "\"EOF\"";
    case StreamTokenizer.TT_NUMBER:
        return "NUMBER";
    case StreamTokenizer.TT_WORD:
        if (sval == null) {
            return "IDENTIFIER";
        } else {
            return "IDENTIFIER " + sval;
        }
    default:
        if (ttype == (int)'"') {
            String msg = "QUOTED STRING";
            if (sval != null)
                msg = msg + " \"" + sval + "\"";
            return msg;
        } else {
            return "CHARACTER \'" + (char)ttype + "\'";
        }
    }
}
 
Example 6
Source File: Parser.java    From big-c with Apache License 2.0 6 votes vote down vote up
Token next() throws IOException {
  int type = tok.nextToken();
  switch (type) {
    case StreamTokenizer.TT_EOF:
    case StreamTokenizer.TT_EOL:
      return null;
    case StreamTokenizer.TT_NUMBER:
      return new NumToken(tok.nval);
    case StreamTokenizer.TT_WORD:
      return new StrToken(TType.IDENT, tok.sval);
    case '"':
      return new StrToken(TType.QUOT, tok.sval);
    default:
      switch (type) {
        case ',':
          return new Token(TType.COMMA);
        case '(':
          return new Token(TType.LPAREN);
        case ')':
          return new Token(TType.RPAREN);
        default:
          throw new IOException("Unexpected: " + type);
      }
  }
}
 
Example 7
Source File: Token.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public String toMessage() {
    switch(ttype) {
    case StreamTokenizer.TT_EOL:
        return "\"EOL\"";
    case StreamTokenizer.TT_EOF:
        return "\"EOF\"";
    case StreamTokenizer.TT_NUMBER:
        return "NUMBER";
    case StreamTokenizer.TT_WORD:
        if (sval == null) {
            return "IDENTIFIER";
        } else {
            return "IDENTIFIER " + sval;
        }
    default:
        if (ttype == (int)'"') {
            String msg = "QUOTED STRING";
            if (sval != null)
                msg = msg + " \"" + sval + "\"";
            return msg;
        } else {
            return "CHARACTER \'" + (char)ttype + "\'";
        }
    }
}
 
Example 8
Source File: Token.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public String toMessage() {
    switch(ttype) {
    case StreamTokenizer.TT_EOL:
        return "\"EOL\"";
    case StreamTokenizer.TT_EOF:
        return "\"EOF\"";
    case StreamTokenizer.TT_NUMBER:
        return "NUMBER";
    case StreamTokenizer.TT_WORD:
        if (sval == null) {
            return "IDENTIFIER";
        } else {
            return "IDENTIFIER " + sval;
        }
    default:
        if (ttype == (int)'"') {
            String msg = "QUOTED STRING";
            if (sval != null)
                msg = msg + " \"" + sval + "\"";
            return msg;
        } else {
            return "CHARACTER \'" + (char)ttype + "\'";
        }
    }
}
 
Example 9
Source File: Parser.java    From big-c with Apache License 2.0 6 votes vote down vote up
Token next() throws IOException {
  int type = tok.nextToken();
  switch (type) {
    case StreamTokenizer.TT_EOF:
    case StreamTokenizer.TT_EOL:
      return null;
    case StreamTokenizer.TT_NUMBER:
      return new NumToken(tok.nval);
    case StreamTokenizer.TT_WORD:
      return new StrToken(TType.IDENT, tok.sval);
    case '"':
      return new StrToken(TType.QUOT, tok.sval);
    default:
      switch (type) {
        case ',':
          return new Token(TType.COMMA);
        case '(':
          return new Token(TType.LPAREN);
        case ')':
          return new Token(TType.RPAREN);
        default:
          throw new IOException("Unexpected: " + type);
      }
  }
}
 
Example 10
Source File: Token.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public String toString() {
    StringBuilder sb = new StringBuilder();
    switch(ttype) {
    case StreamTokenizer.TT_EOL:
        sb.append("ttype=TT_EOL");
        break;
    case StreamTokenizer.TT_EOF:
        sb.append("ttype=TT_EOF");
        break;
    case StreamTokenizer.TT_NUMBER:
        sb.append("ttype=TT_NUM,").append("nval="+nval);
        break;
    case StreamTokenizer.TT_WORD:
        if (sval == null) {
            sb.append("ttype=TT_WORD:IDENTIFIER");
        } else {
            sb.append("ttype=TT_WORD:").append("sval="+sval);
        }
        break;
    default:
        if (ttype == (int)'"') {
            sb.append("ttype=TT_STRING:").append("sval="+sval);
        } else {
            sb.append("ttype=TT_CHAR:").append((char)ttype);
        }
        break;
    }
    return sb.toString();
}
 
Example 11
Source File: TestProto.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Read a string from the command file
 *
 * @return string found in file
 * @exception 	IOException 	error reading file
 */
private String getString() throws IOException
{
	int val = tkn.nextToken();
	if (val == StreamTokenizer.TT_NUMBER)
	{
		System.err.println("Expecting word, got " + tkn.nval + " on line " + tkn.lineno());
		System.exit(1);
	}
	return tkn.sval;
}
 
Example 12
Source File: Token.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public String toString() {
    StringBuilder sb = new StringBuilder();
    switch(ttype) {
    case StreamTokenizer.TT_EOL:
        sb.append("ttype=TT_EOL");
        break;
    case StreamTokenizer.TT_EOF:
        sb.append("ttype=TT_EOF");
        break;
    case StreamTokenizer.TT_NUMBER:
        sb.append("ttype=TT_NUM,").append("nval="+nval);
        break;
    case StreamTokenizer.TT_WORD:
        if (sval == null) {
            sb.append("ttype=TT_WORD:IDENTIFIER");
        } else {
            sb.append("ttype=TT_WORD:").append("sval="+sval);
        }
        break;
    default:
        if (ttype == (int)'"') {
            sb.append("ttype=TT_STRING:").append("sval="+sval);
        } else {
            sb.append("ttype=TT_CHAR:").append((char)ttype);
        }
        break;
    }
    return sb.toString();
}
 
Example 13
Source File: TestProto.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Read a string from the command file
 *
 * @return string found in file
 * @exception 	IOException 	error reading file
 */
private String getString() throws IOException
{
	int val = tkn.nextToken();
	if (val == StreamTokenizer.TT_NUMBER)
	{
		System.err.println("Expecting word, got " + tkn.nval + " on line " + tkn.lineno());
		System.exit(1);
	}
	return tkn.sval;
}
 
Example 14
Source File: HexTileset.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
public void loadFromFile(String filename) throws IOException {
    long startTime = System.currentTimeMillis();
    // make input stream for board
    Reader r = new BufferedReader(new FileReader(new MegaMekFile(Configuration.hexesDir(), filename).getFile()));
    // read board, looking for "size"
    StreamTokenizer st = new StreamTokenizer(r);
    st.eolIsSignificant(true);
    st.commentChar('#');
    st.quoteChar('"');
    st.wordChars('_', '_');
    while (st.nextToken() != StreamTokenizer.TT_EOF) {
        int elevation = 0;
        // int levity = 0;
        String terrain = null;
        String theme = null;
        String imageName = null;
        if ((st.ttype == StreamTokenizer.TT_WORD)
                && (st.sval.equals("base") || st.sval.equals("super") || st.sval.equals("ortho"))) { //$NON-NLS-3$ //$NON-NLS-2$
            boolean bas = st.sval.equals("base"); //$NON-NLS-1$
            boolean sup = st.sval.equals("super"); //$NON-NLS-1$
            boolean ort = st.sval.equals("ortho"); //$NON-NLS-1$

            if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                elevation = (int) st.nval;
            } else {
                elevation = ITerrain.WILDCARD;
            }
            st.nextToken();
            terrain = st.sval;
            st.nextToken();
            theme = st.sval;
            themes.add(theme);
            st.nextToken();
            imageName = st.sval;
            // add to list
            if (bas) {
                bases.add(new HexEntry(new Hex(elevation, terrain, theme), imageName));
            }
            if (sup) {
                supers.add(new HexEntry(new Hex(elevation, terrain, theme), imageName));
            }
            if (ort) {
                orthos.add(new HexEntry(new Hex(elevation, terrain, theme), imageName));
            }
        } else if ((st.ttype == StreamTokenizer.TT_WORD) && st.sval.equals("include")) {
            st.nextToken();
            incDepth++;
            if (incDepth < 100) {
                String incFile = st.sval;
                System.out.println("Including " + incFile); //$NON-NLS-1$
                loadFromFile(incFile);
            }
        }
        // else if((st.ttype == StreamTokenizer.TT_WORD) &&
        // st.sval.equals("ortho")){}
    }
    r.close();
    themes.add(TRANSPARENT_THEME);
    long endTime = System.currentTimeMillis();
    
    System.out.println("hexTileset: loaded " + bases.size() + " base images"); //$NON-NLS-2$ //$NON-NLS-2$
    System.out.println("hexTileset: loaded " + supers.size() + " super images"); //$NON-NLS-2$ //$NON-NLS-2$
    System.out.println("hexTileset: loaded " + orthos.size() + " ortho images"); //$NON-NLS-2$ //$NON-NLS-2$
    if (incDepth == 0) {
        System.out.println("hexTileset loaded in " + (endTime - startTime) + "ms.");
    }
    incDepth--;
}
 
Example 15
Source File: XYZApp.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/** Create a Chemical model by parsing an input stream */
XYZChemModel(InputStream is) throws Exception {
    this();
    StreamTokenizer st = new StreamTokenizer(
            new BufferedReader(new InputStreamReader(is, "UTF-8")));
    st.eolIsSignificant(true);
    st.commentChar('#');

    try {
        scan:
        while (true) {
            switch (st.nextToken()) {
                case StreamTokenizer.TT_EOF:
                    break scan;
                default:
                    break;
                case StreamTokenizer.TT_WORD:
                    String name = st.sval;
                    double x = 0,
                     y = 0,
                     z = 0;
                    if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                        x = st.nval;
                        if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                            y = st.nval;
                            if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                                z = st.nval;
                            }
                        }
                    }
                    addVert(name, (float) x, (float) y, (float) z);
                    while (st.ttype != StreamTokenizer.TT_EOL
                            && st.ttype != StreamTokenizer.TT_EOF) {
                        st.nextToken();
                    }

            }   // end Switch

        }  // end while

        is.close();

    } // end Try
    catch (IOException e) {
    }

    if (st.ttype != StreamTokenizer.TT_EOF) {
        throw new Exception(st.toString());
    }

}
 
Example 16
Source File: XYZApp.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/** Create a Chemical model by parsing an input stream */
XYZChemModel(InputStream is) throws Exception {
    this();
    StreamTokenizer st = new StreamTokenizer(
            new BufferedReader(new InputStreamReader(is, "UTF-8")));
    st.eolIsSignificant(true);
    st.commentChar('#');

    try {
        scan:
        while (true) {
            switch (st.nextToken()) {
                case StreamTokenizer.TT_EOF:
                    break scan;
                default:
                    break;
                case StreamTokenizer.TT_WORD:
                    String name = st.sval;
                    double x = 0,
                     y = 0,
                     z = 0;
                    if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                        x = st.nval;
                        if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                            y = st.nval;
                            if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                                z = st.nval;
                            }
                        }
                    }
                    addVert(name, (float) x, (float) y, (float) z);
                    while (st.ttype != StreamTokenizer.TT_EOL
                            && st.ttype != StreamTokenizer.TT_EOF) {
                        st.nextToken();
                    }

            }   // end Switch

        }  // end while

        is.close();

    } // end Try
    catch (IOException e) {
    }

    if (st.ttype != StreamTokenizer.TT_EOF) {
        throw new Exception(st.toString());
    }

}
 
Example 17
Source File: FileSourceBase.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Read a word or symbol or string or EOL/EOF or generate a parse error. If EOL is read the "EOL" string is
 * returned. If EOF is read the "EOF" string is returned.
 *
 * @return A string.
 */
protected String getWordOrSymbolOrStringOrEolOrEof() throws IOException {
	final int tok = st.nextToken();

	if (tok == StreamTokenizer.TT_NUMBER) {
		parseError("expecting a word, symbol or string, " + gotWhat(tok));
	}

	if (tok == QUOTE_CHAR) { return st.sval; }

	if (tok == StreamTokenizer.TT_WORD) { return st.sval; }

	if (tok == StreamTokenizer.TT_EOF) { return "EOF"; }

	if (tok == StreamTokenizer.TT_EOL) { return "EOL"; }

	return Character.toString((char) tok);
}
 
Example 18
Source File: XYZApp.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/** Create a Chemical model by parsing an input stream */
XYZChemModel(InputStream is) throws Exception {
    this();
    StreamTokenizer st = new StreamTokenizer(
            new BufferedReader(new InputStreamReader(is, "UTF-8")));
    st.eolIsSignificant(true);
    st.commentChar('#');

    try {
        scan:
        while (true) {
            switch (st.nextToken()) {
                case StreamTokenizer.TT_EOF:
                    break scan;
                default:
                    break;
                case StreamTokenizer.TT_WORD:
                    String name = st.sval;
                    double x = 0,
                     y = 0,
                     z = 0;
                    if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                        x = st.nval;
                        if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                            y = st.nval;
                            if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
                                z = st.nval;
                            }
                        }
                    }
                    addVert(name, (float) x, (float) y, (float) z);
                    while (st.ttype != StreamTokenizer.TT_EOL
                            && st.ttype != StreamTokenizer.TT_EOF) {
                        st.nextToken();
                    }

            }   // end Switch

        }  // end while

        is.close();

    } // end Try
    catch (IOException e) {
    }

    if (st.ttype != StreamTokenizer.TT_EOF) {
        throw new Exception(st.toString());
    }

}
 
Example 19
Source File: XMLQuery.java    From oodt with Apache License 2.0 4 votes vote down vote up
/**
   * Lexical analyzer - return next token from instance of StreamTokenizer.
   */
 private String getNextTokenFromStream () {
          int c, c2;
   String rc;
          try {
              switch (c=tokens.nextToken()) {
                  case StreamTokenizer.TT_EOF:
                      rc = "";
	break;
                  case StreamTokenizer.TT_EOL:
                      rc = "";
	break;
                  case StreamTokenizer.TT_NUMBER: // not currently set
	rc = "";
	break;
                  case StreamTokenizer.TT_WORD:
                      rc = tokens.sval;
	break;
                  case '(':
                  case ')':
	rc = String.valueOf((char)c);
	break;
                  case '"':
                  case '\'':
                      rc = tokens.sval;
	break;
                  case '=':
                      rc = "EQ";
	break;
                  case '&':
                      rc = "AND";
	break;
                  case '|':
                      rc = "OR";
	break;
                  case '<':
                      c2 = tokens.nextToken();
                      if (c2 == '=') {
		rc = "LE";
                      } else {
		tokens.pushBack();
		rc = "LT";
                      }
	break;
                  case '>':
                      c2 = tokens.nextToken();
                      if (c2 == '=') {
		rc = "GE";
                      } else {
                              tokens.pushBack();
		rc = "GT";
                      }
	break;
                  case '!':
                      c2 = tokens.nextToken();
                      if (c2 == '=') {
		rc = "NE";
                      } else {
                              tokens.pushBack();
		rc = "NOT";
                      }
	break;
                  default:
                      rc = "";
                  }
              } catch (IOException e1) {
	rc = "";
}
   return rc;
 }
 
Example 20
Source File: ArffLoader.java    From incubator-samoa with Apache License 2.0 4 votes vote down vote up
/**
 * Reads a dense instance from the file.
 *
 * @return the instance
 */
public Instance readInstanceDense() {
  Instance instance = newDenseInstance(this.instanceInformation.numAttributes());
  //System.out.println(this.instanceInformation.numAttributes());
  int numAttribute = 0;
  try {
    while (numAttribute == 0 && streamTokenizer.ttype != StreamTokenizer.TT_EOF) {
      //For each line
      while (streamTokenizer.ttype != StreamTokenizer.TT_EOL
              && streamTokenizer.ttype != StreamTokenizer.TT_EOF) {
        //For each item
        if (streamTokenizer.ttype == StreamTokenizer.TT_NUMBER) {
          //System.out.println(streamTokenizer.nval + "Num ");
          instance.setValue(numAttribute, streamTokenizer.nval);//this.setValue(instance, numAttribute, streamTokenizer.nval, true);
          ++numAttribute;

        } else if (streamTokenizer.sval != null && (streamTokenizer.ttype == StreamTokenizer.TT_WORD
                || streamTokenizer.ttype == 34 || streamTokenizer.ttype == 39)) {
          //System.out.println(streamTokenizer.sval + "Str");
          boolean isNumeric = this.auxAttributes.get(numAttribute).isNumeric();
          double value;
          if ("?".equals(streamTokenizer.sval)) {
            value = Double.NaN; //Utils.missingValue();
          } else if (isNumeric == true) {
            value = Double.valueOf(streamTokenizer.sval).doubleValue();
          } else {
            value = this.auxAttributes.get(numAttribute).indexOfValue(streamTokenizer.sval);
          }

          instance.setValue(numAttribute, value);//this.setValue(instance, numAttribute, value, isNumeric);
          ++numAttribute;
        }
        streamTokenizer.nextToken();
      }
      streamTokenizer.nextToken();
      //System.out.println("EOL");
    }

  } catch (IOException ex) {
    Logger.getLogger(ArffLoader.class.getName()).log(Level.SEVERE, null, ex);
  }
  return (numAttribute > 0) ? instance : null;
}