X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Flexer%2Ftoken.h;h=8ec28f3714ba54046f10c910e6276b2088df6eef;hb=cee6f0eb54144da7034566fa1bcdcee22337ae6a;hp=cab1a8cf9c63d011b3788e8a0123ba7acf19dd34;hpb=1d424c5e30a08aa1047c47a2f8a2fe1e02d02a3e;p=pspp diff --git a/src/language/lexer/token.h b/src/language/lexer/token.h index cab1a8cf9c..8ec28f3714 100644 --- a/src/language/lexer/token.h +++ b/src/language/lexer/token.h @@ -17,29 +17,52 @@ #ifndef TOKEN_H #define TOKEN_H 1 +#include #include +#include "libpspp/assertion.h" #include "libpspp/str.h" #include "data/identifier.h" -/* A PSPP syntax token. - - The 'type' member is used by the scanner (see scan.h) for SCAN_* values as - well, which is why it is not declared as type "enum token_type". */ +/* A PSPP syntax token. */ struct token { - int type; /* Usually a "enum token_type" value. */ + enum token_type type; double number; struct substring string; }; -#define TOKEN_INITIALIZER(TYPE, NUMBER, STRING) \ - { TYPE, NUMBER, SS_LITERAL_INITIALIZER (STRING) } - -void token_init (struct token *); +void token_copy (struct token *, const struct token *); void token_uninit (struct token *); +bool token_equal (const struct token *, const struct token *); + char *token_to_string (const struct token *); void token_print (const struct token *, FILE *); +static inline bool token_is_number (const struct token *); +static inline double token_number (const struct token *); +bool token_is_integer (const struct token *); +long token_integer (const struct token *); +static inline bool token_is_string (const struct token *); + +static inline bool +token_is_number (const struct token *t) +{ + return t->type == T_POS_NUM || t->type == T_NEG_NUM; +} + +static inline double +token_number (const struct token *t) +{ + assert (token_is_number (t)); + return t->number; +} + +static inline bool +token_is_string (const struct token *t) +{ + return t->type == T_STRING; +} + #endif /* token.h */