Next: String Literal
Up: Literals
Previous: Boolean Literals
A literal of type char is expressed as a character or an escape
sequence, enclosed in apostrophes:
This macro is invoked in definition 12.
Normalize a literal value[31]
:
Token processor[1](`mkchar')
{ char strval[6], *p;
int charval;
if (c[1] != '\\') {
strval[0] = c[1]; strval[1] = '\0';
p = strval;
} else if (c[2] == 'u') {
p = strnorm(c + 3, 16, 10, "");
} else if (c[2] >= '0' && c[2] <= '7') {
p = strnorm(c + 2, 8, 10, "");
} else {
switch (c[2]) {
case 'b': charval = '\b'; break;
case 't': charval = '\t'; break;
case 'n': charval = '\n'; break;
case 'f': charval = '\f'; break;
case 'r': charval = '\r'; break;
case '"': charval = '"'; break;
case '\'': charval = '\''; break;
case '\\': charval = '\\'; break;
default: {
charval = c[2];
message(ERROR, "Illegal escape", 0, &curpos);
}
}
snprintf(strval, 6, "%d", charval);
p = strval;
}
mkidn(p, strlen(p), t, s);
*t = CharacterLiteral;
}
This macro is defined in definitions 18, 25, and 31.
This macro is invoked in definition 37.
Next: String Literal
Up: Literals
Previous: Boolean Literals
2008-09-11