From: Dale Weiler Date: Mon, 9 Apr 2012 14:14:26 +0000 (-0400) Subject: Some parsing X-Git-Tag: 0.1-rc1~711 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e6a270a7e00abd3bcc1b587594e21ed75e341f43;p=xonotic%2Fgmqcc.git Some parsing --- diff --git a/cpp.c b/cpp.c index e2f8021..62a9819 100644 --- a/cpp.c +++ b/cpp.c @@ -6,5 +6,5 @@ * which is what we parse for the preprocessor here. */ int cpp(struct lex_file *file) { - /* TODO ... */ + /* no return */ } diff --git a/gmqcc b/gmqcc index 257c415..9bc7f27 100755 Binary files a/gmqcc and b/gmqcc differ diff --git a/lex.c b/lex.c index 9d15301..5333171 100644 --- a/lex.c +++ b/lex.c @@ -349,6 +349,7 @@ int lex_debug(struct lex_file *file) { while ((token = lex_token(file)) != ERROR_LEX && file->length >= 0) if (token == LEX_IDENT) printf("%s ", file->lastok); + fputc('\n', stdout); lex_reset(file); return 1; } diff --git a/main.c b/main.c index 248f94f..5134e98 100644 --- a/main.c +++ b/main.c @@ -61,12 +61,11 @@ int main(int argc, char **argv) { if (!fp) { fclose(fp); return error(ERROR_COMPILER, "Source file: %s not found\n", ifile); + } else { + struct lex_file *lex = lex_open(fp); + lex_debug(lex); + parse (lex); + lex_close(lex); } - - struct lex_file *lex = lex_open(fp); - lex_debug(lex); - parse (lex); - lex_close(lex); - return 0; } diff --git a/parse.c b/parse.c index 129bcb1..9398319 100644 --- a/parse.c +++ b/parse.c @@ -23,6 +23,19 @@ #include #include "gmqcc.h" + +static const char *const parse_punct[] = { + "&&", "||", "<=", ">=", "==", "!=", ";", ",", "!", "*", + "/" , "(" , "-" , "+" , "=" , "[" , "]", "{", "}", "...", + "." , "<" , ">" , "#" , "&" , "|" , "$", "@", ":", NULL + /* + * $,@,: are extensions: + * $ is a shorter `self`, so instead of self.frags, $.frags + * @ is a constructor + * : is compiler builtin functions + */ +}; + int parse(struct lex_file *file) { int token = 0; while ((token = lex_token(file)) != ERROR_LEX && \ @@ -42,10 +55,89 @@ int parse(struct lex_file *file) { /* TODO: Preprocessor */ case '#': - token = cpp(file); + token = lex_token(file); + token = lex_token(file); + token = lex_token(file); + token = lex_token(file); + token = lex_token(file); + token = lex_token(file); + break; + + /* PUNCTUATION PARSING BEGINS */ + case '&': /* & */ + token = lex_token(file); + if (token == '&') { /* && */ + token = lex_token(file); + printf("--> LOGICAL AND\n"); + goto end; + } + printf("--> BITWISE AND\n"); + break; + case '|': /* | */ + token = lex_token(file); + if (token == '|') { /* || */ + token = lex_token(file); + printf("--> LOGICAL OR\n"); + goto end; + } + printf("--> BITWISE OR\n"); + break; + case '!': + token = lex_token(file); + if (token == '=') { /* != */ + token = lex_token(file); + printf("--> LOGICAL NOT EQUAL\n"); + goto end; + } + printf("--> LOGICAL NOT\n"); + break; + case '<': /* < */ + token = lex_token(file); + if (token == '=') { /* <= */ + token = lex_token(file); + printf("--> LESS THAN OR EQUALL\n"); + goto end; + } + printf("--> LESS THAN\n"); + break; + case '>': /* > */ + token = lex_token(file); + if (token == '=') { /* >= */ + token = lex_token(file); + printf("--> GREATER THAN OR EQUAL\n"); + goto end; + } + printf("--> GREATER THAN\n"); + break; + case '=': + token = lex_token(file); + if (token == '=') { /* == */ + token = lex_token(file); + printf("--> COMPARISION \n"); + goto end; + } + printf("--> ASSIGNMENT\n"); + break; + case ';': + token = lex_token(file); + printf("--> FINISHED STATMENT\n"); + break; + case '-': + token = lex_token(file); + printf("--> SUBTRACTION EXPRESSION\n"); + break; + case '+': + token = lex_token(file); + printf("--> ASSIGNMENT EXPRRESSION\n"); + break; } + end:; } lex_reset(file); + // "&&", "||", "<=", ">=", "==", "!=", ";", ",", "!", "*", + //"/" , "(" , "-" , "+" , "=" , "[" , "]", "{", "}", "...", + //"." , "<" , ">" , "#" , "&" , "|" , "$", "@", ":", NULL + return 1; }