While making a compiler for C language, I was looking for its grammar. I stumbled upon ANSI C Grammar (Lex). There I found the following regular expression (RE):
{CP}?"'"([^'\\\n]|{ES})+"'" { return I_CONSTANT; }
where CP and ES are as follows
CP (u|U|L)
ES (\\(['"\?\\abfnrtv]|[0-7]{1,3}|x[a-fA-F0-9]+))
I understand that ES is RE for escape sequence.
If I understand the regular expression correctly then, u'123'
or U'\n\t'
or L'abc'
are valid I_CONSTANT
s.
I wrote the following small program to see what constant values they represent.
#include <stdio.h>
int main(void) {
printf("%d %d %d\n", u'123', U'\n\t', L'abc');
return 0;
}
This gave the following output.
51 9 99
I deciphered that they represent the ASCII value of the right-most character inside single quotes. However, what I fail to understand is the use and importance of this kind of integer constant.