summaryrefslogtreecommitdiff
path: root/src/token.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/token.h')
-rw-r--r--src/token.h42
1 files changed, 32 insertions, 10 deletions
diff --git a/src/token.h b/src/token.h
index e99294e..1e57662 100644
--- a/src/token.h
+++ b/src/token.h
@@ -3,12 +3,14 @@
#include <string.h>
-/* Token and type definitions shared by lexer, parser, and JIT.
- * The type system uses a base kind plus pointer/array decorations. */
typedef enum {
- TY_INT = 0,
- TY_CHAR = 1,
- TY_BOOL = 2,
+ TY_INT = 0,
+ TY_CHAR = 1,
+ TY_BOOL = 2,
+ TY_VOID = 3,
+ TY_FLOAT = 4,
+ TY_LONG = 5,
+ TY_SHORT = 6,
} _TYBASE;
typedef struct {
@@ -19,9 +21,13 @@ typedef struct {
static inline const char *tybase_name(_TYBASE b) {
switch (b) {
- case TY_INT: return "int";
- case TY_CHAR: return "char";
- case TY_BOOL: return "bool";
+ case TY_INT: return "int";
+ case TY_CHAR: return "char";
+ case TY_BOOL: return "bool";
+ case TY_VOID: return "void";
+ case TY_FLOAT: return "float";
+ case TY_LONG: return "long";
+ case TY_SHORT: return "short";
default: return "?";
}
}
@@ -30,6 +36,10 @@ static inline const char *tybase_name(_TYBASE b) {
_(TK_BEGIN, "begin") \
_(TK_INT, "int") \
_(TK_CHAR, "char") \
+ _(TK_VOID, "void") \
+ _(TK_FLOAT, "float") \
+ _(TK_LONG, "long") \
+ _(TK_SHORT, "short") \
_(TK_ASSIGN, "=") \
_(TK_EQ, "==") \
_(TK_NE, "!=") \
@@ -42,6 +52,9 @@ static inline const char *tybase_name(_TYBASE b) {
_(TK_ELSE, "else") \
_(TK_FOR, "for") \
_(TK_WHILE, "while") \
+ _(TK_DO, "do") \
+ _(TK_BREAK, "break") \
+ _(TK_CONTINUE, "continue") \
_(TK_BOOL, "bool") \
_(TK_IDENT, "ident") \
_(TK_NUMBER, "number") \
@@ -69,6 +82,15 @@ static inline const char *tybase_name(_TYBASE b) {
_(TK_LBRACKET, "[") \
_(TK_RBRACKET, "]") \
_(TK_STRING, "string") \
+ _(TK_PLUS_EQ, "+=") \
+ _(TK_MINUS_EQ, "-=") \
+ _(TK_STAR_EQ, "*=") \
+ _(TK_SLASH_EQ, "/=") \
+ _(TK_INC, "++") \
+ _(TK_DEC, "--") \
+ _(TK_SIZEOF, "sizeof") \
+ _(TK_QUESTION, "?") \
+ _(TK_COLON, ":") \
_(TK_EOF, "eof") \
_(TK_COMMA, ",") \
_(TK_INVALID, "invalid") \
@@ -88,8 +110,8 @@ static const char *_TN[] = {
typedef struct {
_TK kind;
- int val; // only valid if kind == TK_NUMBER
- char *lxem; // malloc’d lexeme string, or NULL
+ int val;
+ char *lxem;
} _T;
static _TK checkkw(const char *kw) {