Add character literal parsing
This commit is contained in:
parent
2345931528
commit
9ff658615b
31
src/Lexer.c
31
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)) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user