Added support for octal and hex character constants
git-svn-id: http://picoc.googlecode.com/svn/trunk@326 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
637e224fff
commit
b55ab05d48
15
lex.c
15
lex.c
|
@ -211,6 +211,17 @@ enum LexToken LexGetWord(struct LexState *Lexer, struct Value *Value)
|
||||||
return TokenIdentifier;
|
return TokenIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* unescape a character from an octal character constant */
|
||||||
|
unsigned char LexUnEscapeCharacterConstant(const char **From, const char *End, unsigned char FirstChar, int Base)
|
||||||
|
{
|
||||||
|
unsigned char Total = GET_BASE_DIGIT(FirstChar);
|
||||||
|
int CCount;
|
||||||
|
for (CCount = 0; IS_BASE_DIGIT(**From, Base) && CCount < 2; CCount++, (*From)++)
|
||||||
|
Total = Total * Base + GET_BASE_DIGIT(**From);
|
||||||
|
|
||||||
|
return Total;
|
||||||
|
}
|
||||||
|
|
||||||
/* unescape a character from a string or character constant */
|
/* unescape a character from a string or character constant */
|
||||||
unsigned char LexUnEscapeCharacter(const char **From, const char *End)
|
unsigned char LexUnEscapeCharacter(const char **From, const char *End)
|
||||||
{
|
{
|
||||||
|
@ -243,8 +254,8 @@ unsigned char LexUnEscapeCharacter(const char **From, const char *End)
|
||||||
case 'r': return '\r';
|
case 'r': return '\r';
|
||||||
case 't': return '\t';
|
case 't': return '\t';
|
||||||
case 'v': return '\v';
|
case 'v': return '\v';
|
||||||
/* case '0': XXX - implement octal character constants */
|
case '0': case '1': case '2': case '3': return LexUnEscapeCharacterConstant(From, End, ThisChar, 8);
|
||||||
/* case 'x': XXX - implement hex character constants */
|
case 'x': return LexUnEscapeCharacterConstant(From, End, '0', 16);
|
||||||
default: return ThisChar;
|
default: return ThisChar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
tests/26_character_constants.c
Normal file
10
tests/26_character_constants.c
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
printf("%d\n", '\1');
|
||||||
|
printf("%d\n", '\10');
|
||||||
|
printf("%d\n", '\100');
|
||||||
|
printf("%d\n", '\377');
|
||||||
|
printf("%d\n", '\x01');
|
||||||
|
printf("%d\n", '\x0e');
|
||||||
|
printf("%d\n", '\x10');
|
||||||
|
printf("%d\n", '\x40');
|
||||||
|
printf("test \x407\n");
|
||||||
|
|
9
tests/26_character_constants.expect
Normal file
9
tests/26_character_constants.expect
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
1
|
||||||
|
8
|
||||||
|
64
|
||||||
|
255
|
||||||
|
1
|
||||||
|
14
|
||||||
|
16
|
||||||
|
64
|
||||||
|
test @7
|
|
@ -21,7 +21,8 @@ TESTS= 00_assignment.test \
|
||||||
20_pointer_comparison.test \
|
20_pointer_comparison.test \
|
||||||
22_floating_point.test \
|
22_floating_point.test \
|
||||||
23_type_coercion.test \
|
23_type_coercion.test \
|
||||||
24_math_library.test
|
24_math_library.test \
|
||||||
|
26_character_constants.test
|
||||||
|
|
||||||
%.test: %.expect %.c
|
%.test: %.expect %.c
|
||||||
@echo Test: $*...
|
@echo Test: $*...
|
||||||
|
|
Loading…
Reference in a new issue