Add character literal parsing

This commit is contained in:
Curle 2020-11-22 00:41:48 +00:00
parent 2345931528
commit 9ff658615b
Signed by: TheCurle
GPG Key ID: 5942F13718443F79

View File

@ -108,6 +108,29 @@ static int ReadIdentifier(int Char, char* Buffer, int Limit) {
return ind; 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 * This function is what defines the valid keywords for the language
* //TODO: move this to a static list? * //TODO: move this to a static list?
@ -307,6 +330,14 @@ int Tokenise(struct Token* Token) {
} }
break; break;
case '\'':
Token->value = ReadCharLiteral();
Token->type = LI_INT;
if(NextChar() != '\'')
Die("Expected '\\'' at the end of a character.");
break;
default: default:
if(isdigit(Char)) { if(isdigit(Char)) {