[CTAP] 1# Lexical Pitfalls

문연수·2022년 7월 27일
0

CTAP

목록 보기
2/9

0. Terminologies

 The word token refers to a part of a program that plays much the same role as a word in a sentenc: in some sense it means the same thing every time it appears.

 The part of a compiler that breaks a program up into tokens is often called a lexical analyzer.

1. Words

  • inadvertently: 실수로, without intention; accidentally.'
  • apparently: 보기에, as far as one knows or one see.
  • plain: 명백한,
  • count on: 기대다.
  • inadvertent: 부주의
  • bite off: 물어뜯다.
  • colloquially: 구어체로
  • maximal munch: 우적우적 먹다.
  • constitude: 구성하다, be (a part) of a whole.
  • archaic: 낡은
  • sort: 종류
  • near-ambiguity: 모호함
  • gobble: 펠라티오, 칠면조의 울음소리, 게걸스럽게 먹다, 울음소리를 내다.
  • prohibit: 금지하다, formally forbid (something) by law, rule, or ther authority.
  • collating: 대조
  • collate: 함께 함치다. 대조하다. 페이지 순서를 맞추다, 성직에 임명하다, collect and combine (texts, information, or sets of figures) in porper order.
  • diagnostic: 특수 증상, 진단 상의, 특징적인
  • coincidental: 동시에 일어나는, 일치하는, 부합하는, resulting from a coincidence; done or happening by chance.
  • coincedence: 우연의 일치

2. Summery

- 1. = is not ==

 The title says it all.

- 2. & and | are not && or ||

 The title says it all.

- 3. Greedy lexical analysis

 The way to convert a C program to tokens is to move from left to right, taking the longest possible token each time. This strategy is also sometimes referred to as greedy, or, more colloquially, as the maximal munch strategy.

- 4. Integer constants

 Many C compilers accept 8 and 9 as "octal" digits without complaint. The meaning of this strange construct follows from the definition of octal numbers. For instance, 0195 means 1×82+9×81+5×801 \times 8^2+ 9 \times 8^1 + 5 \times 8^0, which is equivalent to 141 (decimal) or 0215 (octal).

Important: ANSI C prohibits it.

- 5. Strings and characters

 Because an integer is usually large enough to hold several characters, some C compilers permit multiple characters in a character constant as well as a string constant. This means that writing 'yes' instead of "yes" may well go undetected.

Interesting...

3. Exercises

https://www.mythos-git.com/Cruzer-S/CTAP/-/tree/main/Chapter01

4. References

[Book] C Traps and Pitfalls (Andrew Koenig)

profile
2000.11.30

0개의 댓글