How are backslash escape sequences performed in compilers?

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

+5
source share
3 answers

, , . , , ( ). - , . . , , , "Hello". "([^\"]|\"|\\|\n|\b)*". , , 1) , 2) , 3) , 4) , n 5) , b. . (: , , ). .

, , , , , . , . . \" ". \\ \. \n . \b .. , , , , .

+8

" " ( , ACM Turing: 1966-1985 .), , ACM .

, , \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.1

c = next();
if (c != '\\')
    return(c);
c = next();
if (c == '\\')
    return('\\');
if (c == 'n')
    return('\n');

2.2

c = next();
if (c != '\\')
    return(c);
c = next();
if (c == '\\')
    return('\\');
if (c == 'n')
    return('\n');
if (c == 'v')
    return('\v');

2.3

c = next();
if (c != '\\')
    return(c);
c = next();
if (c == '\\')
    return('\\');
if (c == 'n')
    return('\n');
if (c == 'v')
    return(11);
+5

, . : ?

, . -, ( ), , .

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.

+4
source

All Articles