/* * token.h - definition of lexical tokens for D compiler * CSE 413 au07 *TODO: add constants for remaining lexical token classes * (note: integer values do not need to be contiguous, but since * token classes are used in switch statements, it's best to keep * the values relatively small. feel free to change any of these * values - the exact integers assigned to the names don't matter.) */ #ifndef TOKEN_H #define TOKEN_H /*----- Lexical classes -----*/ /*----- EOF, ID, and INT -----*/ #define TOK_EOF 0 /* end of file */ #define TOK_ID 1 /* identifier */ #define TOK_INTGR 2 /* integer */ /*----- D keywords -----*/ #define TOK_INT 10 /* int */ #define TOK_IF 11 /* if */ #define TOK_ELSE 12 /* else */ /*----- Operators, punctuation, and delimiters */ #define LPAREN 20 /* ( */ #define RPAREN 21 /* ) */ #define COMMA 22 /* , */ #define BECOMES 23 /* = */ #define EQUALS 24 /* == */ #define PLUS 25 /* + */ #define MINUS 26 /* - */ /*----- Token type definition and toString function -----*/ /* Length of longest possible identifier + 1 */ #define MAX_ID_LENGTH 31 typedef struct { /* One lexical token: */ int kind; /* Lexical class */ char id[MAX_ID_LENGTH]; /* if kind is TOK_ID, the actual identifier */ int val; /* if kind is TOK_INTGR, the int constant value */ } Token; /* Store a string representation of Token t in s. */ /* pre: s must have enough space for the result. */ void tok2str(Token t, char* s); #endif /* ifndef TOKEN_H */