Ejemplo n.º 1
0
  /** @return true if this is a Pascal string type. */
  public boolean isPascalString() {
    if (form == ARRAY) {
      TypeSpec elmtType = (TypeSpec) getAttribute(ARRAY_ELEMENT_TYPE);
      TypeSpec indexType = (TypeSpec) getAttribute(ARRAY_INDEX_TYPE);

      return (elmtType.baseType() == Predefined.charType)
          && (indexType.baseType() == Predefined.integerType);
    } else {
      return false;
    }
  }
Ejemplo n.º 2
0
  /**
   * Constructor.
   *
   * @param value a string value.
   */
  public TypeSpecImpl(String value) {
    this.form = ARRAY;

    TypeSpec indexType = new TypeSpecImpl(SUBRANGE);
    indexType.setAttribute(SUBRANGE_BASE_TYPE, Predefined.integerType);
    indexType.setAttribute(SUBRANGE_MIN_VALUE, 1);
    indexType.setAttribute(SUBRANGE_MAX_VALUE, value.length());

    setAttribute(ARRAY_INDEX_TYPE, indexType);
    setAttribute(ARRAY_ELEMENT_TYPE, Predefined.charType);
    setAttribute(ARRAY_ELEMENT_COUNT, value.length());
  }
Ejemplo n.º 3
0
  /**
   * Parse type definitions.
   *
   * @param token the initial token.
   * @throws Exception if an error occurred.
   */
  public void parse(Token token) throws Exception {
    token = synchronize(IDENTIFIER_SET);

    // Loop to parse a sequence of type definitions
    // separated by semicolons.
    while (token.getType() == IDENTIFIER) {
      String name = token.getText().toLowerCase();
      SymTabEntry typeId = symTabStack.lookupLocal(name);

      // Enter the new identifier into the symbol table
      // but don't set how it's defined yet.
      if (typeId == null) {
        typeId = symTabStack.enterLocal(name);
        typeId.appendLineNumber(token.getLineNumber());
      } else {
        errorHandler.flag(token, IDENTIFIER_REDEFINED, this);
        typeId = null;
      }

      token = nextToken(); // consume the identifier token

      // Synchronize on the = token.
      token = synchronize(EQUALS_SET);
      if (token.getType() == EQUALS) {
        token = nextToken(); // consume the =
      } else {
        errorHandler.flag(token, MISSING_EQUALS, this);
      }

      // Parse the type specification.
      TypeSpecificationParser typeSpecificationParser = new TypeSpecificationParser(this);
      TypeSpec type = typeSpecificationParser.parse(token);

      // Set identifier to be a type and set its type specificationt.
      if (typeId != null) {
        typeId.setDefinition(TYPE);
      }

      // Cross-link the type identifier and the type specification.
      if (type != null && typeId != null) {
        if (type.getIdentifier() == null) {
          type.setIdentifier(typeId);
        }
        typeId.setTypeSpec(type);
      } else {
        token = synchronize(FOLLOW_SET);
      }

      token = currentToken();
      TokenType tokenType = token.getType();

      // Look for one or more semicolons after a definition.
      if (tokenType == SEMICOLON) {
        while (token.getType() == SEMICOLON) {
          token = nextToken(); // consume the ;
        }
      }

      // If at the start of the next definition or declaration,
      // then missing a semicolon.
      else if (NEXT_START_SET.contains(tokenType)) {
        errorHandler.flag(token, MISSING_SEMICOLON, this);
      }

      token = synchronize(IDENTIFIER_SET);
    }
  }