diff --git a/src/Lexer.c b/src/Lexer.c index 7dce4f1..0fcee47 100644 --- a/src/Lexer.c +++ b/src/Lexer.c @@ -108,6 +108,29 @@ static int ReadIdentifier(int Char, char* Buffer, int Limit) { return ind; } +static int ReadCharLiteral() { + int Char; + Char = NextChar(); + if(Char == '\\') { + switch(Char = NextChar()) { + case 'a': return '\a'; + case 'b': return '\b'; + case 'f': return '\f'; + case 'n': return '\n'; + case 'r': return '\r'; + case 't': return '\t'; + case 'v': return '\v'; + case '\\': return '\\'; + case '"': return '"'; + case '\'': return '\''; + default: + DieChar("Unknown Escape: ", c); + } + } + + return Char; +} + /* * This function is what defines the valid keywords for the language * //TODO: move this to a static list? @@ -307,6 +330,14 @@ int Tokenise(struct Token* Token) { } break; + case '\'': + Token->value = ReadCharLiteral(); + Token->type = LI_INT; + + if(NextChar() != '\'') + Die("Expected '\\'' at the end of a character."); + break; + default: if(isdigit(Char)) {