/* PowerBASIC Keywords Table */
#ifndef PB_KEYWORDS_INC
#define PB_KEYWORDS_INC

typedef struct PbKeywordEntry {
    const char* word;
    int type;
    int flags;
} PbKeywordEntry;

/* Keyword flags */
#define KWF_STATEMENT   0x01
#define KWF_DECL        0x02
#define KWF_TYPE        0x04
#define KWF_CONTROL     0x08
#define KWF_OPERATOR    0x10
#define KWF_DIRECTIVE   0x20

/* Token types for PB */
enum PbTokenTypes {
    /* Directives */
    PB_TK_COMPILE = 1000,
    PB_TK_DIM_ALL,
    PB_TK_DEBUG,
    PB_TK_INCLUDE,
    PB_TK_IF_DEF,
    
    /* Multi-language directives */
    TK_DIRECTIVE_CC,
    TK_DIRECTIVE_ENDC,
    TK_DIRECTIVE_ASM,
    TK_DIRECTIVE_ENDASM,
    TK_DIRECTIVE_FASM,
    TK_DIRECTIVE_ENDFASM,
    TK_DIRECTIVE_JS,
    TK_DIRECTIVE_ENDJS,
    TK_DIRECTIVE_PB,
    TK_DIRECTIVE_ENDPB,
    
    /* PB Keywords */
    PB_TK_SUB,
    PB_TK_FUNCTION,
    PB_TK_END,
    PB_TK_DECLARE,
    PB_TK_LIB,
    PB_TK_ALIAS,
    PB_TK_BYVAL,
    PB_TK_BYREF,
    PB_TK_AS,
    PB_TK_DIM,
    PB_TK_REDIM,
    PB_TK_PRESERVE,
    PB_TK_GLOBAL,
    PB_TK_LOCAL,
    PB_TK_STATIC,
    PB_TK_SHARED,
    PB_TK_TYPE,
    PB_TK_UNION,
    PB_TK_ENUM,
    PB_TK_IF,
    PB_TK_THEN,
    PB_TK_ELSE,
    PB_TK_ELSEIF,
    PB_TK_ENDIF,
    PB_TK_SELECT,
    PB_TK_CASE,
    PB_TK_FOR,
    PB_TK_NEXT,
    PB_TK_TO,
    PB_TK_STEP,
    PB_TK_EACH,
    PB_TK_IN,
    PB_TK_DO,
    PB_TK_LOOP,
    PB_TK_WHILE,
    PB_TK_WEND,
    PB_TK_UNTIL,
    PB_TK_EXIT,
    PB_TK_CONTINUE,
    PB_TK_GOTO,
    PB_TK_GOSUB,
    PB_TK_RETURN,
    PB_TK_CALL,
    PB_TK_PRINT,
    PB_TK_INPUT,
    PB_TK_OPEN,
    PB_TK_CLOSE,
    PB_TK_GET,
    PB_TK_PUT,
    PB_TK_SEEK,
    PB_TK_LINE,
    PB_TK_ERROR,
    PB_TK_ON,
    PB_TK_RESUME,
    PB_TK_TRY,
    PB_TK_CATCH,
    PB_TK_FINALLY,
    
    /* Types */
    PB_TK_INTEGER,
    PB_TK_LONG,
    PB_TK_QUAD,
    PB_TK_BYTE,
    PB_TK_WORD,
    PB_TK_DWORD,
    PB_TK_SINGLE,
    PB_TK_DOUBLE,
    PB_TK_EXT,
    PB_TK_CURRENCY,
    PB_TK_STRING,
    PB_TK_VARIANT,
    PB_TK_OBJECT,
    PB_TK_GUID,
    PB_TK_ANY,
    PB_TK_ASCII,
    PB_TK_WSTRING,
    
    /* Operators */
    PB_TK_AND,
    PB_TK_OR,
    PB_TK_XOR,
    PB_TK_NOT,
    PB_TK_EQV,
    PB_TK_IMP,
    PB_TK_MOD,
    PB_TK_LIKE,
    PB_TK_IS,
    PB_TK_NEW,
};

/* Main keyword table - sorted for binary search */
static const PbKeywordEntry PB_KEYWORDS[] = {
    {"#ASM", TK_DIRECTIVE_ASM, KWF_DIRECTIVE},
    {"#CCODE", TK_DIRECTIVE_CC, KWF_DIRECTIVE},
    {"#COMPILE", PB_TK_COMPILE, KWF_DIRECTIVE},
    {"#DEBUG", PB_TK_DEBUG, KWF_DIRECTIVE},
    {"#DIM", PB_TK_DIM_ALL, KWF_DIRECTIVE},
    {"#ENDASM", TK_DIRECTIVE_ENDASM, KWF_DIRECTIVE},
    {"#ENDC", TK_DIRECTIVE_ENDC, KWF_DIRECTIVE},
    {"#ENDFASM", TK_DIRECTIVE_ENDFASM, KWF_DIRECTIVE},
    {"#ENDJS", TK_DIRECTIVE_ENDJS, KWF_DIRECTIVE},
    {"#ENDPB", TK_DIRECTIVE_ENDPB, KWF_DIRECTIVE},
    {"#FASM", TK_DIRECTIVE_FASM, KWF_DIRECTIVE},
    {"#IF", PB_TK_IF_DEF, KWF_DIRECTIVE},
    {"#INCLUDE", PB_TK_INCLUDE, KWF_DIRECTIVE},
    {"#JS", TK_DIRECTIVE_JS, KWF_DIRECTIVE},
    {"#PB", TK_DIRECTIVE_PB, KWF_DIRECTIVE},
    {"ALIAS", PB_TK_ALIAS, KWF_DECL},
    {"AND", PB_TK_AND, KWF_OPERATOR},
    {"ANY", PB_TK_ANY, KWF_TYPE},
    {"AS", PB_TK_AS, KWF_STATEMENT},
    {"ASCII", PB_TK_ASCII, KWF_TYPE},
    {"BYTE", PB_TK_BYTE, KWF_TYPE},
    {"BYREF", PB_TK_BYREF, KWF_DECL},
    {"BYVAL", PB_TK_BYVAL, KWF_DECL},
    {"CALL", PB_TK_CALL, KWF_STATEMENT},
    {"CASE", PB_TK_CASE, KWF_CONTROL},
    {"CATCH", PB_TK_CATCH, KWF_CONTROL},
    {"CLOSE", PB_TK_CLOSE, KWF_STATEMENT},
    {"CONTINUE", PB_TK_CONTINUE, KWF_CONTROL},
    {"CURRENCY", PB_TK_CURRENCY, KWF_TYPE},
    {"DECLARE", PB_TK_DECLARE, KWF_DECL},
    {"DIM", PB_TK_DIM, KWF_DECL | KWF_STATEMENT},
    {"DO", PB_TK_DO, KWF_CONTROL},
    {"DOUBLE", PB_TK_DOUBLE, KWF_TYPE},
    {"DWORD", PB_TK_DWORD, KWF_TYPE},
    {"EACH", PB_TK_EACH, KWF_CONTROL},
    {"ELSE", PB_TK_ELSE, KWF_CONTROL},
    {"ELSEIF", PB_TK_ELSEIF, KWF_CONTROL},
    {"END", PB_TK_END, KWF_CONTROL},
    {"ENUM", PB_TK_ENUM, KWF_DECL},
    {"EQV", PB_TK_EQV, KWF_OPERATOR},
    {"ERROR", PB_TK_ERROR, KWF_STATEMENT},
    {"EXIT", PB_TK_EXIT, KWF_CONTROL},
    {"FALSE", PB_TK_FALSE, 0},
    {"FINALLY", PB_TK_FINALLY, KWF_CONTROL},
    {"FOR", PB_TK_FOR, KWF_CONTROL},
    {"FUNCTION", PB_TK_FUNCTION, KWF_DECL},
    {"GET", PB_TK_GET, KWF_STATEMENT},
    {"GLOBAL", PB_TK_GLOBAL, KWF_DECL},
    {"GOSUB", PB_TK_GOSUB, KWF_CONTROL},
    {"GOTO", PB_TK_GOTO, KWF_CONTROL},
    {"GUID", PB_TK_GUID, KWF_TYPE},
    {"IF", PB_TK_IF, KWF_CONTROL},
    {"IMP", PB_TK_IMP, KWF_OPERATOR},
    {"IN", PB_TK_IN, KWF_CONTROL},
    {"INPUT", PB_TK_INPUT, KWF_STATEMENT},
    {"INTEGER", PB_TK_INTEGER, KWF_TYPE},
    {"IS", PB_TK_IS, KWF_OPERATOR},
    {"LIB", PB_TK_LIB, KWF_DECL},
    {"LIKE", PB_TK_LIKE, KWF_OPERATOR},
    {"LINE", PB_TK_LINE, KWF_STATEMENT},
    {"LOCAL", PB_TK_LOCAL, KWF_DECL},
    {"LONG", PB_TK_LONG, KWF_TYPE},
    {"LOOP", PB_TK_LOOP, KWF_CONTROL},
    {"MOD", PB_TK_MOD, KWF_OPERATOR},
    {"NEW", PB_TK_NEW, KWF_STATEMENT},
    {"NEXT", PB_TK_NEXT, KWF_CONTROL},
    {"NOT", PB_TK_NOT, KWF_OPERATOR},
    {"OBJECT", PB_TK_OBJECT, KWF_TYPE},
    {"ON", PB_TK_ON, KWF_CONTROL},
    {"OPEN", PB_TK_OPEN, KWF_STATEMENT},
    {"OR", PB_TK_OR, KWF_OPERATOR},
    {"PRESERVE", PB_TK_PRESERVE, KWF_STATEMENT},
    {"PRINT", PB_TK_PRINT, KWF_STATEMENT},
    {"PUT", PB_TK_PUT, KWF_STATEMENT},
    {"QUAD", PB_TK_QUAD, KWF_TYPE},
    {"REDIM", PB_TK_REDIM, KWF_DECL},
    {"RESUME", PB_TK_RESUME, KWF_CONTROL},
    {"RETURN", PB_TK_RETURN, KWF_CONTROL},
    {"SEEK", PB_TK_SEEK, KWF_STATEMENT},
    {"SELECT", PB_TK_SELECT, KWF_CONTROL},
    {"SHARED", PB_TK_SHARED, KWF_DECL},
    {"SINGLE", PB_TK_SINGLE, KWF_TYPE},
    {"STATIC", PB_TK_STATIC, KWF_DECL},
    {"STEP", PB_TK_STEP, KWF_CONTROL},
    {"STRING", PB_TK_STRING, KWF_TYPE},
    {"SUB", PB_TK_SUB, KWF_DECL},
    {"THEN", PB_TK_THEN, KWF_CONTROL},
    {"TO", PB_TK_TO, KWF_CONTROL},
    {"TRUE", PB_TK_TRUE, 0},
    {"TRY", PB_TK_TRY, KWF_CONTROL},
    {"TYPE", PB_TK_TYPE, KWF_DECL},
    {"UNION", PB_TK_UNION, KWF_DECL},
    {"UNTIL", PB_TK_UNTIL, KWF_CONTROL},
    {"VARIANT", PB_TK_VARIANT, KWF_TYPE},
    {"WEND", PB_TK_WEND, KWF_CONTROL},
    {"WHILE", PB_TK_WHILE, KWF_CONTROL},
    {"WORD", PB_TK_WORD, KWF_TYPE},
    {"WSTRING", PB_TK_WSTRING, KWF_TYPE},
    {"XOR", PB_TK_XOR, KWF_OPERATOR},
};

#define PB_KEYWORD_COUNT (sizeof(PB_KEYWORDS) / sizeof(PB_KEYWORDS[0]))

/* Type suffixes */
static const struct {
    char suffix;
    int type;
    const char* name;
} PB_TYPE_SUFFIXES[] = {
    {'%%', PB_TK_INTEGER, "INTEGER"},
    {'%', PB_TK_LONG, "LONG"},
    {'&', PB_TK_QUAD, "QUAD"},
    {'&&', PB_TK_QUAD, "QUAD"},
    {'!', PB_TK_SINGLE, "SINGLE"},
    {'#', PB_TK_DOUBLE, "DOUBLE"},
    {'##', PB_TK_EXT, "EXTENDED"},
    {'@', PB_TK_CURRENCY, "CURRENCY"},
    {'$', PB_TK_STRING, "STRING"},
    {'$$', PB_TK_WSTRING, "WSTRING"},
    {'??', PB_TK_BYTE, "BYTE"},
    {'???', PB_TK_DWORD, "DWORD"},
};

#endif /* PB_KEYWORDS_INC */
