Example #1
0
 private SymbolType 类型() {
   Token token = tokens.get(index++);
   if (token.getWord().equals("int")) {
     return SymbolType.Integer;
   } else if (token.getWord().equals("double")) {
     return SymbolType.Double;
   } else {
     throw new RuntimeException("读取的不是int,double");
   }
 }
Example #2
0
 private void 句子() {
   Token token = tokens.get(index++);
   if (token.getWord().equals("int") || token.getWord().equals("double")) {
     index--;
     SymbolType type = 类型();
     token = tokens.get(index++);
     if (token.getType() == TokenType.identifier) {
       Symbol symbol = this.symbolTable.get(token.getWord());
       symbol.setType(type);
     } else {
       throw new RuntimeException("读取的不是标示符");
     }
     String digit = A();
     Symbol symbol = this.symbolTable.get(token.getWord());
     symbol.setValue(digit);
   }
 }
Example #3
0
  private String A() {
    Token token = tokens.get(index++);
    if (token.getWord().equals("=")) {

      token = tokens.get(index++);
      if (token.getType() == TokenType.digit) {
        return token.getWord();
      } else {
        throw new RuntimeException("读取的不是数字");
      }
    } else if (token.getWord().equals(";")) {
      index--;
    } else {
      throw new RuntimeException("读取的不是=或者;");
    }
    return null;
  }
Example #4
0
  private void S() {
    Token token = tokens.get(index++);
    if (token.getWord().equals("int") || token.getWord().equals("double")) {
      index--;
      句子();
      token = tokens.get(index++);
      if (token.getWord().equals(";")) {

      } else {
        throw new RuntimeException("读取的不是;");
      }
      S();
    } else if (token.getWord().equals("#")) {
      System.out.println("语法正确!");
    } else {
      throw new RuntimeException("读取的不是int或者#");
    }
  }
Example #5
0
  /**
   * Sets the token list for this utterance. Note that this could be optimized by turning the token
   * list directly into the token relation.
   *
   * @param tokenList the tokenList
   */
  private void setTokenList(List tokenList) {
    setInputText(tokenList);

    Relation relation = createRelation(Relation.TOKEN);
    for (Iterator i = tokenList.iterator(); i.hasNext(); ) {
      Token token = (Token) i.next();
      String tokenWord = token.getWord();

      if (tokenWord != null && tokenWord.length() > 0) {
        Item item = relation.appendItem();

        FeatureSet featureSet = item.getFeatures();
        featureSet.setString("name", tokenWord);
        featureSet.setString("whitespace", token.getWhitespace());
        featureSet.setString("prepunctuation", token.getPrepunctuation());
        featureSet.setString("punc", token.getPostpunctuation());
        featureSet.setString("file_pos", String.valueOf(token.getPosition()));
        featureSet.setString("line_number", String.valueOf(token.getLineNumber()));
      }
    }
  }