mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 14:21:36 +00:00
Starting some parsing
This commit is contained in:
parent
9b6598f049
commit
4f611475de
2 changed files with 56 additions and 14 deletions
31
lexer.c
31
lexer.c
|
@ -559,20 +559,25 @@ int lex_do(lex_file *lex)
|
|||
lex->tok->ttype = TOKEN_IDENT;
|
||||
|
||||
v = lex->tok->value;
|
||||
if (!strcmp(v, "void") ||
|
||||
!strcmp(v, "int") ||
|
||||
!strcmp(v, "float") ||
|
||||
!strcmp(v, "vector") )
|
||||
{
|
||||
if (!strcmp(v, "void")) {
|
||||
lex->tok->ttype = TOKEN_TYPENAME;
|
||||
switch (v[1]) {
|
||||
case 'o': lex->tok->constval.t = TYPE_VOID; break;
|
||||
case 'n': lex->tok->constval.t = TYPE_INTEGER; break;
|
||||
case 'l': lex->tok->constval.t = TYPE_FLOAT; break;
|
||||
case 'e': lex->tok->constval.t = TYPE_VECTOR; break;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(v, "for") ||
|
||||
lex->tok->constval.t = TYPE_VOID;
|
||||
} else if (!strcmp(v, "int")) {
|
||||
lex->tok->ttype = TOKEN_TYPENAME;
|
||||
lex->tok->constval.t = TYPE_INTEGER;
|
||||
} else if (!strcmp(v, "float")) {
|
||||
lex->tok->ttype = TOKEN_TYPENAME;
|
||||
lex->tok->constval.t = TYPE_FLOAT;
|
||||
} else if (!strcmp(v, "string")) {
|
||||
lex->tok->ttype = TOKEN_TYPENAME;
|
||||
lex->tok->constval.t = TYPE_STRING;
|
||||
} else if (!strcmp(v, "entity")) {
|
||||
lex->tok->ttype = TOKEN_TYPENAME;
|
||||
lex->tok->constval.t = TYPE_ENTITY;
|
||||
} else if (!strcmp(v, "vector")) {
|
||||
lex->tok->ttype = TOKEN_TYPENAME;
|
||||
lex->tok->constval.t = TYPE_VECTOR;
|
||||
} else if (!strcmp(v, "for") ||
|
||||
!strcmp(v, "while") ||
|
||||
!strcmp(v, "do"))
|
||||
lex->tok->ttype = TOKEN_KEYWORD;
|
||||
|
|
39
parser.c
39
parser.c
|
@ -1,7 +1,44 @@
|
|||
#include "gmqcc.h"
|
||||
#include "lexer.h"
|
||||
|
||||
typedef struct {
|
||||
lex_file *lex;
|
||||
int tok;
|
||||
} parser_t;
|
||||
|
||||
bool parser_do(parser_t *parser)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parser_compile(const char *filename)
|
||||
{
|
||||
return false;
|
||||
parser_t *parser;
|
||||
|
||||
parser = (parser_t*)mem_a(sizeof(parser_t));
|
||||
if (!parser)
|
||||
return false;
|
||||
|
||||
parser->lex = lex_open(filename);
|
||||
|
||||
if (!parser->lex) {
|
||||
printf("failed to open file \"%s\"\n", filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (parser->tok = lex_do(parser->lex);
|
||||
parser->tok != TOKEN_EOF && parser->tok < TOKEN_ERROR;
|
||||
parser->tok = lex_do(parser->lex))
|
||||
{
|
||||
if (!parser_do(parser)) {
|
||||
printf("parse error\n");
|
||||
lex_close(parser->lex);
|
||||
mem_d(parser);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
lex_close(parser->lex);
|
||||
mem_d(parser);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue