I just wanted to know how backslash escape sequences are implemented in compilers? If we write "\ n" in a string, how will the compiler replace it with the new character of the string? How does the compiler replace "\ b" with a backspace character?
I ask because I wrote the code:
#include<stdio.h> main() { printf("Hello \c"); }
The output was:
Hello Exited: ExitFailure 7
I launched it in the codec, I looked through the book number number 1. 1.2.
Thanks at Advance
, , . , , ( ). - , . . , , , "Hello". "([^\"]|\"|\\|\n|\b)*". , , 1) , 2) , 3) , 4) , n 5) , b. . (: , , ). .
"Hello"
"([^\"]|\"|\\|\n|\b)*"
, , , , , . , . . \" ". \\ \. \n . \b .. , , , , .
\"
"
\\
\
\n
\b
" " ( , ACM Turing: 1966-1985 .), , ACM .
, , \v , :
\v
C . . ,"Hello world\n" "\n", .2.1 C, escape-. . "" , . , ., C, "\v" . , 2.1, 2.2. C , . , "\v" , C. "" . , "", "\v" , C. ASCII, 11. , 2,3. . C, , 2.2.. , . , .2.1c = next(); if (c != '\\') return(c); c = next(); if (c == '\\') return('\\'); if (c == 'n') return('\n'); 2.2c = next(); if (c != '\\') return(c); c = next(); if (c == '\\') return('\\'); if (c == 'n') return('\n'); if (c == 'v') return('\v'); 2.3c = next(); if (c != '\\') return(c); c = next(); if (c == '\\') return('\\'); if (c == 'n') return('\n'); if (c == 'v') return(11);
C . . ,
"Hello world\n"
"\n", .
2.1 C, escape-. . "" , . , .
, C, "\v" . , 2.1, 2.2. C , . , "\v" , C. "" . , "", "\v" , C. ASCII, 11. , 2,3. . C, , 2.2.
. , . , .
c = next(); if (c != '\\') return(c); c = next(); if (c == '\\') return('\\'); if (c == 'n') return('\n');
c = next(); if (c != '\\') return(c); c = next(); if (c == '\\') return('\\'); if (c == 'n') return('\n'); if (c == 'v') return('\v');
c = next(); if (c != '\\') return(c); c = next(); if (c == '\\') return('\\'); if (c == 'n') return('\n'); if (c == 'v') return(11);
, . : ?
, . -, ( ), , .
Here's a related post, and one of the posts also recommends what Jonathan Leffler recommended. What is a Magic Behind Escape (\) Character
Another short answer to the whole compiler is the grammar.