[5-1] Elementary Data Types
1. Data
- 숫자, 문자, 군집 데이터, 복합 데이터, 메타 데이터(포인터)
Data Object
- Binding of a name to a memoty location
- 일반적으로 변수
Data Value
- 특정 값을 나타내는 비트 패턴
Data Object Attributes
- Component attribute : type, location, value, name
- Variable attribute : scope, lifetime
상수
- 반드시 초기화되어야하는 변수
- 이후 변경x
- Literal (이름 == 값)
- Named constant (이름 != 값) ex. define
2. Type
- 데이터의 분류
- 값 집합 + 연산 집합
@Abstract Data Type
- 연산 구현 방법이 명시되지 않은 데이터 타입
Data Type Specification
- 타입 속성 + 값 집합 + 연산 집합 = 타입 명세
- char s[5]에서
- Attributes는 크기 5, 원소 타입 signed char
- 값 집합 : S = C * C * C * C * C
- 연산 집합 : 대입, +, -
Subtypes
- 어떤 타입의 값 집합 일부을 취한 새로운 타입
- 기존 타입으로 부터 유도된 타입일 수 있음
- C에서 거의 모든 것은 int의 서브타입
Declaration
- 선언문은 수행x elaboration된다o
- 선언문의 위치 및 종류에 따라 데이터 객체의 scope과 lifetime 결정 (type, name 포함)
- 명시적 선언, 암시적 선언, 함수 선언
Declaration 목적
- 저장 형태 결정
- 메모리 관리
- 다형연산 지원
- 타입검사
Type Checking
- 연산자나 서브프로그램에 대해 적절한 개수의 인수와 적절한 타입을 사용하는지 검사
- 정적 타입 검사 : 컴파일 시간에 검사 (C, C++)
- 동적 타입 검사 : 실행 시간에 검사 (Python, JS)
@Descriptor
- 동적 타입검사를 위해서 필요
- 타입 검사에 필요한 정보를 저장 (타입 속성)
Typeless Languages
- 동적 타입검사를 수행하는 언어중에서 선언문x, 변수 타입이 유동적인 언어
Strong Typing
- 타입 오류가 있는 경우 무조건 검출할 수 있는 타입검사
- 반드시 정적일 필요x
- Type safe function (함수 값 타입 고정)
Strongly-typed Language
- 강력한 타입검사를 수행하는 언어
- C의 union, void*, type casting은 강력한 타입검사 적용x
Type Inference
- 정적 타입검사를 수행하는 언어중에서 모호하지 않으면 타입 정보를 추론 가능
- 변수의 타입 + 연산 가능 여부를 통해 추론
Type Conversion and Coercion
- 연산하고 싶은 변수들의 타입이 다를 때
- 명시적 변환 (type casting)
- 암시적 변환 (규칙이 존재, type coercion)
- Widening (암시적 변환)
- Narrowing 허용x, 대신 변환을 위한 대체 함수가 존재
Assignment
- L-value : 객체의 위치
- R-value : 변수의 내용
Assignment Issue
- 언어 마다 구현 형태가 다르다 (cascading 유무)
- Scalar assignment : value copying
- Pointer assignment : pointer copying
- Record assignemnt : bit-wise/field-wise copying
@Cascading assignment
- 한 줄에 여러 변수에 값을 할당하는 것
- x, y, z = 1, 2, 3
Scalar Data
- Atomic
- 하드웨어를 통해 직접 지원
Numeric Data Types
1.정수
- 일반적으로 2's complement로 구현
- 값 집합 : -128 ~ 127 (1 byte)
- 연산 집합 : 산술, 관계, 대입, 비트
@Dynamic type checking
- descriptor는 값과 분리된 word로 저장될 수도
- 같은 word에 저장될 수도 있다
2.Floating-Point Real Numbers
- 구현은 IEEE Standard 754에 표준화 (32, 64 bit)
- 값 집합 : -128 ~ +127 (1 byte)
- 연산 집합 : 정수형의 모든 연산 + 나머지 + 소수점 처리
Floating-Point Number 구현
- Sign, exponent, mantissa
- 실제 exponent는 보이는 값에서 -127 (8 bit)
- Mantissa의 첫 비트는 항상 1, 비트를 온전히 사용가능
@IEEE 754
- 32비트 : (1, 8, 23)
- 64비트 : (1, 11, 52)
Decoding IEEE format
- E=255 and M!=0, invalid number
- E=255 and M=0, infinite
- 0<E<255, 2^E-127 (normal value)
- E=0 and M!=0, 2^-126
- E=0 and M=0, 0
Fixed-Point Real Number
- 길이가 고정된 자릿수로 실수를 표현
Computing With Decimal Data
- 숫자와 scalig factor를 따로 저장
- Scaling factor를 통해 자릿수를 마추고 연산
Subrange Type
- 값 집합은 줄었지만 연산은 그대로인 타입
- 더 작은 공간에 저장할 수 있고
- 더 정밀한 타입 검사가 가능
Enumeration
- 이산 값들의 순차 목록
- 가독성 및 타입 검사 용이
- 연산 집합 : int와 동일?
Booleans (enumeration)
- 값 집합 : {true, false}
- 연산 집합 : and, or, not
- 0과 기타
Characters (enumeration)
- 값 집합 : ASCII, Unicode의 문자집합
- 연산 진합 : 형 변환 연산자, 문자 변환 연산자(collating sequence)
@Collating sequence
- character set에 따라 결정되는 문자들의 순서
Composite Data
- 복합 데이터 (aggregate data)
- 소프트웨어를 통해 지원
- Derived Type과 다름
Character String
- Fixed/variable 길이를 가짐
- 값 집합 : Primitive data type의 문자들
- 연산 집합 : concat, substring, reverse, ...
- Language-defined operators / library functions
@Fixed length string 구현
- 4 characters per word padded with blanks
@Variable length string 구현
1. Bounded
- Current and maximmum string length at header
- 4 characters per word padded with blanks
2. Unbounded with variable allocations
- Contiguous array with null at the end
3. Unbounded with fixed allocations
- Length at header
- Contiguously linked words
- 4 chacters per word
4. Seperate descriptor
- (cur length, max length, pointer to data(2))
Pointer
- 주소를 저장하기 위한 데이터 타입
- Recursive data structure
- 값 집합 : 주소
- 연산 집합 : 대입
Files and Input-Output
- Large persistnet linear data
- 대형, 지속성
- Text or binary
- Pseudo-file : input/output/error stream
파일 종류
- 순차파일 : 순차적 접근만 허용
- 직접접근파일 : 색인을 통한 접근 허용 (expansive)
- 색인순차파일 : 첫 위치는 색인, 이후 순차적으로 접근
'CS > 프로그래밍 언어론' 카테고리의 다른 글
[프로그래밍 언어론] Encapsulation - Abstract Data Types (7) (0) | 2024.06.20 |
---|---|
[프로그래밍 언어론] Structured Data Types (6) (0) | 2024.04.25 |
[프로그래밍 언어론] Modeling Language Properties (4) (0) | 2024.04.25 |
[프로그래밍 언어론] Language Translation Issues (3) (0) | 2024.04.25 |
[프로그래밍 언어론] Impact of Machine Architecture (2) (0) | 2024.04.25 |