What kind of magic is the escape (\) character

How does the C / C ++ compiler control the escape character ["\"] in the source code? How is the compiler grammar written to handle this character? What does the compiler do after encountering this symbol?

+5
source share
4 answers

Most compilers are divided into parts: the compiler interface is called a lexical analyzer or scanner. This part of the compiler reads the actual characters and creates tokens. This one has a state machine that decides upon seeing the escape character whether it is genuine (for example, when it appears inside a string) or changes the next character. The token is displayed accordingly as an escape character or some other token (for example, a tab or a new line) in the next part of the compiler ( analyzer ). A state machine can group multiple characters into a token.

+14
source

An interesting note on this subject is On Trusting Trust [PDF link] .

, , , c-write-in-c ASCII; escape- , ASCII .

+5

, :

  • , . \a "" ( , - ), \n "linefeed", \xNUM , .
  • , ( !), . , .
+2

escape- (, \n) C - , escape-.

+1

All Articles