mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-31 03:50:36 +00:00
Fix parser bug
This commit is contained in:
parent
506f4bca1b
commit
248cd7af94
4 changed files with 30 additions and 24 deletions
4
README
4
README
|
@ -30,6 +30,10 @@ typedef.c
|
|||
complicated than it sounds. This handles all typedefs, and even recrusive
|
||||
typedefs.
|
||||
|
||||
alloc.c
|
||||
This is just an allocator for the compiler, it's used for debugging reasons
|
||||
only.
|
||||
|
||||
README
|
||||
This is the file you're currently reading
|
||||
|
||||
|
|
11
gmqcc.h
11
gmqcc.h
|
@ -155,12 +155,11 @@ struct lex_file {
|
|||
#define TOKEN_GOTO 7
|
||||
#define TOKEN_FOR 8 // extension
|
||||
#define TOKEN_TYPEDEF 9 // extension
|
||||
#define TOKEN_INT 10 // extension
|
||||
#define TOKEN_VOID 11
|
||||
#define TOKEN_STRING 12
|
||||
#define TOKEN_FLOAT 13
|
||||
#define TOKEN_VECTOR 14
|
||||
#define TOKEN_ENTITY 15
|
||||
#define TOKEN_VOID 10
|
||||
#define TOKEN_STRING 11
|
||||
#define TOKEN_FLOAT 12
|
||||
#define TOKEN_VECTOR 13
|
||||
#define TOKEN_ENTITY 14
|
||||
|
||||
/*
|
||||
* Lexer state constants, these are numbers for where exactly in
|
||||
|
|
1
lex.c
1
lex.c
|
@ -37,7 +37,6 @@ static const char *const lex_keywords[] = {
|
|||
"for", "typedef",
|
||||
|
||||
/* types */
|
||||
"int",
|
||||
"void",
|
||||
"string",
|
||||
"float",
|
||||
|
|
38
parse.c
38
parse.c
|
@ -98,13 +98,7 @@
|
|||
}
|
||||
|
||||
void parse_debug(struct parsenode *tree) {
|
||||
while (tree && tree->next != NULL) {
|
||||
/* skip blanks */
|
||||
if (tree->type == 0) {
|
||||
tree = tree->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
while (tree) {
|
||||
switch (tree->type) {
|
||||
case PARSE_TYPE_ADD: STORE("OPERATOR: ADD \n");
|
||||
case PARSE_TYPE_BAND: STORE("OPERATOR: BITAND \n");
|
||||
|
@ -162,10 +156,13 @@ void parse_debug(struct parsenode *tree) {
|
|||
* like syntax check for legal use -- like it should as it's a TODO item
|
||||
* which is not implemented
|
||||
*/
|
||||
#define PARSE_TODO(X) { \
|
||||
token = lex_token(file); \
|
||||
PARSE_TREE_ADD(X); \
|
||||
break; \
|
||||
#define PARSE_TODO(X) { \
|
||||
token = lex_token(file); \
|
||||
while (token != '\n') { \
|
||||
token = lex_token(file); \
|
||||
} \
|
||||
PARSE_TREE_ADD(X); \
|
||||
break; \
|
||||
}
|
||||
|
||||
void parse_clear(struct parsenode *tree) {
|
||||
|
@ -191,7 +188,8 @@ int parse(struct lex_file *file) {
|
|||
parseroot = mem_a(sizeof(struct parsenode));
|
||||
if (!parseroot)
|
||||
return error(ERROR_INTERNAL, "Ran out of memory", " ");
|
||||
parsetree = parseroot;
|
||||
parsetree = parseroot;
|
||||
parsetree->type = -1; /* not a valid type -- root element */
|
||||
}
|
||||
|
||||
int token = 0;
|
||||
|
@ -203,8 +201,8 @@ int parse(struct lex_file *file) {
|
|||
switch (token) {
|
||||
case TOKEN_IF:
|
||||
token = lex_token(file);
|
||||
//while ((token == ' ' || token == '\n') && file->length >= 0)
|
||||
// token = lex_token(file);
|
||||
while ((token == ' ' || token == '\n') && file->length >= 0)
|
||||
token = lex_token(file);
|
||||
|
||||
//if (token != '(')
|
||||
// error(ERROR_PARSE, "Expected `(` after if\n", "");
|
||||
|
@ -212,18 +210,19 @@ int parse(struct lex_file *file) {
|
|||
PARSE_TREE_ADD(PARSE_TYPE_IF);
|
||||
break;
|
||||
case TOKEN_ELSE:
|
||||
token = lex_token(file);
|
||||
//token = lex_token(file);
|
||||
//while ((token == ' ' || token == '\n') && file->length >= 0)
|
||||
// token = lex_token(file);
|
||||
|
||||
PARSE_TREE_ADD(PARSE_TYPE_ELSE);
|
||||
break;
|
||||
case TOKEN_FOR:
|
||||
token = lex_token(file);
|
||||
//token = lex_token(file);
|
||||
//while ((token == ' ' || token == '\n') && file->length >= 0)
|
||||
// token = lex_token(file);
|
||||
|
||||
PARSE_TREE_ADD(PARSE_TYPE_FOR);
|
||||
//PARSE_TREE_ADD(PARSE_TYPE_FOR);
|
||||
PARSE_TODO(PARSE_TYPE_FOR);
|
||||
break;
|
||||
|
||||
/*
|
||||
|
@ -281,6 +280,11 @@ int parse(struct lex_file *file) {
|
|||
token = lex_token(file);
|
||||
break;
|
||||
|
||||
case '.':
|
||||
token = lex_token(file);
|
||||
PARSE_TREE_ADD(PARSE_TYPE_DOT);
|
||||
break;
|
||||
|
||||
case '(':
|
||||
token = lex_token(file);
|
||||
PARSE_TREE_ADD(PARSE_TYPE_LPARTH);
|
||||
|
|
Loading…
Reference in a new issue