[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[misc 11/18] identifier: New function token_type_to_string().
From: |
Ben Pfaff |
Subject: |
[misc 11/18] identifier: New function token_type_to_string(). |
Date: |
Sat, 11 Dec 2010 22:20:05 -0800 |
This is useful for debugging and testing code.
---
src/data/identifier.c | 16 ++++++++++
src/data/identifier.h | 79 ++++++++++++++++++++++++++----------------------
2 files changed, 59 insertions(+), 36 deletions(-)
diff --git a/src/data/identifier.c b/src/data/identifier.c
index 1e149b8..498f5ea 100644
--- a/src/data/identifier.c
+++ b/src/data/identifier.c
@@ -31,6 +31,22 @@
#include "gl/c-ctype.h"
+/* Tokens. */
+
+const char *
+token_type_to_string (enum token_type type)
+{
+ switch (type)
+ {
+#define TOKEN_TYPE(TYPE) case T_##TYPE: return #TYPE;
+ TOKEN_TYPES
+#undef TOKEN_TYPE
+ case TOKEN_N_TYPES:
+ default:
+ return "unknown token type";
+ }
+}
+
/* Recognizing identifiers. */
static bool
diff --git a/src/data/identifier.h b/src/data/identifier.h
index 02fc0db..fe030d1 100644
--- a/src/data/identifier.h
+++ b/src/data/identifier.h
@@ -22,47 +22,54 @@
#include <unitypes.h>
#include "libpspp/str.h"
+#define TOKEN_TYPES \
+ TOKEN_TYPE(ID) /* Identifier. */ \
+ TOKEN_TYPE(POS_NUM) /* Positive number. */ \
+ TOKEN_TYPE(NEG_NUM) /* Negative number. */ \
+ TOKEN_TYPE(STRING) /* Quoted string. */ \
+ TOKEN_TYPE(STOP) /* End of input. */ \
+ \
+ TOKEN_TYPE(ENDCMD) /* . */ \
+ TOKEN_TYPE(PLUS) /* + */ \
+ TOKEN_TYPE(DASH) /* - */ \
+ TOKEN_TYPE(ASTERISK) /* * */ \
+ TOKEN_TYPE(SLASH) /* / */ \
+ TOKEN_TYPE(EQUALS) /* = */ \
+ TOKEN_TYPE(LPAREN) /* ( */ \
+ TOKEN_TYPE(RPAREN) /* ) */ \
+ TOKEN_TYPE(LBRACK) /* [ */ \
+ TOKEN_TYPE(RBRACK) /* ] */ \
+ TOKEN_TYPE(COMMA) /* , */ \
+ \
+ TOKEN_TYPE(AND) /* AND */ \
+ TOKEN_TYPE(OR) /* OR */ \
+ TOKEN_TYPE(NOT) /* NOT */ \
+ \
+ TOKEN_TYPE(EQ) /* EQ */ \
+ TOKEN_TYPE(GE) /* GE or >= */ \
+ TOKEN_TYPE(GT) /* GT or > */ \
+ TOKEN_TYPE(LE) /* LE or <= */ \
+ TOKEN_TYPE(LT) /* LT or < */ \
+ TOKEN_TYPE(NE) /* NE or ~= */ \
+ \
+ TOKEN_TYPE(ALL) /* ALL */ \
+ TOKEN_TYPE(BY) /* BY */ \
+ TOKEN_TYPE(TO) /* TO */ \
+ TOKEN_TYPE(WITH) /* WITH */ \
+ \
+ TOKEN_TYPE(EXP) /* ** */
+
/* Token types. */
enum token_type
{
- T_ID = 1, /* Identifier. */
- T_POS_NUM, /* Positive number. */
- T_NEG_NUM, /* Negative number. */
- T_STRING, /* Quoted string. */
- T_STOP, /* End of input. */
-
- T_ENDCMD, /* End of command (e.g. '.'). */
-
- T_PLUS, /* + */
- T_DASH, /* - */
- T_ASTERISK, /* * */
- T_SLASH, /* / */
- T_EQUALS, /* = */
- T_LPAREN, /* ( */
- T_RPAREN, /* ) */
- T_LBRACK, /* [ */
- T_RBRACK, /* ] */
- T_COMMA, /* , */
-
- T_AND, /* AND */
- T_OR, /* OR */
- T_NOT, /* NOT */
-
- T_EQ, /* EQ */
- T_GE, /* GE or >= */
- T_GT, /* GT or > */
- T_LE, /* LE or <= */
- T_LT, /* LT or < */
- T_NE, /* NE or ~= */
-
- T_ALL, /* ALL */
- T_BY, /* BY */
- T_TO, /* TO */
- T_WITH, /* WITH */
-
- T_EXP, /* ** */
+#define TOKEN_TYPE(TYPE) T_##TYPE,
+ TOKEN_TYPES
+ TOKEN_N_TYPES
+#undef TOKEN_TYPE
};
+const char *token_type_to_string (enum token_type);
+
/* Tokens. */
bool lex_is_keyword (enum token_type);
--
1.7.1
- [misc 04/18] covariance: Fix const-ness of covariance_calculate[_unnormalized] retval., (continued)
- [misc 04/18] covariance: Fix const-ness of covariance_calculate[_unnormalized] retval., Ben Pfaff, 2010/12/12
- [misc 08/18] DEBUG XFORM FAIL: Issue an error message as part of transformation., Ben Pfaff, 2010/12/12
- [misc 18/18] value-parser: Remove redundant call to lex_force_string() in parse_value()., Ben Pfaff, 2010/12/12
- [misc 17/18] GET DATA: Fix punctuation in error message., Ben Pfaff, 2010/12/12
- [misc 07/18] INPUT PROGRAM: Remove unused enumeration., Ben Pfaff, 2010/12/12
- [misc 03/18] ONEWAY: Fix warning for passing "const" pointer as non-const parameter., Ben Pfaff, 2010/12/12
- [misc 09/18] q2c: Prefer lex_match_id() over lex_match_hyphenated_word() in emitted code., Ben Pfaff, 2010/12/12
- [misc 02/18] mann-whitney: Suppress GCC warning about unused parameter., Ben Pfaff, 2010/12/12
- [misc 05/18] categoricals: Make parameter to categoricals_done() const., Ben Pfaff, 2010/12/12
- [misc 13/18] float-format: Don't translate test strings., Ben Pfaff, 2010/12/12
- [misc 11/18] identifier: New function token_type_to_string().,
Ben Pfaff <=
- Re: [misc 00/18] miscellaneous minor improvements, John Darrington, 2010/12/12