1 / 15

Chapter 2

Chapter 2. 3 주 강의 Lexical Elements, Operators, and the C System. Compiler. Grammar ::: lexical, syntax, semantics, pragmatics Compiler checks the legality of C code Preprocessor  compiler Error recovery. Lexical Terms. Token 의 종류 (ANSI C)

ashtyn
Download Presentation

Chapter 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 2 3주 강의 Lexical Elements, Operators, and the C System

  2. Compiler • Grammar ::: lexical, syntax, semantics, pragmatics • Compiler checks the legality of C code • Preprocessor  compiler • Error recovery

  3. Lexical Terms • Token의 종류 (ANSI C) : keywords, identifiers, constants, string constants, operators, punctuators • Lexical errors

  4. Characters and Lexical Elements • Lowercase letters, uppercase letters, digits, other characters (+, -, …), white space characters (blank, newline, tab) • Lexical errors int a, b, c;  inta, b, c &a, &b == & a , & b • sum=a+b; == sum = a +b;  s u m = a +b;

  5. Syntax Rules • Digit ::= 0|1|2|3 |4|5|6|7|8|9 • BNF(Bacus Naur Form) ::= (rewriting), | (separate), * [] (optional), {} (0 or more), * {}1, {}0+, {}1+, {}opt • conditional_statement :: if (expression) statement {else statement}opt

  6. 명칭(identifier) • identifier ::= {letter | _}1 {letter | digit | _}0+ • 숙제 ::: constant(실수, 정수), string을 위한 문법(BNF)을 참고로 2.74, 36, 2.7e-04, “I love you.”가 바름을 보여라. (constant나 string임) • Appendix B를 참고하여 설명 !!!!

  7. Comments • /* This is comments */ // This is comments • Self-documentation ??? 바른 documentation의 중요성 ???

  8. Keywords • Auto, do, goto, signed … (page 77) • Reserved word와 그렇지 않은 word의 차이점 • Keyword가 reserved된 언어와 그렇지 않은 언어

  9. Constants, String constants,Operators, Punctuator • Constants : 0, 17, 3,14159, ‘a’, ‘+’, “\n”, enumeration type • String constants : “I”, “a string”, ““, “c=a+b”, “\\ I \\” “abc”“def” “abcdef” ??? /* “ This is a string” */, “ ” • Operators : +, -, *, /, % ??? a-b, a_b • Punctuators : “{“, “,”, “;”, “(“, “)” ??? main(void) • ++a, a+=b • 질문 :::: ‘=‘은 어디에 속하나 ???

  10. Precedence and Associativity of Operators *** Page 332에 전체 테이블

  11. Increment and decrement Operators • ++val, val++ :: val=val+1 • 속도에서 빠르다 …이유? • 차이 :: (1) a=1; b=++a; printf(“%d,%d”,a,b) (2) a=1; b=a++; printf(“%d,%d”,a,b) • Side-effect

  12. Assignment Operators • a=b+c; /* ‘=‘의 우선순위는 어떤 연산자보다 낮으면서 오른쪽 우선 */ • variable=right_side • a= (b=2) + (c=3);  b=2; c=3; a=b+c; /* 속도 차이 */ • a=b=c=0; • k=k+2  k+=2; • =, +=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |= /* 조심 …‘>=‘, ‘<=‘와 구별 */ • i += j+k  i += (j+k)  i=i+j+k  i=(i+(j+k))

  13. The C System • The preprocessor #include <stdio.h> #include <stdio.h> /* int rand(void)가 있음 */ • random을 이용한 프로그램 seed number  srand(time(NULL))

  14. 강의 시간에 풀 문제 • 2장 5,7,8,9를 합하여 하나의 프로그램으로 작성한다 • 10을 검증한다. • 20번을 해결한다. • 29를 해결한다 /* 각자 어디까지 해결하는지 검증… 단, 아직은 성적에 반영하지 않고 해결 못한 사람은 집에서 해온다 */

  15. 집에서 풀 문제 • 10, 15,17,18, 23, 25 • 27 (이 문제는 여러 명이 상의해서 풀어도 된다)

More Related