14 6 4 Assignment statement Assignment statement C

  • Slides: 72
Download presentation

14 6. 4 배정문 (Assignment statement) • 배정문 (Assignment statement) – 변수 내용을 변경시키는

14 6. 4 배정문 (Assignment statement) • 배정문 (Assignment statement) – 변수 내용을 변경시키는 기본 연산 • • 각종 배정 연산자 – C, Java, Fortran A=B – Algol, Pascal A : = B – APL A – Basic LET A = B – Cobol MOVE B TO B A l-values와 r-values – 배정 연산자의 왼쪽(l-value)과 오른쪽(r-value)을 의미 – 예) A : = B r-value l-value.

26 6. 5 상수 및 변수 초기화하다 (to initialize) – Ada • 예약어 constant

26 6. 5 상수 및 변수 초기화하다 (to initialize) – Ada • 예약어 constant 사용 (모든 자료형) X:constant INTEGER : =17; Y:INTEGER : =17; • 상수 선언 변수 선언과 초기화 구조 자료형의 초기화 예 type NATURAL is 1. . N; type ROSTER is array (NATURAL) of INTEGER; LINEUP:ROSTER (1. . 100); 배열 선언 LINEUP:= ( 1. . 50 => 1 , 51. . 100 => -l ); 배열 배정문 LINEUP: ROSTER (1. . 100) : = ( 1. . 50 => 1 , 51. . 100 => -l ); 배열 선언, 초기화 LINEUP: constant ROSTER (1. . 100) : = ( 1. . 50 => 1 , 51. . 100 => -l ); 상수 선언 .

33 6. 6 표현식 (Expression) C ++, -- (postfix operator), ->, . &, *,

33 6. 6 표현식 (Expression) C ++, -- (postfix operator), ->, . &, *, +, -, ~, ! (unary operator), ++, -- (prefix operator) *, /, % +, - <<, >> (shift 연산자) <, >, <=, >= (비교 연산자) ==, != (equality operator) & (and) ^ (exclusive or) | (inclusive or) && (logical and) || (logical or) ? (조건 연산자) =, +=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |= (배정 연산자) .

<primary-expression> : : = <identifier> | <constant> | <string-literal> | `('expression`)' <postfix-expression> : :

<primary-expression> : : = <identifier> | <constant> | <string-literal> | `('expression`)' <postfix-expression> : : = <primary-expression> | <postfix-expression>`['expression`]' | <postfix-expression>`('<argument-expression-list>opt`)' | <postfix-expression>(. | -> )<identifier> | <postfix-expression>( ++ | -- ) <argument-expression-list> : : =`('<assignment-expression>{, <assignment-expression>}`)' <unary-expression> : : = <postfix-expression> | ( ++ | -- )<unary-expression> | <unary-operator><cast-expression> | sizeof(<unary-expression> | `('<type-name>`)') <unary-operator> : : = & | * | + | - | ~ | ! <cast-expression> : : = <unary-expression> | `('<type-name>`)'<cast-expression> <multiplicative-expression> : : = <cast-expression> | <multiplicative-expression>( * | / | % )<cast-expression> <additive-expression> : : = <multiplicative-expression> | <additive-expression>( + | - )<multiplicative-expression> <shift-expression> : : = <additive-expression> | <shift-expression>( << | >> )<additive-expression> <relational-expression> : : = <shift-expression> | <relational-expression>( < | > | <= | >= )<shift-expression> <equality-expression> : : = <relational-expression> | <equality-expression>( == | != )<relational-expression> <AND-expression> : : = <equality-expression> | <AND-expression>&<equality-expression> <exclusive-OR-expression> : : = <AND-expression> | <exclusive-OR-expression>^<AND-expression> <inclusive-OR-expression> : : = <exclusive-OR-expression> | <inclusive-OR-expression>`|'<exclusive-OR-expression> <logical-AND-expression> : : = <inclusive-OR-expression> | <logical-AND-expression>&&<inclusive-OR-expression> <logical-OR-expression> : : = <logical-AND-expression> | <logical-OR-expression>`|'`|'<logical-AND-expression> <conditional-expression> : : = <logical-OR-expression> | <logical-OR-expression>? <expression>: <conditional-expression> <assignment-expression> : : = <conditional-expression> | <unary-expression><assignment-operator><assignment-expression> <assignment-operator> : : = = | *= | /= | %= | += | -= | <<= | >>= | &= | ^= | `|'= <expression> : : = <assignment-expression> | <expression>, <assignment-expression> 34 C언어의 식에 대한 EBNF 2004 Y. H. Won, Hongik University. All rights reserved.

35 6. 6 표현식 (Expression) • C언어에서 한 수식의 parse tree .

35 6. 6 표현식 (Expression) • C언어에서 한 수식의 parse tree .

37 6. 7 조건문 (Condition Statements) • 조건문 – FORTRAN (조건 분기문 임) IF

37 6. 7 조건문 (Condition Statements) • 조건문 – FORTRAN (조건 분기문 임) IF (BCOND) L 1 , L 2 ; IF (BCOND) <STMT> GOTO문 요구 판독성 저하 IF (ACOND) L 1 , L 2 , L 3 – Algol 60 if cond then S 1 else S 2 택일문 (조건문) dangling else발생 Fortran 77에서는 dangling else의 해결로 ENDIF 사용 • if문 (if statement).

38 6. 7 조건문 (Condition Statements) • 중첩 if 개선 표 5. 5 nested

38 6. 7 조건문 (Condition Statements) • 중첩 if 개선 표 5. 5 nested if문 구조 if C 1 then S 1 else if C 2 then S 2 else if C 3 then S 3. . . . else if Cn then Sn else Sn+1 end if . . . . end if .

39 6. 7 조건문 (Condition Statements) • 다수의 endif 사용을 줄이고 판독성을 증가시키기 위해

39 6. 7 조건문 (Condition Statements) • 다수의 endif 사용을 줄이고 판독성을 증가시키기 위해 새 구문 형태 도입 예) Algol 68의 elif (최초 시도), Ada의 elsif 도입 Ada의 elsif 사용한 표 5. 5 개선 예 if C 1 then S 1 elsif C 2 then S 2 elsif C 3 then S 3 …. . elsif Cn then Sn else Sn+1 endif; .

40 6. 7 조건문 (Condition Statements) • Case 문 If-then-else를 확장한 택일문 – Algol-w(Hoare,

40 6. 7 조건문 (Condition Statements) • Case 문 If-then-else를 확장한 택일문 – Algol-w(Hoare, Wirth) <integer expression > : (1 ~ n) 정수 case <integer expression > of 임의 i 이면 Si 실행 begin S 1;S 2;. . . ;Sn end – 열거형 도입 Pascal case < expr > of <case label list>:<stmt>. . . <case label list>:<stmt> end. <case label list>는 <expr>의 상수

41 6. 7 조건문 (Condition Statements) • Pascal case문 사용 예 다음 문장이 정의되었다고

41 6. 7 조건문 (Condition Statements) • Pascal case문 사용 예 다음 문장이 정의되었다고 가정 type months = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec); case thismonth of Feb, Apr, Jun, Jul, Aug : birthday : = 4; var thismonth : months; Sep : birthday : = 1; Jan, Mar, May, Oct, Nov, Dec : birthday : = 0; end; • Ada – others절 도입 – 열거형과 부분범위(range)형 – 예) case thismonth is when Feb|Apr|Jun. . Aug ⇒ birthday : = 4; when Sep ⇒ birthday : = 1; when others ⇒ birthday : = 0; endcase; .

45 6. 8 반복문 (Iterative Statements) • 종류 (1 of 4) ① 가장 간결한

45 6. 8 반복문 (Iterative Statements) • 종류 (1 of 4) ① 가장 간결한 형태 (괄호 사용 개념) • loop-repeat 문 – 탈출 방법(조건/무조건 분기문 이용) <loop-repeat예> loop – goto(비구조적) -> exit(제한적 goto) if not <조건> then exit Bliss-10 (다양한 exit 제공) <statement> repeat exit, exitblock, exitcase, exitcommand, exitselect, exitloop, exitset 사용 – Bliss II (label을 사용하므로써 중첩된 scope을 한번에 탈출 가능) exit<label> : label은 scope 이름 반복문 몸체, 복합문, case 문 등.

56 변수 (variables) 용어 국제 표준 규격 15. 03 Variable 변수 A quadruple, established

56 변수 (variables) 용어 국제 표준 규격 15. 03 Variable 변수 A quadruple, established by a declaration or an implicit declaration, that consists of an identifier, a set of attributes, one or more addresses, and data values, where the relationship between the addresses and the data values may vary. <NOTE> In some programming languages, the addresses may vary, hence the associated data values may vary. In other programming languages, the addresses remain fixed, but the associated data values may change during execution. 선언문 또는 묵시적 선언으로 생성되며, 식별자, 자료 속성들의 집합, 하나 이상의 주소, 그리고 자료값들의 4요소로 구성되는데, 주소와 자료값들의 관계는 변할 수 있다. <주> 일부 프로그래밍 언어들에서 주소가 변화될 수 있으며, 이에 따라 그 주소와 관련된 자료값도 변할 수 있다. 다른 프로그래밍 언어들에서는, 주소는 고정되어 있으나, 그 주소와 관련된 자료값은 실행 동안 변할 수 있다. 2004 Y. H. Won, Hongik University. All rights reserved.

57 정적 (static) 용어 국제 표준 규격 15. 02. 14 static (. adj) 정적

57 정적 (static) 용어 국제 표준 규격 15. 02. 14 static (. adj) 정적 (형용사) Pertaining to objects that exist and retain their values throughout the execution of the entire program. <Example> A subprogram * variable that has been declared static to retain its values from one execution to the next. 전체 프로그램의 실행 동안 그 값이 존재하고 유지되는 객체들의 속성 <예> 한 실행에서 다음 실행 시까지 그 값이 유지하도록 정적으로 선언된 부프로그램 변수 2004 Y. H. Won, Hongik University. All rights reserved.

58 동적 (dynamic) 용어 국제 표준 규격 15. 02. 15 dynamic 동적 Pertaining to

58 동적 (dynamic) 용어 국제 표준 규격 15. 02. 15 dynamic 동적 Pertaining to a data attribute, whose values can only be established during the execution of all or part of a program. <Example> The length of a variable-length data object is dynamic. 프로그램의 전체 또는 일부의 실행 동안만 그 값을 설정할 수 있는 자료의 속성 <예> 가변 길이 자료 객체의 길이는 동적이다. 2004 Y. H. Won, Hongik University. All rights reserved.

59 선언문 (declaration) 용어 국제 표준 규격 15. 02. 01 declaration 선언[문] An explicit

59 선언문 (declaration) 용어 국제 표준 규격 15. 02. 01 declaration 선언[문] An explicit language construct that introduces one or more identifiers into a program and specifies how these identifiers are to be interpreted. <Example>Declarations of data types, storage organization, packages, or tasks. <NOTE> In some programming languages, declarations are considered to be statements. 하나 이상의 식별자를 프로그램에 도입시켜 이 식별자들이 어떻게 해석되느냐를 명세하는 명시적인 언어 구성자 <예> 데이터형, 저장 조직, 패키지 또는 태스크 선언문 <주> 선언문이 문장으로 간주되는 프로그래밍 언어도 있다. 2004 Y. H. Won, Hongik University. All rights reserved.

60 디폴트 (default) 용어 국제 표준 규격 15. 02. 03 default (adj. ) 디폴트

60 디폴트 (default) 용어 국제 표준 규격 15. 02. 03 default (adj. ) 디폴트 (형용사) Pertaining to an attribute, data value, or option that is assumed when none is explicitly specified. <Example> In Fortran, the default naming convention specifies that names beginning with one of the letters I through N denote variables of integer type. 속성이나 데이터, 또는 선택에 대해, 명시적으로 어떤 값도 지정되지 않았을 때에 갖게 되는 것 <예> Fortran에서 디폴트로 명명하는 규약에 따르면, I에서 N까지 중의 한 문자로 시작되는 이름은 정수형 변수를 나타낸다. 2004 Y. H. Won, Hongik University. All rights reserved.

61 배정문 (assignment statement) 용어 국제 표준 규격 15. 04 assignment statement assignment 배정문

61 배정문 (assignment statement) 용어 국제 표준 규격 15. 04 assignment statement assignment 배정문 배정 A simple statement that replaces the current data value of a variable with a new data value specified by an expression. 수식으로 기술된 새로운 자료값으로 변수의 현재 자료값을 바꾸는 단순문 2004 Y. H. Won, Hongik University. All rights reserved.

62 상수 (constant) 용어 국제 표준 규격 15. 03. 05 Constant 상수 A quadruple,

62 상수 (constant) 용어 국제 표준 규격 15. 03. 05 Constant 상수 A quadruple, established by a declaration or an implicit declaration, that consists of an identifier, a set of data attributes, one or more addresses, and only one data value. 선언문 또는 묵시적 선언으로 생성되며, 식별자, 자료 속성들의 집합, 하나 이상의 주소, 그리고 오직 한 개의 자료값의 4요소로 구성된 것. 2004 Y. H. Won, Hongik University. All rights reserved.

63 초기화하다 (to initialize) 용어 국제 표준 규격 15. 10. 03 To initialize 초기화하다

63 초기화하다 (to initialize) 용어 국제 표준 규격 15. 10. 03 To initialize 초기화하다 To give a data value to a data object at the beginning of its lifetime 자료 객체의 수명이 시작될 때 자료 객체에게 자료값을 주는 것 2004 Y. H. Won, Hongik University. All rights reserved.

64 표현식 (expression) 용어 국제 표준 규격 15. 05. 33 Expression 표현식 A language

64 표현식 (expression) 용어 국제 표준 규격 15. 05. 33 Expression 표현식 A language construct that defines the computation of a data value as a result from one or more operands. <NOTE> Operands may be literals, identifiers, * function calls. 하나이상의 피연산자에서 발생되는 결과로서, 자료값의 계산을 정의하는 언어 구성자 <주> 피연산자는 리터럴, 식별자, 함수호출등이 될 수있다. 2004 Y. H. Won, Hongik University. All rights reserved.

65 연산자 순위 용어 국제 표준 규격 15. 05. 36 operator precedence 연산자 순위

65 연산자 순위 용어 국제 표준 규격 15. 05. 36 operator precedence 연산자 순위 An ordering rule defining the sequence of the application of operators within an expression. <NOTE> The ordering rule may specify the evaluation direction. 식 내에 연산자들의 적용 순서를 정의하는 순서화 규칙 <주> 순서화 규칙은 계산 방향을 서술할 수 있다. 2004 Y. H. Won, Hongik University. All rights reserved.

66 조건문 용어 국제 표준 규격 15. 05. 13 Conditional statement 조건문 A compound

66 조건문 용어 국제 표준 규격 15. 05. 13 Conditional statement 조건문 A compound statement that selects for execution one or none of the enclosed sequences of statements depending on the value of a conditional expression of one or more corresponding conditions. <Examples> In Pascal, if statements and case statements are conditional statements. 일치하는 하나 이상의 조건으로 이루어진 조건식의 값에 따라, 내포된 문장들의 실행 순서 0개 또는 1개를 실행하도록 선택할 수 있는 복합문 <예> Pascal에서 if문과 case문이 조건문이다. 2004 Y. H. Won, Hongik University. All rights reserved.

67 if 문 (if statement) 용어 국제 표준 규격 15. 05. 15 if statement

67 if 문 (if statement) 용어 국제 표준 규격 15. 05. 15 if statement if문 A conditional statement that causes execution of the enclosed sequences of statements or skips them depending on the truth value of the conditional expression. 조건식의 진리값에 따라, 내포된 문장들의 순서를 실행하거나 건너뛰게 하는 조건문 2004 Y. H. Won, Hongik University. All rights reserved.

68 case 문 용어 국제 표준 규격 15. 05. 16 case statement case문 A

68 case 문 용어 국제 표준 규격 15. 05. 16 case statement case문 A conditional statement that selects for execution one of a number of alternative sequences of statements depending on the value of a conditional expression. 조건식의 진리값에 따라, 많은 선택 가능한 문장들의 순서들 중에서 하나 를 실행하도록 선택하는 조건문 2004 Y. H. Won, Hongik University. All rights reserved.

69 반복문 용어 국제 표준 규격 15. 05. 17 Iteration statement, loop statement 반복문

69 반복문 용어 국제 표준 규격 15. 05. 17 Iteration statement, loop statement 반복문 A compound statement that includes a mechanism to control repeated execution of its enclosed statements. 내포된 문장의 반복실행을 제어하기 위한 기법을 포함하는 복합문 2004 Y. H. Won, Hongik University. All rights reserved.

70 for 구성자 (for construct) 용어 국제 표준 규격 15. 05. 20 for-construct for-구성자

70 for 구성자 (for construct) 용어 국제 표준 규격 15. 05. 20 for-construct for-구성자 A language construct for iteration control that defines the test to be performed for such control, usually based on a loop-control variable, and the prescription for the changes of that iteration control variable to be carried out between iteration steps. 반복제어를 위한 언어구성자로서 통산 반복제어변수를 가지고 수행할 테스트를 정의한다. 또한 반복 구간들 사이에서 수행되는 반복제어변수의 변화에 대한 처리를 정의한다. 2004 Y. H. Won, Hongik University. All rights reserved.

71 레이블 (label) 용어 국제 표준 규격 15. 01. 10 label (in programming languages)

71 레이블 (label) 용어 국제 표준 규격 15. 01. 10 label (in programming languages) 레이블 (프로그래밍 언어에서) An identifier for a location in a program. <NOTE> 1. A Label is frequently used to refer to a statement. 2. In BASIC, a line number can serve as a label, but is not always the target of a transfer. 3. In Fortran, a label, consisting of up to five digits, that precedes a statement, may be used to refer to the statement. 프로그램 내의 위치를 나타내는 식별자 <주> 1. 레이블은 어떤 문장을 참조하는데 자주 사용된다. 2. Basic에서 줄 번호가 레이블로 사용될 수 있으나, 항상 전이의 목표가 되지는 않는다. 3. Fortran에서 레이블은 문장 앞에 선행되는 최대 5자리수로 구성되며, 그 문장을 참조하는데 사용 될 수 있다. 2004 Y. H. Won, Hongik University. All rights reserved.

72 goto 문 (goto statement) 용어 국제 표준 규격 15. 05. 11 goto statement

72 goto 문 (goto statement) 용어 국제 표준 규격 15. 05. 11 goto statement goto문 A simple statement that specifies an explicit transfer of program control for its place in the execution sequence to a target statement that usually is identified by a label. <NOTE> The transfer of program control may be equivalent to a jump. 단순문으로서 실행순서 내의 한 장소에서, 통상 레이블로 식별되는 목적문으로 프 로그램 제어를 명시적으로 전이하도록 기술한다. <주> 프로그램 제어의 전송은 분기와 동등할 수 있다. 2004 Y. H. Won, Hongik University. All rights reserved.