commit 4569add3a27a58457e0fb0379932a98868ae9fe8
parent a45c8561f198fb8ccdb58bc462d79efaea74587d
Author: sin <sin@2f30.org>
Date: Tue, 13 May 2014 16:22:19 +0100
Prefix token enumeration constants with 'T'
Diffstat:
M | debug.c | | | 22 | +++++++++++----------- |
M | lexer.c | | | 44 | ++++++++++++++++++++++---------------------- |
M | lexer.h | | | 22 | +++++++++++----------- |
M | repl.c | | | 2 | +- |
4 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/debug.c b/debug.c
@@ -13,37 +13,37 @@ printtok(struct tok *t)
if (!s)
return;
switch (t->type) {
- case Error:
+ case TError:
printf("token: error, value: '%s'", s);
break;
- case Eof:
+ case TEof:
printf("token: eof");
break;
- case Identifier:
+ case TIdentifier:
printf("token: identifier, value: '%s'", s);
break;
- case Boolean:
+ case TBoolean:
printf("token: boolean, value: '%s'", s);
break;
- case Number:
+ case TNumber:
printf("token number, value: '%s'", s);
break;
- case Character:
+ case TCharacter:
printf("token character, value: '%s'", s);
break;
- case String:
+ case TString:
printf("token string, value: '%s'", s);
break;
- case Lparen:
+ case TLparen:
printf("token: lparen, value: '%s'", s);
break;
- case Rparen:
+ case TRparen:
printf("token rparen, value: '%s'", s);
break;
- case Quote:
+ case TQuote:
printf("token quote, value: '%s'", s);
break;
- case Dot:
+ case TDot:
printf("token dot, value: '%s'", s);
break;
default:
diff --git a/lexer.c b/lexer.c
@@ -78,14 +78,14 @@ again:
break;
case State_Identifier:
if (delim(*e) != 0) {
- tok.type = Identifier;
+ tok.type = TIdentifier;
tok.s = s;
tok.e = e;
ungetc(*e, in);
return tok;
}
if (isalnum(*e) == 0) {
- tok.type = Error;
+ tok.type = TError;
tok.s = "malformed identifier";
tok.e = NULL;
return tok;
@@ -97,7 +97,7 @@ again:
else if (*e == '\\')
state = State_Probable_Character;
else {
- tok.type = Error;
+ tok.type = TError;
tok.s = "not a boolean or a character";
tok.e = NULL;
return tok;
@@ -105,26 +105,26 @@ again:
break;
case State_Boolean:
if (delim(*e) != 0) {
- tok.type = Boolean;
+ tok.type = TBoolean;
tok.s = s;
tok.e = e;
ungetc(*e, in);
return tok;
}
- tok.type = Error;
+ tok.type = TError;
tok.s = "missing delimiter after boolean";
tok.e = NULL;
return tok;
case State_Number:
if (delim(*e) != 0) {
- tok.type = Number;
+ tok.type = TNumber;
tok.s = s;
tok.e = e;
ungetc(*e, in);
return tok;
}
if (isdigit(*e) == 0) {
- tok.type = Error;
+ tok.type = TError;
tok.s = "not a number";
tok.e = NULL;
return tok;
@@ -132,7 +132,7 @@ again:
break;
case State_Signed_Number:
if (isdigit(*e) == 0) {
- tok.type = Error;
+ tok.type = TError;
tok.s = "not a number";
tok.e = NULL;
return tok;
@@ -143,7 +143,7 @@ again:
if (isalpha(*e) != 0) {
state = State_Character;
} else {
- tok.type = Error;
+ tok.type = TError;
tok.s = "expected character constant";
tok.e = NULL;
return tok;
@@ -151,46 +151,46 @@ again:
break;
case State_Character:
if (delim(*e) != 0) {
- tok.type = Character;
+ tok.type = TCharacter;
tok.s = s;
tok.e = e;
ungetc(*e, in);
return tok;
}
- tok.type = Error;
+ tok.type = TError;
tok.s = "missing delimiter after character constant";
tok.e = NULL;
return tok;
case State_Probable_String:
if (*e == '"')
- state = String;
+ state = State_String;
break;
case State_String:
- tok.type = String;
+ tok.type = TString;
tok.s = s;
tok.e = e;
ungetc(*e, in);
return tok;
case State_Lparen:
- tok.type = Lparen;
+ tok.type = TLparen;
tok.s = s;
tok.e = e;
ungetc(*e, in);
return tok;
case State_Rparen:
- tok.type = Rparen;
+ tok.type = TRparen;
tok.s = s;
tok.e = e;
ungetc(*e, in);
return tok;
case State_Quote:
- tok.type = Quote;
+ tok.type = TQuote;
tok.s = s;
tok.e = e;
ungetc(*e, in);
return tok;
case State_Dot:
- tok.type = Dot;
+ tok.type = TDot;
tok.s = s;
tok.e = e;
ungetc(*e, in);
@@ -200,12 +200,12 @@ again:
goto again;
break;
case State_Illegal_Input:
- tok.type = Error;
+ tok.type = TError;
tok.s = "illegal input";
tok.e = NULL;
return tok;
default:
- tok.type = Error;
+ tok.type = TError;
tok.s = "internal lex error";
tok.e = NULL;
return tok;
@@ -213,18 +213,18 @@ again:
e++;
}
if (e == &buf[MAXTOKSIZE]) {
- tok.type = Error;
+ tok.type = TError;
tok.s = "reached the maximum token size";
tok.e = NULL;
return tok;
}
if (state != State_Se) {
- tok.type = Error;
+ tok.type = TError;
tok.s = "unexpected EOF encountered";
tok.e = NULL;
return tok;
}
- tok.type = Eof;
+ tok.type = TEof;
tok.s = "reached the end-of-file";
tok.e = NULL;
return tok;
diff --git a/lexer.h b/lexer.h
@@ -1,16 +1,16 @@
/* See LICENSE file for copyright and license details. */
enum toktype {
- Error = -2,
- Eof = -1,
- Identifier,
- Boolean,
- Number,
- Character,
- String,
- Lparen,
- Rparen,
- Quote,
- Dot
+ TError = -2,
+ TEof = -1,
+ TIdentifier,
+ TBoolean,
+ TNumber,
+ TCharacter,
+ TString,
+ TLparen,
+ TRparen,
+ TQuote,
+ TDot
};
struct tok {
diff --git a/repl.c b/repl.c
@@ -13,7 +13,7 @@ lexertest(FILE *in)
printtok(&tok);
putchar('\n');
fflush(stdout);
- } while (tok.type != Eof && tok.type != Error);
+ } while (tok.type != TEof && tok.type != TError);
}
int