diff --git a/lex.c b/lex.c index bf2dab0..26a10f3 100644 --- a/lex.c +++ b/lex.c @@ -7,7 +7,10 @@ #include "picoc.h" - +#ifndef isalpha +#define isalpha(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z')) +#define isalnum(c) (isalpha(c) || ((c) >= '0' && (c) <= '9')) +#endif #define isCidstart(c) (isalpha(c) || (c)=='_' || (c)=='#') #define isCident(c) (isalnum(c) || (c)=='_') @@ -229,9 +232,8 @@ enum LexToken LexGetStringConstant(struct LexState *Lexer, struct Value *Value) enum LexToken LexGetCharacterConstant(struct LexState *Lexer, struct Value *Value) { Value->Typ = &IntType; - Lexer->Pos++; Value->Val->Integer = LexUnEscapeCharacter(&Lexer->Pos, Lexer->End); - if (Lexer->Pos != Lexer->End || *Lexer->Pos != '\'') + if (Lexer->Pos != Lexer->End && *Lexer->Pos != '\'') LexFail(Lexer, "expected \"'\""); Lexer->Pos++; @@ -443,8 +445,7 @@ enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int I { case TokenStringConstant: LexValue.Typ = CharPtrType; break; case TokenIdentifier: LexValue.Typ = NULL; break; - case TokenIntegerConstant: LexValue.Typ = &IntType; break; - case TokenCharacterConstant: LexValue.Typ = &CharType; break; + case TokenIntegerConstant: case TokenCharacterConstant: LexValue.Typ = &IntType; break; #ifndef NO_FP case TokenFPConstant: LexValue.Typ = &FPType; break; #endif diff --git a/tests/02_printf.c b/tests/02_printf.c index 8ec8b33..4523acb 100644 --- a/tests/02_printf.c +++ b/tests/02_printf.c @@ -5,4 +5,5 @@ for (Count = -5; Count <= 5; Count++) printf("Count = %d\n", Count); printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there"); -//printf("Character 'a' is '%c'\n", 65); +printf("Character 'A' is '%c'\n", 65); +printf("Character 'a' is '%c'\n", 'a'); diff --git a/tests/02_printf.expect b/tests/02_printf.expect index 5d6e81f..f67a0f6 100644 --- a/tests/02_printf.expect +++ b/tests/02_printf.expect @@ -11,3 +11,5 @@ Count = 3 Count = 4 Count = 5 String 'hello', 'there' is 'hello', 'there' +Character 'A' is 'A' +Character 'a' is 'a'