CS/Programming Language

Semantics Analyzer : Type

WakaraNai 2022. 11. 11. 16:59
728x90
반응형

Type Menagerie

ex, in ML

- primitive types : int real char

- construced types : list - 수학에 기반하여 만들어짐

 

Constructed types ...

 

Use Type: Type Annotator

Semantic Analizy 

checking...

- scope rules

: 변수 x가 뭐냐 ? binding issue

- type rules 

 

 

 

Type Annotation

타입이 무엇인지 명시해주는 문법이 무엇인지

ML은 *와 ->로 표현했음

 

- intrinsic type : 코드에 내포된 - BASIC (변수라고 적어야하는 경우)

- extreme type : 사용자의 직접 지시가 있어야 함 - ML (파이썬에서 함수 파라미터 타입을 정하는 것도)

https://en.wikibooks.org/wiki/Standard_ML_Programming/Types

 

Standard ML Programming/Types - Wikibooks, open books for an open world

From Wikibooks, open books for an open world Jump to navigation Jump to search Standard ML has a particularly strong static type system. Unlike many languages, it does not have subtypes ("is-a" relationships) or implicit casts between types. Internally, al

en.wikibooks.org

 

 

Type Checking

Compiler Step의 입출력 형태

소스 파일이 Syntactic Analyzer를 거치면 

AST : abstract syntax tree (오른쪽 그림: id+id3*60) 가 되어

이를  Semantic Analyzer를 거쳐서 decorated AST가 되면서

각 값들이 어떤 타입이 될 수밖에 없는지 알아낸다./

Static VS Dynamic  Type Checking

Static은 코드만 보고 타입 체크 (함수 선언 시 지정한 타입에 맞는지)

Dynamic은 실행해야만 알 수 있는 것들에 대해 타입 체크 (파이썬은 데이터형 선언 없이 변수 선언함)

Strong Typing, Weak Typing

strong -> 프로그래머가 힘들겠지만 굉장히 효율적으로 일할 수 있어요... (ML > Java)

weak -> 버그에 조심하세요... (C - 여러가지 타입이 섞일 수 있어요)

 

Type equivalence Issue

변수 타입 충돌에 대한 이슈

 

Name Equivalence 

- 두 개의 변수 타입의 이름이 같으면 같아

ex) Pascal

 

Structural Equivalence (대부분)

- 변수 이름은 다른데 같은 타입으로 인정해줌

 

 

 

 

 

728x90
반응형

'CS > Programming Language' 카테고리의 다른 글

Stack Memory  (0) 2022.11.20
Semantic Analyzer: Polymorphism  (0) 2022.11.15
ML: Higher-order Functions  (0) 2022.11.11
ML: Semantics - "Types", Polymorphism, Scope  (0) 2022.11.10
Language Systems  (0) 2022.11.03