Character constants now work

git-svn-id: http://picoc.googlecode.com/svn/trunk@102 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-02-24 01:01:02 +00:00
parent e94767ba98
commit 37c2364eff
3 changed files with 10 additions and 6 deletions

11
lex.c
View file

@ -7,7 +7,10 @@
#include "picoc.h" #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 isCidstart(c) (isalpha(c) || (c)=='_' || (c)=='#')
#define isCident(c) (isalnum(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) enum LexToken LexGetCharacterConstant(struct LexState *Lexer, struct Value *Value)
{ {
Value->Typ = &IntType; Value->Typ = &IntType;
Lexer->Pos++;
Value->Val->Integer = LexUnEscapeCharacter(&Lexer->Pos, Lexer->End); 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 \"'\""); LexFail(Lexer, "expected \"'\"");
Lexer->Pos++; Lexer->Pos++;
@ -443,8 +445,7 @@ enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int I
{ {
case TokenStringConstant: LexValue.Typ = CharPtrType; break; case TokenStringConstant: LexValue.Typ = CharPtrType; break;
case TokenIdentifier: LexValue.Typ = NULL; break; case TokenIdentifier: LexValue.Typ = NULL; break;
case TokenIntegerConstant: LexValue.Typ = &IntType; break; case TokenIntegerConstant: case TokenCharacterConstant: LexValue.Typ = &IntType; break;
case TokenCharacterConstant: LexValue.Typ = &CharType; break;
#ifndef NO_FP #ifndef NO_FP
case TokenFPConstant: LexValue.Typ = &FPType; break; case TokenFPConstant: LexValue.Typ = &FPType; break;
#endif #endif

View file

@ -5,4 +5,5 @@ for (Count = -5; Count <= 5; Count++)
printf("Count = %d\n", Count); printf("Count = %d\n", Count);
printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there"); 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');

View file

@ -11,3 +11,5 @@ Count = 3
Count = 4 Count = 4
Count = 5 Count = 5
String 'hello', 'there' is 'hello', 'there' String 'hello', 'there' is 'hello', 'there'
Character 'A' is 'A'
Character 'a' is 'a'