mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-25 13:11:00 +00:00
[qfcc] Move keyword and directive structs
The end goal is to share the tokenisation between the C-like languages, and maybe even Pascal.
This commit is contained in:
parent
56f0c3f821
commit
2d362c445c
4 changed files with 39 additions and 54 deletions
|
@ -30,6 +30,19 @@
|
||||||
|
|
||||||
#include "QF/dstring.h"
|
#include "QF/dstring.h"
|
||||||
|
|
||||||
|
#include "specifier.h"
|
||||||
|
|
||||||
|
typedef struct keyword_s {
|
||||||
|
const char *name;
|
||||||
|
int value;
|
||||||
|
specifier_t spec;
|
||||||
|
} keyword_t;
|
||||||
|
|
||||||
|
typedef struct directive_s {
|
||||||
|
const char *name;
|
||||||
|
int value;
|
||||||
|
} directive_t;
|
||||||
|
|
||||||
typedef struct rua_loc_s {
|
typedef struct rua_loc_s {
|
||||||
int line, column;
|
int line, column;
|
||||||
int last_line, last_column;
|
int last_line, last_column;
|
||||||
|
|
|
@ -1548,17 +1548,6 @@ identifier
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
|
||||||
typedef struct keyword_s {
|
|
||||||
const char *name;
|
|
||||||
int value;
|
|
||||||
specifier_t spec;
|
|
||||||
} keyword_t;
|
|
||||||
|
|
||||||
typedef struct directive_s {
|
|
||||||
const char *name;
|
|
||||||
int value;
|
|
||||||
} directive_t;
|
|
||||||
|
|
||||||
static __attribute__((used)) keyword_t glsl_keywords[] = {
|
static __attribute__((used)) keyword_t glsl_keywords[] = {
|
||||||
{"const", 0},
|
{"const", 0},
|
||||||
{"uniform", 0},
|
{"uniform", 0},
|
||||||
|
|
|
@ -371,17 +371,6 @@ pp_vnumber '({s}*{m}?{pp_number}){2,4}{s}*'{ULFD}?
|
||||||
|
|
||||||
#define ARRCOUNT(_k) (sizeof (_k) / sizeof (_k[0]))
|
#define ARRCOUNT(_k) (sizeof (_k) / sizeof (_k[0]))
|
||||||
|
|
||||||
typedef struct keyword_s {
|
|
||||||
const char *name;
|
|
||||||
int value;
|
|
||||||
specifier_t spec;
|
|
||||||
} keyword_t;
|
|
||||||
|
|
||||||
typedef struct directive_s {
|
|
||||||
const char *name;
|
|
||||||
int value;
|
|
||||||
} directive_t;
|
|
||||||
|
|
||||||
// preprocessor directives in ruamoko and quakec
|
// preprocessor directives in ruamoko and quakec
|
||||||
static directive_t rua_directives[] = {
|
static directive_t rua_directives[] = {
|
||||||
{"include", PRE_INCLUDE},
|
{"include", PRE_INCLUDE},
|
||||||
|
|
|
@ -210,40 +210,34 @@ FRAMEID {ID}(\.{ID})*
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *name;
|
|
||||||
int value;
|
|
||||||
type_t *type;
|
|
||||||
} keyword_t;
|
|
||||||
|
|
||||||
static keyword_t keywords[] = {
|
static keyword_t keywords[] = {
|
||||||
{"real", TYPE, &type_float},
|
{"real", TYPE, .spec = { .type = &type_float } },
|
||||||
{"string", TYPE, &type_string},
|
{"string", TYPE, .spec = { .type = &type_string } },
|
||||||
{"vector", TYPE, &type_vector},
|
{"vector", TYPE, .spec = { .type = &type_vector } },
|
||||||
{"entity", TYPE, &type_entity},
|
{"entity", TYPE, .spec = { .type = &type_entity } },
|
||||||
{"quaternion", TYPE, &type_quaternion},
|
{"quaternion", TYPE, .spec = { .type = &type_quaternion } },
|
||||||
{"integer", TYPE, &type_int},
|
{"integer", TYPE, .spec = { .type = &type_int } },
|
||||||
|
|
||||||
{"program", PROGRAM, 0},
|
{"program", PROGRAM, .spec = {} },
|
||||||
{"var", VAR, 0},
|
{"var", VAR, .spec = {} },
|
||||||
{"array", ARRAY, 0},
|
{"array", ARRAY, .spec = {} },
|
||||||
{"of", OF, 0},
|
{"of", OF, .spec = {} },
|
||||||
{"function", FUNCTION, 0},
|
{"function", FUNCTION, .spec = {} },
|
||||||
{"procedure", PROCEDURE, 0},
|
{"procedure", PROCEDURE, .spec = {} },
|
||||||
{"begin", PBEGIN, 0},
|
{"begin", PBEGIN, .spec = {} },
|
||||||
{"end", END, 0},
|
{"end", END, .spec = {} },
|
||||||
{"if", IF, 0},
|
{"if", IF, .spec = {} },
|
||||||
{"then", THEN, 0},
|
{"then", THEN, .spec = {} },
|
||||||
{"else", ELSE, 0},
|
{"else", ELSE, .spec = {} },
|
||||||
{"while", WHILE, 0},
|
{"while", WHILE, .spec = {} },
|
||||||
{"do", DO, 0},
|
{"do", DO, .spec = {} },
|
||||||
{"or", ADDOP, 0},
|
{"or", ADDOP, .spec = {} },
|
||||||
{"div", MULOP, 0},
|
{"div", MULOP, .spec = {} },
|
||||||
{"mod", MULOP, 0},
|
{"mod", MULOP, .spec = {} },
|
||||||
{"and", MULOP, 0},
|
{"and", MULOP, .spec = {} },
|
||||||
{"not", NOT, 0},
|
{"not", NOT, .spec = {} },
|
||||||
|
|
||||||
{"return", RETURN, 0},
|
{"return", RETURN, .spec = {} },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
|
@ -270,7 +264,7 @@ keyword_or_id (YYSTYPE *lval, const char *token)
|
||||||
if (keyword->value == ADDOP || keyword->value == MULOP) {
|
if (keyword->value == ADDOP || keyword->value == MULOP) {
|
||||||
lval->op = token[0];
|
lval->op = token[0];
|
||||||
} else {
|
} else {
|
||||||
lval->type = keyword->type;
|
lval->type = keyword->spec.type;
|
||||||
}
|
}
|
||||||
return keyword->value;
|
return keyword->value;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue