Ejemplo n.º 1
0
  /**
   * 解析标识符
   *
   * @param token
   * @return 对应符号表项
   * @throws Exception
   */
  private SymTabEntry parseIdentifier(Token token) throws Exception {
    SymTabEntry id = null;

    if (token.getType() == IDENTIFIER) {
      String name = token.getText().toLowerCase();
      id = symTabStack.lookupLocal(name);

      // 申明必须得没有,否则重定义了
      if (id == null) {
        id = symTabStack.enterLocal(name);
        id.setDefinition(definition);
        id.appendLineNumber(token.getLineNumber());
      } else {
        errorHandler.flag(token, IDENTIFIER_REDEFINED, this);
      }

      token = nextToken();
    } else {
      errorHandler.flag(token, MISSING_IDENTIFIER, this);
    }

    return id;
  }