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;
#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;
}